Skip to content

Commit

Permalink
renaming option
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Jan 7, 2025
1 parent fd14f4a commit 55346a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/template-tag-codemod/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ yargs(process.argv.slice(2))
default: optionsWithDefaults().components,
describe: `Controls which component files we will convert to template tag. Provide a list of globs.`,
})
.option('defaultOutput', {
.option('defaultFormat', {
type: 'string',
default: optionsWithDefaults().defaultOutput,
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', {
Expand Down
14 changes: 7 additions & 7 deletions packages/template-tag-codemod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Options {
// 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.
defaultOutput?: 'gjs' | 'gts';
defaultFormat?: 'gjs' | 'gts';

// snippet of typescript to use for the type signature of route templates.
// Defaults to `{ Args: { model: unknown, controller: unknown } }`
Expand All @@ -57,7 +57,7 @@ export function optionsWithDefaults(options?: Options): OptionsWithDefaults {
nativeRouteTemplates: true,
routeTemplates: ['app/templates/**/*.hbs'],
components: ['app/components/**/*.{js,ts,hbs}'],
defaultOutput: 'gjs',
defaultFormat: 'gjs',
routeTemplateSignature: `{ Args: { model: unknown, controller: unknown } }`,
templateOnlyComponentSignature: `{ Args: {} }`,
templateInsertion: 'beginning',
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function processRouteTemplate(filename: string, opts: OptionsWithDe
let outSource: string[] = [];

if (opts.nativeRouteTemplates) {
if (opts.defaultOutput === 'gts') {
if (opts.defaultFormat === 'gts') {
outSource.unshift(`import type { TemplateOnlyComponent } from '@ember/component/template-only';`);
outSource.push(
`export default <template>${templateSource}</template> satisfies TemplateOnlyComponent<${opts.routeTemplateSignature}>`
Expand All @@ -173,7 +173,7 @@ export async function processRouteTemplate(filename: string, opts: OptionsWithDe
imported: 'default',
module: 'ember-route-template',
});
if (opts.defaultOutput === 'gts') {
if (opts.defaultFormat === 'gts') {
outSource.push(
`export default RouteTemplate<${opts.routeTemplateSignature}>(<template>${templateSource}</template>)`
);
Expand All @@ -184,7 +184,7 @@ export async function processRouteTemplate(filename: string, opts: OptionsWithDe

outSource.unshift(renderScopeImports(scope));

writeFileSync(filename.replace(/.hbs$/, '.' + opts.defaultOutput), outSource.join('\n'));
writeFileSync(filename.replace(/.hbs$/, '.' + opts.defaultFormat), outSource.join('\n'));
unlinkSync(filename);
console.log(`route template: ${filename} `);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ export async function processComponent(
unlinkSync(jsPath);
} else {
writeFileSync(
hbsPath.replace(/.hbs$/, '.' + opts.defaultOutput),
hbsPath.replace(/.hbs$/, '.' + opts.defaultFormat),
renderHbsOnlyComponent(templateSource, scope, opts)
);
unlinkSync(hbsPath);
Expand All @@ -297,7 +297,7 @@ async function renderJsComponent(

function renderHbsOnlyComponent(templateSource: string, scope: MetaResult['scope'], opts: OptionsWithDefaults): string {
let outSource: string[] = [];
if (opts.defaultOutput === 'gts') {
if (opts.defaultFormat === 'gts') {
outSource.unshift(`import type { TemplateOnlyComponent } from '@ember/component/template-only';`);
outSource.push(
`export default <template>${templateSource}</template> satisfies TemplateOnlyComponent<${opts.templateOnlyComponentSignature}>`
Expand Down

0 comments on commit 55346a9

Please sign in to comment.