From 375de29e58e50ae67dbe5cac230feba77562d9dc Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 27 Feb 2025 14:09:29 +0000 Subject: [PATCH] convert from yargs to commander --- packages/template-tag-codemod/package.json | 6 +- packages/template-tag-codemod/src/cli.ts | 154 ++++++++++----------- pnpm-lock.yaml | 25 +++- 3 files changed, 95 insertions(+), 90 deletions(-) diff --git a/packages/template-tag-codemod/package.json b/packages/template-tag-codemod/package.json index aac04b3d0..11c1d96e7 100644 --- a/packages/template-tag-codemod/package.json +++ b/packages/template-tag-codemod/package.json @@ -38,20 +38,20 @@ "@babel/generator": "^7.26.5", "@babel/plugin-syntax-decorators": "^7.25.9", "@babel/plugin-syntax-typescript": "^7.25.9", + "@commander-js/extra-typings": "^13.1.0", "@embroider/compat": "workspace:^*", "@embroider/core": "workspace:^*", "@embroider/reverse-exports": "workspace:^*", "@humanwhocodes/module-importer": "^1.0.1", "@types/babel__core": "^7.20.5", - "@types/yargs": "^17.0.3", "babel-import-util": "^3.0.0", "babel-plugin-ember-template-compilation": "^2.3.0", "broccoli": "^3.5.2", + "commander": "^13.1.0", "console-ui": "^3.1.2", "ember-cli": "^6.0.1", "glob": "^11.0.0", - "html-tag-names": "^2.1.0", - "yargs": "^17.0.1" + "html-tag-names": "^2.1.0" }, "devDependencies": { "@glimmer/syntax": "^0.84.3", diff --git a/packages/template-tag-codemod/src/cli.ts b/packages/template-tag-codemod/src/cli.ts index e2edc3aed..807094323 100644 --- a/packages/template-tag-codemod/src/cli.ts +++ b/packages/template-tag-codemod/src/cli.ts @@ -1,86 +1,78 @@ #!/usr/bin/env node -import yargs from 'yargs/yargs'; import { type Options, optionsWithDefaults, run } from './index.js'; -yargs(process.argv.slice(2)) - .scriptName('template-tag-codemod') - .command( - '$0', - "Converts Ember's .hbs format to .gjs or .gts format.", - y => - y - .option('relativeLocalPaths', { - default: optionsWithDefaults().relativeLocalPaths, - type: 'boolean', - describe: `When true, imports for other files in the same project will use relative paths with file extensions. This is the most compatible with modern Node ESM convensions, but it's not supported by Ember's classic build.`, - }) - .option('extensions', { - array: true, - type: 'string', - default: optionsWithDefaults().extensions, - describe: `File extensions to search when resolving components, helpers, and modifiers inside your hbs files`, - }) - .option('nativeRouteTemplates', { - default: optionsWithDefaults().nativeRouteTemplates, - type: 'boolean', - describe: `When true, assume we can use template-tag directly in route files (requires ember-source >= 6.3.0-beta.3). When false, assume we can use the ember-route-template addon instead.`, - }) - .option('nativeLexicalThis', { - default: optionsWithDefaults().nativeLexicalThis, - type: 'boolean', - describe: `When true, assume that Ember supports accessing the lexically-scoped "this" from template-tags that are used as expressions (requires ember-source >= TODO). When false, introduce a new local variable to make "this" accessible.`, - }) - .option('routeTemplates', { - array: true, - type: 'string', - default: optionsWithDefaults().routeTemplates, - describe: `Controls which route template files we will convert to template tag. Provide a list of globs.`, - }) - .option('components', { - array: true, - type: 'string', - default: optionsWithDefaults().components, - describe: `Controls which component files we will convert to template tag. Provide a list of globs.`, - }) - .option('renderTests', { - array: true, - type: 'string', - default: optionsWithDefaults().renderTests, - describe: `Controls the files in which we will search for rendering tests to convert to template tags. Provide a list of globs.`, - }) - .option('defaultFormat', { - type: 'string', - default: optionsWithDefaults().defaultFormat, - describe: `When a .js or .ts file already exists, we necessarily convert to .gjs or .gts respectively. But when only an .hbs file exists, we have a choice of default.`, - }) - .option('templateOnlyComponentSignature', { - type: 'string', - default: optionsWithDefaults().templateOnlyComponentSignature, - describe: `Snippet of typescript to use as the type signature of newly-converted template-only components.`, - }) - .option('routeTemplateSignature', { - type: 'string', - default: optionsWithDefaults().routeTemplateSignature, - describe: `Snippet of typescript to use as the type signature of route templates.`, - }) - .option('templateInsertion', { - type: 'string', - default: optionsWithDefaults().templateInsertion, - describe: `Where should