Skip to content

Commit

Permalink
Admin Gen (Future): allow glob pattern to generate specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Ho committed Apr 18, 2024
1 parent 9c8bf1f commit 28f2ccc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/admin/cms-admin/src/generator/future/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export type GeneratorConfig = FormConfig<any> | GridConfig<any> | TabsConfig;

export type GeneratorReturn = { code: string; gqlDocuments: Record<string, string> };

export async function runFutureGenerate(specificFile?: string) {
export async function runFutureGenerate(filePattern = "src/**/*.cometGen.ts") {
const schema = await loadSchema("./schema.gql", {
loaders: [new GraphQLFileLoader()],
});
const gqlIntrospection = introspectionFromSchema(schema);

const files: string[] = specificFile ? [specificFile] : await glob("src/**/*.cometGen.ts");
const files: string[] = await glob(filePattern);
for (const file of files) {
let outputCode = "";
let gqlDocumentsOutputCode = "";
Expand Down
8 changes: 5 additions & 3 deletions packages/admin/cms-admin/src/generator/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ program.addCommand(
);

program.addCommand(
new Command("future-generate").option("-f, --file <file>", "config file to generate").action(async ({ file }: { file?: string }) => {
await runFutureGenerate(file);
}),
new Command("future-generate")
.option("-f, --file <file>", "path to config file or glob pattern to generate specific files")
.action(async ({ file: filePattern }: { file?: string }) => {
await runFutureGenerate(filePattern);
}),
);

program.parse();

0 comments on commit 28f2ccc

Please sign in to comment.