From 242cb7276eaa7da050f0655960a5bbb4d96fbe07 Mon Sep 17 00:00:00 2001 From: Bert De Block Date: Tue, 19 Mar 2024 20:45:00 +0100 Subject: [PATCH] Improve consistency among CLI options --- README.md | 8 ++++---- documents/component.md | 8 ++++---- documents/helper.md | 4 ++-- documents/modifier.md | 8 ++++---- documents/service.md | 4 ++-- src/cli.ts | 18 +++++++++--------- src/generators.ts | 24 ++++++++++++------------ test/generate-component.test.ts | 14 +++----------- test/generate-helper.test.ts | 6 +++--- test/generate-modifier.test.ts | 14 +++----------- test/generate-service.test.ts | 8 ++------ 11 files changed, 48 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 2996f59..7886e8a 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ yarn add -D @bertdeblock/gember ```shell pnpm gember component foo pnpm gember component foo --class -pnpm gember component foo --gts pnpm gember component foo --path="src/-private" +pnpm gember component foo --ts ``` @@ -69,8 +69,8 @@ pnpm gember component foo --path="src/-private" ```shell pnpm gember helper foo pnpm gember helper foo --class -pnpm gember helper foo --ts pnpm gember helper foo --path="src/-private" +pnpm gember helper foo --ts ``` @@ -81,8 +81,8 @@ pnpm gember helper foo --path="src/-private" ```shell pnpm gember modifier foo pnpm gember modifier foo --class -pnpm gember modifier foo --ts pnpm gember modifier foo --path="src/-private" +pnpm gember modifier foo --ts ``` @@ -92,8 +92,8 @@ pnpm gember modifier foo --path="src/-private" ```shell pnpm gember service foo -pnpm gember service foo --ts pnpm gember service foo --path="src/-private" +pnpm gember service foo --ts ``` diff --git a/documents/component.md b/documents/component.md index 8af743c..595fc56 100644 --- a/documents/component.md +++ b/documents/component.md @@ -4,14 +4,14 @@ root: "." output: "**/*" --- -# [[inputs.authoringFormat == "gjs" ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].gjs +# [[inputs.ts ? "!" : (inputs.classBased ? "!" : "")]][[inputs.name]].gjs ```gjs ``` -# [[inputs.authoringFormat == "gjs" ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].gjs +# [[inputs.ts ? "!" : (inputs.classBased ? "" : "!")]][[inputs.name]].gjs ```gjs [[name := pascal(inputs.name)-]] @@ -24,7 +24,7 @@ export default class [[name]] extends Component { ``` -# [[inputs.authoringFormat == "gts" ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].gts +# [[inputs.ts ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].gts ```gts [[name := pascal(inputs.name)-]] @@ -46,7 +46,7 @@ export default [[name]]; ``` -# [[inputs.authoringFormat == "gts" ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].gts +# [[inputs.ts ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].gts ```gts [[name := pascal(inputs.name)-]] diff --git a/documents/helper.md b/documents/helper.md index 0bf8bc6..19a5ac6 100644 --- a/documents/helper.md +++ b/documents/helper.md @@ -4,7 +4,7 @@ root: "." output: "**/*" --- -# [[inputs.classBased ? "!" : ""]][[inputs.name]].[[inputs.authoringFormat]] +# [[inputs.classBased ? "!" : ""]][[inputs.name]].[[inputs.ts ? "ts" : "js"]] ```ts [[name := camel(inputs.name)-]] @@ -15,7 +15,7 @@ export default function [[name]](positional /*, named*/) { ``` -# [[inputs.classBased ? "" : "!"]][[inputs.name]].[[inputs.authoringFormat]] +# [[inputs.classBased ? "" : "!"]][[inputs.name]].[[inputs.ts ? "ts" : "js"]] ```ts [[name := pascal(inputs.name)-]] diff --git a/documents/modifier.md b/documents/modifier.md index a75a2d2..dfebc11 100644 --- a/documents/modifier.md +++ b/documents/modifier.md @@ -4,7 +4,7 @@ root: "." output: "**/*" --- -# [[inputs.authoringFormat == "js" ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].js +# [[inputs.ts ? "!" : (inputs.classBased ? "!" : "")]][[inputs.name]].js ```js [[name := camel(inputs.name)-]] @@ -15,7 +15,7 @@ export default modifier(function [[name]](element, positional, named) {}); ``` -# [[inputs.authoringFormat == "js" ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].js +# [[inputs.ts ? "!" : (inputs.classBased ? "" : "!")]][[inputs.name]].js ```js [[name := pascal(inputs.name)-]] @@ -28,7 +28,7 @@ export default class [[name]] extends Modifier { ``` -# [[inputs.authoringFormat == "ts" ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].ts +# [[inputs.ts ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].ts ```ts [[name := camel(inputs.name)-]] @@ -48,7 +48,7 @@ export default modifier<[[signature]]>(function [[name]](element, positional, na ``` -# [[inputs.authoringFormat == "ts" ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].ts +# [[inputs.ts ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].ts ```ts [[name := pascal(inputs.name)-]] diff --git a/documents/service.md b/documents/service.md index b794062..8180ae7 100644 --- a/documents/service.md +++ b/documents/service.md @@ -4,7 +4,7 @@ root: "." output: "**/*" --- -# [[inputs.name]].[[inputs.authoringFormat]] +# [[inputs.name]].[[inputs.ts ? "ts" : "js"]] ```ts [[name := pascal(inputs.name)-]] @@ -12,7 +12,7 @@ output: "**/*" import Service from "@ember/service"; export default class [[name]] extends Service {} -[[if inputs.authoringFormat == "ts"]] +[[if inputs.ts]] declare module "@ember/service" { interface Registry { "[[inputs.name]]": [[name]]; diff --git a/src/cli.ts b/src/cli.ts index 3c3f980..bf1fa1b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -25,22 +25,22 @@ yargs(hideBin(process.argv)) description: "Generate a class-based component", type: "boolean", }) - .option("gts", { - default: false, - description: "Generate a `.gts` component", - type: "boolean", - }) .option("path", { default: "", description: "Generate a component at a custom path", type: "string", + }) + .option("ts", { + default: false, + description: "Generate a `.gts` component", + type: "boolean", }); }, handler(options) { generateComponent(options.name, { - authoringFormat: options.gts ? "gts" : "gjs", classBased: options.classBased, path: options.path, + ts: options.ts, }); }, }) @@ -74,9 +74,9 @@ yargs(hideBin(process.argv)) }, handler(options) { generateHelper(options.name, { - authoringFormat: options.ts ? "ts" : "js", classBased: options.classBased, path: options.path, + ts: options.ts, }); }, }) @@ -110,9 +110,9 @@ yargs(hideBin(process.argv)) }, handler(options) { generateModifier(options.name, { - authoringFormat: options.ts ? "ts" : "js", classBased: options.classBased, path: options.path, + ts: options.ts, }); }, }) @@ -140,8 +140,8 @@ yargs(hideBin(process.argv)) }, handler(options) { generateService(options.name, { - authoringFormat: options.ts ? "ts" : "js", path: options.path, + ts: options.ts, }); }, }) diff --git a/src/generators.ts b/src/generators.ts index 23653c8..d41af31 100644 --- a/src/generators.ts +++ b/src/generators.ts @@ -3,20 +3,20 @@ import { generateDocument } from "./generate-document.js"; export function generateComponent( name: string, { - authoringFormat = "gjs", classBased = false, cwd = "", path = "", + ts = false, }: { - authoringFormat?: "gjs" | "gts"; classBased?: boolean; cwd?: string; path?: string; + ts?: boolean; } = {}, ) { return generateDocument("component", name, { cwd, - inputs: { authoringFormat, classBased }, + inputs: { classBased, ts }, path, }); } @@ -24,20 +24,20 @@ export function generateComponent( export function generateHelper( name: string, { - authoringFormat = "js", classBased = false, cwd = "", path = "", + ts = false, }: { - authoringFormat?: "js" | "ts"; classBased?: boolean; cwd?: string; path?: string; + ts?: boolean; } = {}, ) { return generateDocument("helper", name, { cwd, - inputs: { authoringFormat, classBased }, + inputs: { classBased, ts }, path, }); } @@ -45,20 +45,20 @@ export function generateHelper( export function generateModifier( name: string, { - authoringFormat = "js", classBased = false, cwd = "", path = "", + ts = false, }: { - authoringFormat?: "js" | "ts"; classBased?: boolean; cwd?: string; path?: string; + ts?: boolean; } = {}, ) { return generateDocument("modifier", name, { cwd, - inputs: { authoringFormat, classBased }, + inputs: { classBased, ts }, path, }); } @@ -66,18 +66,18 @@ export function generateModifier( export function generateService( name: string, { - authoringFormat = "js", cwd = "", path = "", + ts = false, }: { - authoringFormat?: "js" | "ts"; cwd?: string; path?: string; + ts?: boolean; } = {}, ) { return generateDocument("service", name, { cwd, - inputs: { authoringFormat }, + inputs: { ts }, path, }); } diff --git a/test/generate-component.test.ts b/test/generate-component.test.ts index 6956518..5f7dbc1 100644 --- a/test/generate-component.test.ts +++ b/test/generate-component.test.ts @@ -42,7 +42,7 @@ it("generates a template-only `.gjs` component at a custom path", async (ctx) => it("generates a template-only `.gts` component", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateComponent("foo", { authoringFormat: "gts", cwd }); + await generateComponent("foo", { cwd, ts: true }); const content = await readFile(join(cwd, "src/components/foo.gts"), "utf-8"); @@ -52,11 +52,7 @@ it("generates a template-only `.gts` component", async (ctx) => { it("generates a class-based `.gts` component", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateComponent("foo", { - authoringFormat: "gts", - classBased: true, - cwd, - }); + await generateComponent("foo", { classBased: true, cwd, ts: true }); const content = await readFile(join(cwd, "src/components/foo.gts"), "utf-8"); @@ -66,11 +62,7 @@ it("generates a class-based `.gts` component", async (ctx) => { it("generates a template-only `.gts` component at a custom path", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateComponent("foo", { - authoringFormat: "gts", - cwd, - path: "src/-private", - }); + await generateComponent("foo", { cwd, path: "src/-private", ts: true }); const content = await readFile(join(cwd, "src/-private/foo.gts"), "utf-8"); diff --git a/test/generate-helper.test.ts b/test/generate-helper.test.ts index b7bbe6a..3c527c3 100644 --- a/test/generate-helper.test.ts +++ b/test/generate-helper.test.ts @@ -42,7 +42,7 @@ it("generates a function-based `.js` helper at a custom path", async (ctx) => { it("generates a function-based `.ts` helper", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateHelper("foo", { authoringFormat: "ts", cwd }); + await generateHelper("foo", { cwd, ts: true }); const content = await readFile(join(cwd, "src/helpers/foo.ts"), "utf-8"); @@ -52,7 +52,7 @@ it("generates a function-based `.ts` helper", async (ctx) => { it("generates a class-based `.ts` helper", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateHelper("foo", { authoringFormat: "ts", classBased: true, cwd }); + await generateHelper("foo", { classBased: true, cwd, ts: true }); const content = await readFile(join(cwd, "src/helpers/foo.ts"), "utf-8"); @@ -63,9 +63,9 @@ it("generates a function-based `.ts` helper at a custom path", async (ctx) => { cwd = await copyBlueprint("v2-addon"); await generateHelper("foo", { - authoringFormat: "ts", cwd, path: "src/-private", + ts: true, }); const content = await readFile(join(cwd, "src/-private/foo.ts"), "utf-8"); diff --git a/test/generate-modifier.test.ts b/test/generate-modifier.test.ts index cfd830e..5648f19 100644 --- a/test/generate-modifier.test.ts +++ b/test/generate-modifier.test.ts @@ -42,7 +42,7 @@ it("generates a function-based `.js` modifier at a custom path", async (ctx) => it("generates a function-based `.ts` modifier", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateModifier("foo", { authoringFormat: "ts", cwd }); + await generateModifier("foo", { cwd, ts: true }); const content = await readFile(join(cwd, "src/modifiers/foo.ts"), "utf-8"); @@ -52,11 +52,7 @@ it("generates a function-based `.ts` modifier", async (ctx) => { it("generates a class-based `.ts` modifier", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateModifier("foo", { - authoringFormat: "ts", - classBased: true, - cwd, - }); + await generateModifier("foo", { classBased: true, cwd, ts: true }); const content = await readFile(join(cwd, "src/modifiers/foo.ts"), "utf-8"); @@ -66,11 +62,7 @@ it("generates a class-based `.ts` modifier", async (ctx) => { it("generates a function-based `.ts` modifier at a custom path", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateModifier("foo", { - authoringFormat: "ts", - cwd, - path: "src/-private", - }); + await generateModifier("foo", { cwd, path: "src/-private", ts: true }); const content = await readFile(join(cwd, "src/-private/foo.ts"), "utf-8"); diff --git a/test/generate-service.test.ts b/test/generate-service.test.ts index a657a3d..3e68ee0 100644 --- a/test/generate-service.test.ts +++ b/test/generate-service.test.ts @@ -22,7 +22,7 @@ it("generates a `.js` service", async (ctx) => { it("generates a `.ts` service", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateService("foo", { authoringFormat: "ts", cwd }); + await generateService("foo", { cwd, ts: true }); const content = await readFile(join(cwd, "src/services/foo.ts"), "utf-8"); @@ -42,11 +42,7 @@ it("generates a `.js` service at a custom path", async (ctx) => { it("generates a `.ts` service at a custom path", async (ctx) => { cwd = await copyBlueprint("v2-addon"); - await generateService("foo", { - authoringFormat: "ts", - cwd, - path: "src/-private", - }); + await generateService("foo", { cwd, path: "src/-private", ts: true }); const content = await readFile(join(cwd, "src/-private/foo.ts"), "utf-8");