Skip to content
Merged
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export type Config = {
destroy?: boolean;
// Log the generated component to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a nested colocated component, e.g. `foo/bar/index.gts`:
nested?: boolean;
// Generate a component at a custom path, e.g. `--path=src/-private`:
Expand Down Expand Up @@ -149,6 +151,8 @@ export type Config = {
destroy?: boolean;
// Log the generated helper to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a helper at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding helper-test:
Expand Down Expand Up @@ -181,6 +185,8 @@ export type Config = {
destroy?: boolean;
// Log the generated modifier to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a modifier at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding modifier-test:
Expand Down Expand Up @@ -213,6 +219,8 @@ export type Config = {
log?: boolean;
// Generate a route at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding template:
template?: boolean;
// Generate a corresponding route-test:
test?: boolean;
// Generate a `.ts` route, instead of a `.js` route:
Expand Down Expand Up @@ -262,6 +270,22 @@ export type Config = {
// Generate a `.ts` service-test, instead of a `.js` service-test:
typescript?: boolean;
};
template?: {
// Generate a `class-based` template, instead of a `template-only` template:
classBased?: boolean;
// Copy the generated template to the clipboard, instead of writing it to disk:
copy?: boolean;
// The current working directory to run the template generator in:
cwd?: string;
// Destroy a template by name:
destroy?: boolean;
// Log the generated template to the console, instead of writing it to disk:
log?: boolean;
// Generate a template at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a `.gts` template, instead of a `.gjs` template:
typescript?: boolean;
};
util?: {
// Copy the generated util to the clipboard, instead of writing it to disk:
copy?: boolean;
Expand All @@ -271,6 +295,8 @@ export type Config = {
destroy?: boolean;
// Log the generated util to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a util at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding util-test:
Expand Down
23 changes: 11 additions & 12 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GemberError, logGemberErrors } from "./errors.js";
import {
generators,
getGenerator,
getTemplateGenerator,
getTestGenerator,
} from "./generators/generators.js";
import { readOwnPackageJsonSync } from "./internal.js";
Expand Down Expand Up @@ -123,29 +122,29 @@ function generatorCommands(deprecated?: boolean): SubCommandsDef {
logGemberErrors(async () => {
await generator.run(context.args);

if (context.args.template) {
if (generator.hasArg("template")) {
await getGenerator("template").run(context.args);
} else {
logger.warn(
`You passed the \`--template\` option, but the \`${generator.name}\` generator does not have a corresponding template generator.`,
);
}
}

if (context.args.test) {
if (generator.isTestGenerator) {
logger.warn(
`You passed the \`--test\` option, but the \`${generator.name}\` generator is already a test generator.`,
);
} else if (generator.args.find((arg) => arg.name === "test")) {
} else if (generator.hasArg("test")) {
await getTestGenerator(generator.name).run(context.args);
} else {
logger.warn(
`You passed the \`--test\` option, but the \`${generator.name}\` generator does not have a corresponding test generator.`,
);
}
}

if (context.args.template) {
if (generator.args.find((arg) => arg.name === "template")) {
await getTemplateGenerator().run(context.args);
} else {
logger.warn(
`You passed the \`--template\` option, but the \`${generator.name}\` generator does not support generating a template.`,
);
}
}
});
},
};
Expand Down
41 changes: 25 additions & 16 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { GeneratorFile } from "./generators/generator.js";
import { logger } from "./logger.js";

export type Config = {
// Generated using `/dev/generate-generators-type.js`:
generators?: {
"acceptance-test"?: {
// Copy the generated acceptance-test to the clipboard, instead of writing it to disk:
Expand All @@ -31,6 +32,8 @@ export type Config = {
destroy?: boolean;
// Log the generated component to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a nested colocated component, e.g. `foo/bar/index.gts`:
nested?: boolean;
// Generate a component at a custom path, e.g. `--path=src/-private`:
Expand Down Expand Up @@ -95,6 +98,8 @@ export type Config = {
destroy?: boolean;
// Log the generated helper to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a helper at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding helper-test:
Expand Down Expand Up @@ -127,6 +132,8 @@ export type Config = {
destroy?: boolean;
// Log the generated modifier to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a modifier at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding modifier-test:
Expand Down Expand Up @@ -180,22 +187,6 @@ export type Config = {
// Generate a `.ts` route-test, instead of a `.js` route-test:
typescript?: boolean;
};
template?: {
// Generate a `class-based` template, instead of a `template-only` template:
classBased?: boolean;
// Copy the generated template to the clipboard, instead of writing it to disk:
copy?: boolean;
// The current working directory to run the template generator in:
cwd?: string;
// Destroy a template by name:
destroy?: boolean;
// Log the generated template to the console, instead of writing it to disk:
log?: boolean;
// Generate a template at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a `.gts` template, instead of a `.gjs` template:
typescript?: boolean;
};
service?: {
// Copy the generated service to the clipboard, instead of writing it to disk:
copy?: boolean;
Expand Down Expand Up @@ -226,6 +217,22 @@ export type Config = {
// Generate a `.ts` service-test, instead of a `.js` service-test:
typescript?: boolean;
};
template?: {
// Generate a `class-based` template, instead of a `template-only` template:
classBased?: boolean;
// Copy the generated template to the clipboard, instead of writing it to disk:
copy?: boolean;
// The current working directory to run the template generator in:
cwd?: string;
// Destroy a template by name:
destroy?: boolean;
// Log the generated template to the console, instead of writing it to disk:
log?: boolean;
// Generate a template at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a `.gts` template, instead of a `.gjs` template:
typescript?: boolean;
};
util?: {
// Copy the generated util to the clipboard, instead of writing it to disk:
copy?: boolean;
Expand All @@ -235,6 +242,8 @@ export type Config = {
destroy?: boolean;
// Log the generated util to the console, instead of writing it to disk:
log?: boolean;
// Generate a named export, instead of a default export:
namedExport?: boolean;
// Generate a util at a custom path, e.g. `--path=src/-private`:
path?: string;
// Generate a corresponding util-test:
Expand Down
4 changes: 3 additions & 1 deletion src/generators/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
export type Generator = {
args: GeneratorArg[];
description: string;
hasArg: (name: GeneratorArg["name"]) => boolean;
isTestGenerator: boolean;
name: string;
run: (args: Args) => Promise<void>;
Expand Down Expand Up @@ -234,6 +235,7 @@ export function defineGenerator({
return {
args: generatorArgs,
description: description ?? `Generate a new ${generatorName}`,
hasArg: (name) => generatorArgs.some((arg) => arg.name === name),
isTestGenerator: isTestGenerator ?? false,
name: generatorName,
run,
Expand Down Expand Up @@ -360,7 +362,7 @@ export function path(): GeneratorArgFactory {

export function template(): GeneratorArgFactory {
return () => ({
description: `Generate a corresponding template`,
description: "Generate a corresponding template",
name: "template",
type: "boolean",
});
Expand Down
7 changes: 0 additions & 7 deletions src/generators/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ export const generators: Generator[] = [
classBased({ functionBasedName: "template-only" }),
typescript({ gts: true }),
],
modifyTemplateFile: (templateFile) => {
templateFile.name = "component";
},
name: "template",
}),

Expand Down Expand Up @@ -133,7 +130,3 @@ export function getGenerator(generatorName: string): Generator {
export function getTestGenerator(generatorName: string): Generator {
return getGenerator(testGeneratorName(generatorName));
}

export function getTemplateGenerator(): Generator {
return getGenerator("template");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';

export interface {{name.signature}} {
Args: {
model: unknown;
controller: unknown;
model: unknown;
};
Blocks: {
default: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { TOC } from '@ember/component/template-only';

export interface {{name.signature}} {
Args: {
model: unknown;
controller: unknown;
model: unknown;
};
Blocks: {
default: [];
Expand Down
Loading