@betterstart/cli 0.1.61 → 0.1.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -230,6 +230,15 @@ function loadSchema(schemasDir, name) {
230
230
  }
231
231
  return { type: "entity", schema: parsed, filePath: entityPath };
232
232
  }
233
+ function listEntitySchemas(schemasDir) {
234
+ if (!fs2.existsSync(schemasDir)) return [];
235
+ return fs2.readdirSync(schemasDir).filter((f) => f.endsWith(".json") && f !== "schema.json").map((f) => f.replace(".json", ""));
236
+ }
237
+ function listFormSchemas(schemasDir) {
238
+ const formsDir = path2.join(schemasDir, "forms");
239
+ if (!fs2.existsSync(formsDir)) return [];
240
+ return fs2.readdirSync(formsDir).filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
241
+ }
233
242
  function validateEntitySchema(schema) {
234
243
  const errors = [];
235
244
  if (!schema.name || typeof schema.name !== "string") {
@@ -1481,6 +1490,7 @@ import { Button } from '@cms/components/ui/button'
1481
1490
  import { ChevronLeft } from 'lucide-react'
1482
1491
  import Link from 'next/link'
1483
1492
  import { notFound } from 'next/navigation'
1493
+ import { connection } from 'next/server'
1484
1494
 
1485
1495
  interface PageProps {
1486
1496
  params: Promise<{ id: string }>
@@ -1488,6 +1498,7 @@ interface PageProps {
1488
1498
 
1489
1499
  export default async function Page({ params }: PageProps) {
1490
1500
  const { id } = await params
1501
+ await connection()
1491
1502
  const submission = await get${pascal}Submission(Number.parseInt(id, 10))
1492
1503
 
1493
1504
  if (!submission) {
@@ -5364,6 +5375,7 @@ function generateEditPage(schema, cwd, pagesDir, options = {}) {
5364
5375
  const content = `import { ChevronLeft } from 'lucide-react'
5365
5376
  import Link from 'next/link'
5366
5377
  import { notFound } from 'next/navigation'
5378
+ import { connection } from 'next/server'
5367
5379
  import { PageHeader } from '@cms/components/shared/page-header'
5368
5380
  import { Button } from '@cms/components/ui/button'
5369
5381
  import { get${Singular}ById } from '@cms/actions/${schema.name}'
@@ -5377,6 +5389,7 @@ interface PageProps {
5377
5389
 
5378
5390
  export default async function Edit${Singular}Page({ params }: PageProps) {
5379
5391
  const { id } = await params
5392
+ await connection()
5380
5393
  const ${camelSingular} = await get${Singular}ById(Number.parseInt(id, 10))
5381
5394
 
5382
5395
  if (!${camelSingular}) {
@@ -7408,8 +7421,10 @@ function generateSinglePage(schema, cwd, pagesDir, options = {}) {
7408
7421
  const content = `import { get${Singular} } from '@cms/actions/${schema.name}'
7409
7422
  import { PageHeader } from '@cms/components/shared/page-header'
7410
7423
  import { ${Singular}Form } from './${schema.name}-form'
7424
+ import { connection } from 'next/server'
7411
7425
 
7412
7426
  export default async function ${PageName}Page() {
7427
+ await connection()
7413
7428
  const data = await get${Singular}()
7414
7429
 
7415
7430
  return (
@@ -8140,9 +8155,17 @@ function runPostGenerate(cwd, schemaName, options = {}) {
8140
8155
  }
8141
8156
 
8142
8157
  // src/commands/generate.ts
8143
- var generateCommand = new Command("generate").alias("g").description("Generate entity or form from a JSON schema").argument("<schema>", "Schema name (e.g. posts, categories, contact)").option("-f, --force", "Overwrite existing generated files", false).option("--skip-migration", "Skip running db:push after generation", false).option("--cwd <path>", "Project root path").action(
8158
+ var generateCommand = new Command("generate").alias("g").description("Generate entity or form from a JSON schema").argument("[schema]", "Schema name (e.g. posts, categories, contact)").option("-f, --force", "Overwrite existing generated files", false).option("-a, --all", "Regenerate all schemas", false).option("--skip-migration", "Skip running db:push after generation", false).option("--cwd <path>", "Project root path").action(
8144
8159
  async (schemaName, options) => {
8145
8160
  const cwd = options.cwd ? path30.resolve(options.cwd) : process.cwd();
8161
+ if (options.all) {
8162
+ await generateAll(cwd, options);
8163
+ return;
8164
+ }
8165
+ if (!schemaName) {
8166
+ console.error(" Error: schema name is required (or use --all)");
8167
+ process.exit(1);
8168
+ }
8146
8169
  console.log("\n BetterStart Generator\n");
8147
8170
  let config;
8148
8171
  try {
@@ -8253,6 +8276,84 @@ var generateCommand = new Command("generate").alias("g").description("Generate e
8253
8276
  console.log("");
8254
8277
  }
8255
8278
  );
8279
+ async function generateAll(cwd, options) {
8280
+ let config;
8281
+ try {
8282
+ config = await resolveConfig(cwd);
8283
+ } catch (err) {
8284
+ console.error(` Error loading config: ${err instanceof Error ? err.message : String(err)}`);
8285
+ process.exit(1);
8286
+ }
8287
+ const schemasDir = path30.join(cwd, config.paths?.schemas ?? "./cms/schemas");
8288
+ const entityNames = listEntitySchemas(schemasDir);
8289
+ const formNames = listFormSchemas(schemasDir);
8290
+ const allNames = [...entityNames, ...formNames];
8291
+ if (allNames.length === 0) {
8292
+ console.error(`
8293
+ No schemas found in ${schemasDir}
8294
+ `);
8295
+ process.exit(1);
8296
+ }
8297
+ console.log(`
8298
+ BetterStart Generator \u2014 regenerating ${allNames.length} schema(s)
8299
+ `);
8300
+ let totalFiles = 0;
8301
+ const failed = [];
8302
+ for (const name of allNames) {
8303
+ try {
8304
+ const loaded = loadSchema(schemasDir, name);
8305
+ const validationErrors = validateLoadedSchema(loaded);
8306
+ if (validationErrors.length > 0) {
8307
+ console.error(` \u2717 ${name} \u2014 validation failed`);
8308
+ failed.push(name);
8309
+ continue;
8310
+ }
8311
+ let files = [];
8312
+ if (loaded.type === "form") {
8313
+ const result = runFormPipeline(loaded.schema, cwd, config, {
8314
+ force: options.force,
8315
+ skipMigration: true
8316
+ });
8317
+ files = result.files;
8318
+ if (!result.success) {
8319
+ failed.push(name);
8320
+ }
8321
+ } else if (loaded.type === "single") {
8322
+ const result = runSinglePipeline(loaded.schema, cwd, config, {
8323
+ force: options.force,
8324
+ skipMigration: true
8325
+ });
8326
+ files = result.files;
8327
+ if (!result.success) {
8328
+ failed.push(name);
8329
+ }
8330
+ } else {
8331
+ const result = runEntityPipeline(loaded.schema, cwd, config, {
8332
+ force: options.force,
8333
+ skipMigration: true
8334
+ });
8335
+ files = result.files;
8336
+ if (!result.success) {
8337
+ failed.push(name);
8338
+ }
8339
+ }
8340
+ totalFiles += files.length;
8341
+ console.log(` \u2713 ${name} (${loaded.type}) \u2014 ${files.length} files`);
8342
+ } catch (err) {
8343
+ console.error(` \u2717 ${name} \u2014 ${err instanceof Error ? err.message : String(err)}`);
8344
+ failed.push(name);
8345
+ }
8346
+ }
8347
+ if (!options.skipMigration) {
8348
+ runPostGenerate(cwd, allNames[0], { skipMigration: false });
8349
+ }
8350
+ console.log(`
8351
+ Done! ${totalFiles} files generated across ${allNames.length} schema(s).`);
8352
+ if (failed.length > 0) {
8353
+ console.error(` ${failed.length} failed: ${failed.join(", ")}`);
8354
+ }
8355
+ console.log("");
8356
+ }
8256
8357
 
8257
8358
  // src/commands/init.ts
8258
8359
  import { execFileSync as execFileSync4, spawn as spawn2 } from "child_process";