Feat: Converted Clone to TS module#2308
Conversation
aman19K
left a comment
There was a problem hiding this comment.
Since we're just doing JS to TS conversion, so approving it but in future we need to refactor some files
for example:-
packages/contentstack-clone/src/lib/util/clone-handler.ts
Also, we shouldn’t use lib as a folder name because after compilation the compiler generates a lib directory. That would result in a lib inside another lib, which can be confusing when debugging.
Done |
Feat: Converted Clone to TS module
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)