Feat: Converted Clone to TS module #2308
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the contentstack-clone module from JavaScript to TypeScript and significantly improves test coverage from minimal coverage to 87.51% overall. The migration includes comprehensive type definitions, improved code quality, and extensive unit test coverage across all major components.
clone-handler.ts(up from ~35%)clone.tscommand📊 Test Coverage Metrics
commands/cm/stacks/clone.tslib/util/clone-handler.tslib/helpers/command-helpers.tslib/util/abort-controller.tsutils/constants.ts🔄 TypeScript Migration
Core Files Converted
1. Clone Handler (
src/lib/util/clone-handler.js→clone-handler.ts)require()to ES6importstatementsexportsyntax2. Clone Command (
src/commands/cm/stacks/clone.js→clone.ts)CloneConfigandCloneContext3. Supporting Files
abort-controller.js→abort-controller.tscommand-helpers.js→command-helpers.tsType Definitions Added
Created comprehensive TypeScript type definition files:
types/clone-config.ts- Type definitions for clone configurationtypes/clone-context.ts- Type definitions for clone contexttypes/command-types.ts- Command-related type definitionstypes/index.ts- Centralized type exportsutils/constants.ts- Type-safe constantsBug Fixes
Source Code Improvements
path.joincalls incmdImport()to handle undefinedpathDir(lines 637, 668)cmdImport()method to properly reject Promise on error (changed fromthrow errortoreject(error))Testing Infrastructure
.mocharc.jsonfor Mocha configuration.nycrc.jsonfor coverage configurationeslint-config-oclif-typescriptoraspinner module usingObject.definePropertyinquirer.ui.BottomBarto prevent test hanging📝 Files Changed
Added
src/types/clone-config.tssrc/types/clone-context.tssrc/types/command-types.tssrc/types/index.tssrc/utils/constants.tstest/lib/util/clone-handler.execution.test.tstest/lib/util/clone-handler.commands.test.tstest/lib/util/clone-handler.clone-type.test.tstest/lib/util/clone-handler.organization.test.tstest/lib/util/clone-handler.stack.test.tstest/lib/util/clone-handler.branch.test.tstest/lib/util/clone-handler.helpers.test.tstest/lib/util/clone-handler.initialization.test.tstest/helpers/init.js.mocharc.json.nycrc.jsonModified
src/lib/util/clone-handler.js→clone-handler.ts(converted)src/commands/cm/stacks/clone.js→clone.ts(converted)src/lib/util/abort-controller.js→abort-controller.ts(converted)src/lib/helpers/command-helpers.js→command-helpers.ts(converted)test/commands/cm/stacks/clone.test.ts(enhanced).eslintrc(updated)package.json(updated dependencies)Deleted
test/lib/util/clone-handler.stack-creation.test.ts(replaced with better tests)