Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert from yargs to commander #2320

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/template-tag-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
154 changes: 73 additions & 81 deletions packages/template-tag-codemod/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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 <template> be inserted inside existing class bodies? Say "beginning" or "end".`,
})
.option('renamingRules', {
type: 'string',
default: optionsWithDefaults().renamingRules,
describe: `The name of a module that will provide a renaming strategy for picking the names of components, helpers, and modifiers in rewritten templates`,
}),
import { program } from '@commander-js/extra-typings';

async argv => {
await run(argv as Options);

// we need this to be explicit because our prebuild runs things like
// broccoli-babel-transpiler which leak worker processes and will
// otherwise prevent exit.🤮
process.exit(0);
}
program
.name('template-tag-codemod')
.description(`Converts Ember's .hbs format to .gjs or .gts format.`)
.option(
'--no-relativeLocalPaths',
`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.`,
optionsWithDefaults().relativeLocalPaths
)
.option(
'--extensions <...extensions>',
`File extensions to search when resolving components, helpers, and modifiers inside your hbs files`,
optionsWithDefaults().extensions
)
.option(
'--no-nativeRouteTemplates',
`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.`,
optionsWithDefaults().nativeRouteTemplates
)
.option(
'--nativeLexicalThis',
`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.`,
optionsWithDefaults().nativeLexicalThis
)
.option(
'--routeTemplates <...globs>',
`Controls which route template files we will convert to template tag. Provide a list of globs.`,
optionsWithDefaults().routeTemplates
)
.option(
'--components <...globs>',
`Controls which component files we will convert to template tag. Provide a list of globs.`,
optionsWithDefaults().components
)
.option(
'--renderTests <...globs>',
`Controls the files in which we will search for rendering tests to convert to template tags. Provide a list of globs.`,
optionsWithDefaults().renderTests
)
.parse();
.option(
'--defaultFormat <value>',
`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.`,
optionsWithDefaults().defaultFormat
)
.option(
'--templateOnlyComponentSignature <value>',
`Snippet of typescript to use as the type signature of newly-converted template-only components.`,
optionsWithDefaults().templateOnlyComponentSignature
)
.option(
'--routeTemplateSignature <value>',
`Snippet of typescript to use as the type signature of route templates.`,
optionsWithDefaults().routeTemplateSignature
)
.option(
'--templateInsertion <value>',
`Where should <template> be inserted inside existing class bodies? Say "beginning" or "end".`,
optionsWithDefaults().templateInsertion
)
.option(
'--renamingRules <value>',
`The name of a module that will provide a renaming strategy for picking the names of components, helpers, and modifiers in rewritten templates`,
optionsWithDefaults().renamingRules
)
.action(async args => {
await run(args as Options);

// we need this to be explicit because our prebuild runs things like
// broccoli-babel-transpiler which leak worker processes and will
// otherwise prevent exit.🤮
process.exit(0);
});

program.parse();
25 changes: 19 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading