Skip to content

Commit

Permalink
Merge pull request #22 from bertdeblock/consistent-cli-options
Browse files Browse the repository at this point in the history
Improve consistency among CLI options
  • Loading branch information
bertdeblock authored Mar 20, 2024
2 parents c54819e + 242cb72 commit a50039e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 68 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

</details>
Expand All @@ -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
```

</details>
Expand All @@ -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
```

</details>
Expand All @@ -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
```

</details>
8 changes: 4 additions & 4 deletions documents/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ root: "."
output: "**/*"
---

# [[inputs.authoringFormat == "gjs" ? (inputs.classBased ? "!" : "") : "!"]][[inputs.name]].gjs
# [[inputs.ts ? "!" : (inputs.classBased ? "!" : "")]][[inputs.name]].gjs

```gjs
<template>{{yield}}</template>
```

# [[inputs.authoringFormat == "gjs" ? (inputs.classBased ? "" : "!") : "!"]][[inputs.name]].gjs
# [[inputs.ts ? "!" : (inputs.classBased ? "" : "!")]][[inputs.name]].gjs

```gjs
[[name := pascal(inputs.name)-]]
Expand All @@ -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)-]]
Expand All @@ -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)-]]
Expand Down
4 changes: 2 additions & 2 deletions documents/helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)-]]
Expand All @@ -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)-]]
Expand Down
8 changes: 4 additions & 4 deletions documents/modifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)-]]
Expand All @@ -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)-]]
Expand All @@ -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)-]]
Expand All @@ -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)-]]
Expand Down
4 changes: 2 additions & 2 deletions documents/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ root: "."
output: "**/*"
---

# [[inputs.name]].[[inputs.authoringFormat]]
# [[inputs.name]].[[inputs.ts ? "ts" : "js"]]

```ts
[[name := pascal(inputs.name)-]]

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]];
Expand Down
18 changes: 9 additions & 9 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},
})
Expand Down Expand Up @@ -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,
});
},
})
Expand Down Expand Up @@ -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,
});
},
})
Expand Down Expand Up @@ -140,8 +140,8 @@ yargs(hideBin(process.argv))
},
handler(options) {
generateService(options.name, {
authoringFormat: options.ts ? "ts" : "js",
path: options.path,
ts: options.ts,
});
},
})
Expand Down
24 changes: 12 additions & 12 deletions src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,81 @@ 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,
});
}

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,
});
}

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,
});
}

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,
});
}
14 changes: 3 additions & 11 deletions test/generate-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions test/generate-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");
Expand Down
Loading

0 comments on commit a50039e

Please sign in to comment.