@zenstackhq/cli 3.0.0-beta.8 → 3.0.0

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/index.cjs CHANGED
@@ -28,34 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  ));
29
29
 
30
30
  // src/index.ts
31
- var import_language2 = require("@zenstackhq/language");
32
- var import_colors7 = __toESM(require("colors"), 1);
31
+ var import_language3 = require("@zenstackhq/language");
32
+ var import_colors9 = __toESM(require("colors"), 1);
33
33
  var import_commander = require("commander");
34
34
 
35
- // src/actions/db.ts
36
- var import_node_fs2 = __toESM(require("fs"), 1);
37
-
38
- // src/utils/exec-utils.ts
39
- var import_child_process = require("child_process");
40
- function execSync(cmd, options) {
41
- const { env: env2, ...restOptions } = options ?? {};
42
- const mergedEnv = env2 ? {
43
- ...process.env,
44
- ...env2
45
- } : void 0;
46
- (0, import_child_process.execSync)(cmd, {
47
- encoding: "utf-8",
48
- stdio: options?.stdio ?? "inherit",
49
- env: mergedEnv,
50
- ...restOptions
51
- });
52
- }
53
- __name(execSync, "execSync");
54
- function execPackage(cmd, options) {
55
- const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
56
- execSync(`${packageManager} ${cmd}`, options);
57
- }
58
- __name(execPackage, "execPackage");
35
+ // src/actions/check.ts
36
+ var import_colors2 = __toESM(require("colors"), 1);
59
37
 
60
38
  // src/actions/action-utils.ts
61
39
  var import_language = require("@zenstackhq/language");
@@ -85,14 +63,22 @@ function getSchemaFile(file) {
85
63
  if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
86
64
  throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
87
65
  }
88
- return pkgJsonConfig.schema;
66
+ if (import_node_fs.default.statSync(pkgJsonConfig.schema).isDirectory()) {
67
+ const schemaPath = import_node_path.default.join(pkgJsonConfig.schema, "schema.zmodel");
68
+ if (!import_node_fs.default.existsSync(schemaPath)) {
69
+ throw new CliError(`Schema file not found: ${schemaPath}`);
70
+ }
71
+ return schemaPath;
72
+ } else {
73
+ return pkgJsonConfig.schema;
74
+ }
89
75
  }
90
- if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
91
- return "./zenstack/schema.zmodel";
92
- } else if (import_node_fs.default.existsSync("./schema.zmodel")) {
76
+ if (import_node_fs.default.existsSync("./schema.zmodel")) {
93
77
  return "./schema.zmodel";
78
+ } else if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
79
+ return "./zenstack/schema.zmodel";
94
80
  } else {
95
- throw new CliError('Schema file not found in default locations ("./zenstack/schema.zmodel" or "./schema.zmodel").');
81
+ throw new CliError('Schema file not found in default locations ("./schema.zmodel" or "./zenstack/schema.zmodel").');
96
82
  }
97
83
  }
98
84
  __name(getSchemaFile, "getSchemaFile");
@@ -135,7 +121,8 @@ __name(generateTempPrismaSchema, "generateTempPrismaSchema");
135
121
  function getPkgJsonConfig(startPath) {
136
122
  const result = {
137
123
  schema: void 0,
138
- output: void 0
124
+ output: void 0,
125
+ seed: void 0
139
126
  };
140
127
  const pkgJsonFile = findUp([
141
128
  "package.json"
@@ -150,8 +137,9 @@ function getPkgJsonConfig(startPath) {
150
137
  return result;
151
138
  }
152
139
  if (pkgJson.zenstack && typeof pkgJson.zenstack === "object") {
153
- result.schema = pkgJson.zenstack.schema && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema);
154
- result.output = pkgJson.zenstack.output && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output);
140
+ result.schema = pkgJson.zenstack.schema && typeof pkgJson.zenstack.schema === "string" ? import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema) : void 0;
141
+ result.output = pkgJson.zenstack.output && typeof pkgJson.zenstack.output === "string" ? import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output) : void 0;
142
+ result.seed = typeof pkgJson.zenstack.seed === "string" && pkgJson.zenstack.seed ? pkgJson.zenstack.seed : void 0;
155
143
  }
156
144
  return result;
157
145
  }
@@ -174,29 +162,102 @@ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
174
162
  return findUp(names, up, multiple, result);
175
163
  }
176
164
  __name(findUp, "findUp");
165
+ async function requireDataSourceUrl(schemaFile) {
166
+ const zmodel = await loadSchemaDocument(schemaFile);
167
+ const dataSource = zmodel.declarations.find(import_ast.isDataSource);
168
+ if (!dataSource?.fields.some((f) => f.name === "url")) {
169
+ throw new CliError(`The schema's "datasource" must have a "url" field to use this command.`);
170
+ }
171
+ }
172
+ __name(requireDataSourceUrl, "requireDataSourceUrl");
173
+
174
+ // src/actions/check.ts
175
+ async function run(options) {
176
+ const schemaFile = getSchemaFile(options.schema);
177
+ try {
178
+ await loadSchemaDocument(schemaFile);
179
+ console.log(import_colors2.default.green("\u2713 Schema validation completed successfully."));
180
+ } catch (error) {
181
+ console.error(import_colors2.default.red("\u2717 Schema validation failed."));
182
+ throw error;
183
+ }
184
+ }
185
+ __name(run, "run");
177
186
 
178
187
  // src/actions/db.ts
179
- async function run(command, options) {
188
+ var import_node_fs2 = __toESM(require("fs"), 1);
189
+
190
+ // src/utils/exec-utils.ts
191
+ var import_child_process = require("child_process");
192
+ var import_url = require("url");
193
+ var import_meta = {};
194
+ function execSync(cmd, options) {
195
+ const { env: env2, ...restOptions } = options ?? {};
196
+ const mergedEnv = env2 ? {
197
+ ...process.env,
198
+ ...env2
199
+ } : void 0;
200
+ (0, import_child_process.execSync)(cmd, {
201
+ encoding: "utf-8",
202
+ stdio: options?.stdio ?? "inherit",
203
+ env: mergedEnv,
204
+ ...restOptions
205
+ });
206
+ }
207
+ __name(execSync, "execSync");
208
+ function execPackage(cmd, options) {
209
+ const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
210
+ execSync(`${packageManager} ${cmd}`, options);
211
+ }
212
+ __name(execPackage, "execPackage");
213
+ function execPrisma(args, options) {
214
+ let prismaPath;
215
+ try {
216
+ if (typeof import_meta.resolve === "function") {
217
+ prismaPath = (0, import_url.fileURLToPath)(import_meta.resolve("prisma/build/index.js"));
218
+ } else {
219
+ prismaPath = require.resolve("prisma/build/index.js");
220
+ }
221
+ } catch {
222
+ }
223
+ const _options = {
224
+ ...options,
225
+ env: {
226
+ ...options?.env,
227
+ PRISMA_HIDE_UPDATE_MESSAGE: "1"
228
+ }
229
+ };
230
+ if (!prismaPath) {
231
+ execPackage(`prisma ${args}`, _options);
232
+ return;
233
+ }
234
+ execSync(`node ${prismaPath} ${args}`, _options);
235
+ }
236
+ __name(execPrisma, "execPrisma");
237
+
238
+ // src/actions/db.ts
239
+ async function run2(command, options) {
180
240
  switch (command) {
181
241
  case "push":
182
242
  await runPush(options);
183
243
  break;
184
244
  }
185
245
  }
186
- __name(run, "run");
246
+ __name(run2, "run");
187
247
  async function runPush(options) {
188
248
  const schemaFile = getSchemaFile(options.schema);
249
+ await requireDataSourceUrl(schemaFile);
189
250
  const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
190
251
  try {
191
252
  const cmd = [
192
- "prisma db push",
253
+ "db push",
193
254
  ` --schema "${prismaSchemaFile}"`,
194
255
  options.acceptDataLoss ? " --accept-data-loss" : "",
195
256
  options.forceReset ? " --force-reset" : "",
196
257
  " --skip-generate"
197
258
  ].join("");
198
259
  try {
199
- await execPackage(cmd);
260
+ execPrisma(cmd);
200
261
  } catch (err) {
201
262
  handleSubProcessError(err);
202
263
  }
@@ -208,12 +269,33 @@ async function runPush(options) {
208
269
  }
209
270
  __name(runPush, "runPush");
210
271
 
272
+ // src/actions/format.ts
273
+ var import_language2 = require("@zenstackhq/language");
274
+ var import_colors3 = __toESM(require("colors"), 1);
275
+ var import_node_fs3 = __toESM(require("fs"), 1);
276
+ async function run3(options) {
277
+ const schemaFile = getSchemaFile(options.schema);
278
+ let formattedContent;
279
+ try {
280
+ formattedContent = await (0, import_language2.formatDocument)(import_node_fs3.default.readFileSync(schemaFile, "utf-8"));
281
+ } catch (error) {
282
+ console.error(import_colors3.default.red("\u2717 Schema formatting failed."));
283
+ throw error;
284
+ }
285
+ import_node_fs3.default.writeFileSync(schemaFile, formattedContent, "utf-8");
286
+ console.log(import_colors3.default.green("\u2713 Schema formatting completed successfully."));
287
+ }
288
+ __name(run3, "run");
289
+
211
290
  // src/actions/generate.ts
212
291
  var import_common_helpers = require("@zenstackhq/common-helpers");
213
292
  var import_ast2 = require("@zenstackhq/language/ast");
214
293
  var import_utils = require("@zenstackhq/language/utils");
215
- var import_colors2 = __toESM(require("colors"), 1);
294
+ var import_colors4 = __toESM(require("colors"), 1);
295
+ var import_jiti = require("jiti");
296
+ var import_node_fs6 = __toESM(require("fs"), 1);
216
297
  var import_node_path4 = __toESM(require("path"), 1);
298
+ var import_node_url = require("url");
217
299
  var import_ora = __toESM(require("ora"), 1);
218
300
 
219
301
  // src/plugins/index.ts
@@ -225,30 +307,30 @@ __export(plugins_exports, {
225
307
 
226
308
  // src/plugins/prisma.ts
227
309
  var import_sdk2 = require("@zenstackhq/sdk");
228
- var import_node_fs3 = __toESM(require("fs"), 1);
310
+ var import_node_fs4 = __toESM(require("fs"), 1);
229
311
  var import_node_path2 = __toESM(require("path"), 1);
230
312
  var plugin = {
231
313
  name: "Prisma Schema Generator",
232
314
  statusText: "Generating Prisma schema",
233
- async generate({ model, schemaFile, defaultOutputPath, pluginOptions }) {
315
+ async generate({ model, defaultOutputPath, pluginOptions }) {
234
316
  let outFile = import_node_path2.default.join(defaultOutputPath, "schema.prisma");
235
317
  if (typeof pluginOptions["output"] === "string") {
236
- outFile = import_node_path2.default.resolve(import_node_path2.default.dirname(schemaFile), pluginOptions["output"]);
237
- if (!import_node_fs3.default.existsSync(import_node_path2.default.dirname(outFile))) {
238
- import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(outFile), {
318
+ outFile = import_node_path2.default.resolve(defaultOutputPath, pluginOptions["output"]);
319
+ if (!import_node_fs4.default.existsSync(import_node_path2.default.dirname(outFile))) {
320
+ import_node_fs4.default.mkdirSync(import_node_path2.default.dirname(outFile), {
239
321
  recursive: true
240
322
  });
241
323
  }
242
324
  }
243
325
  const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
244
- import_node_fs3.default.writeFileSync(outFile, prismaSchema);
326
+ import_node_fs4.default.writeFileSync(outFile, prismaSchema);
245
327
  }
246
328
  };
247
329
  var prisma_default = plugin;
248
330
 
249
331
  // src/plugins/typescript.ts
250
332
  var import_sdk3 = require("@zenstackhq/sdk");
251
- var import_node_fs4 = __toESM(require("fs"), 1);
333
+ var import_node_fs5 = __toESM(require("fs"), 1);
252
334
  var import_node_path3 = __toESM(require("path"), 1);
253
335
  var plugin2 = {
254
336
  name: "TypeScript Schema Generator",
@@ -257,32 +339,43 @@ var plugin2 = {
257
339
  let outDir = defaultOutputPath;
258
340
  if (typeof pluginOptions["output"] === "string") {
259
341
  outDir = import_node_path3.default.resolve(defaultOutputPath, pluginOptions["output"]);
260
- if (!import_node_fs4.default.existsSync(outDir)) {
261
- import_node_fs4.default.mkdirSync(outDir, {
342
+ if (!import_node_fs5.default.existsSync(outDir)) {
343
+ import_node_fs5.default.mkdirSync(outDir, {
262
344
  recursive: true
263
345
  });
264
346
  }
265
347
  }
266
- await new import_sdk3.TsSchemaGenerator().generate(model, outDir);
348
+ const lite = pluginOptions["lite"] === true;
349
+ const liteOnly = pluginOptions["liteOnly"] === true;
350
+ const importWithFileExtension = pluginOptions["importWithFileExtension"];
351
+ if (importWithFileExtension && typeof importWithFileExtension !== "string") {
352
+ throw new Error('The "importWithFileExtension" option must be a string if specified.');
353
+ }
354
+ await new import_sdk3.TsSchemaGenerator().generate(model, {
355
+ outDir,
356
+ lite,
357
+ liteOnly,
358
+ importWithFileExtension
359
+ });
267
360
  }
268
361
  };
269
362
  var typescript_default = plugin2;
270
363
 
271
364
  // src/actions/generate.ts
272
- async function run2(options) {
365
+ async function run4(options) {
273
366
  const start = Date.now();
274
367
  const schemaFile = getSchemaFile(options.schema);
275
368
  const model = await loadSchemaDocument(schemaFile);
276
369
  const outputPath = getOutputPath(options, schemaFile);
277
370
  await runPlugins(schemaFile, model, outputPath, options);
278
371
  if (!options.silent) {
279
- console.log(import_colors2.default.green(`Generation completed successfully in ${Date.now() - start}ms.
372
+ console.log(import_colors4.default.green(`Generation completed successfully in ${Date.now() - start}ms.
280
373
  `));
281
374
  console.log(`You can now create a ZenStack client with it.
282
375
 
283
376
  \`\`\`ts
284
- import { ZenStackClient } from '@zenstackhq/runtime';
285
- import { schema } from '${outputPath}/schema';
377
+ import { ZenStackClient } from '@zenstackhq/orm';
378
+ import { schema } from '${import_node_path4.default.relative(".", outputPath)}/schema';
286
379
 
287
380
  const client = new ZenStackClient(schema, {
288
381
  dialect: { ... }
@@ -292,7 +385,7 @@ const client = new ZenStackClient(schema, {
292
385
  Check documentation: https://zenstack.dev/docs/3.x`);
293
386
  }
294
387
  }
295
- __name(run2, "run");
388
+ __name(run4, "run");
296
389
  function getOutputPath(options, schemaFile) {
297
390
  if (options.output) {
298
391
  return options.output;
@@ -317,29 +410,38 @@ async function runPlugins(schemaFile, model, outputPath, options) {
317
410
  throw new CliError(`Unknown core plugin: ${provider}`);
318
411
  }
319
412
  } else {
320
- let moduleSpec = provider;
321
- if (moduleSpec.startsWith(".")) {
322
- moduleSpec = import_node_path4.default.resolve(import_node_path4.default.dirname(schemaFile), moduleSpec);
323
- }
324
- try {
325
- cliPlugin = (await import(moduleSpec)).default;
326
- } catch (error) {
327
- throw new CliError(`Failed to load plugin ${provider}: ${error}`);
413
+ cliPlugin = await loadPluginModule(provider, import_node_path4.default.dirname(schemaFile));
414
+ }
415
+ if (cliPlugin) {
416
+ const pluginOptions = getPluginOptions(plugin3);
417
+ if (provider === "@core/typescript") {
418
+ if (pluginOptions["lite"] === void 0) {
419
+ pluginOptions["lite"] = options.lite;
420
+ }
421
+ if (pluginOptions["liteOnly"] === void 0) {
422
+ pluginOptions["liteOnly"] = options.liteOnly;
423
+ }
328
424
  }
425
+ processedPlugins.push({
426
+ cliPlugin,
427
+ pluginOptions
428
+ });
329
429
  }
330
- processedPlugins.push({
331
- cliPlugin,
332
- pluginOptions: getPluginOptions(plugin3)
333
- });
334
430
  }
335
431
  const defaultPlugins = [
336
- typescript_default
337
- ].reverse();
338
- defaultPlugins.forEach((d) => {
339
- if (!processedPlugins.some((p) => p.cliPlugin === d)) {
340
- processedPlugins.push({
341
- cliPlugin: d,
342
- pluginOptions: {}
432
+ {
433
+ plugin: typescript_default,
434
+ options: {
435
+ lite: options.lite,
436
+ liteOnly: options.liteOnly
437
+ }
438
+ }
439
+ ];
440
+ defaultPlugins.forEach(({ plugin: plugin3, options: options2 }) => {
441
+ if (!processedPlugins.some((p) => p.cliPlugin === plugin3)) {
442
+ processedPlugins.unshift({
443
+ cliPlugin: plugin3,
444
+ pluginOptions: options2
343
445
  });
344
446
  }
345
447
  });
@@ -387,11 +489,70 @@ function getPluginOptions(plugin3) {
387
489
  return result;
388
490
  }
389
491
  __name(getPluginOptions, "getPluginOptions");
492
+ async function loadPluginModule(provider, basePath) {
493
+ let moduleSpec = provider;
494
+ if (moduleSpec.startsWith(".")) {
495
+ moduleSpec = import_node_path4.default.resolve(basePath, moduleSpec);
496
+ }
497
+ const importAsEsm = /* @__PURE__ */ __name(async (spec) => {
498
+ try {
499
+ const result = (await import(spec)).default;
500
+ return result;
501
+ } catch (err) {
502
+ throw new CliError(`Failed to load plugin module from ${spec}: ${err.message}`);
503
+ }
504
+ }, "importAsEsm");
505
+ const jiti = (0, import_jiti.createJiti)((0, import_node_url.pathToFileURL)(basePath).toString());
506
+ const importAsTs = /* @__PURE__ */ __name(async (spec) => {
507
+ try {
508
+ const result = await jiti.import(spec, {
509
+ default: true
510
+ });
511
+ return result;
512
+ } catch (err) {
513
+ throw new CliError(`Failed to load plugin module from ${spec}: ${err.message}`);
514
+ }
515
+ }, "importAsTs");
516
+ const esmSuffixes = [
517
+ ".js",
518
+ ".mjs"
519
+ ];
520
+ const tsSuffixes = [
521
+ ".ts",
522
+ ".mts"
523
+ ];
524
+ if (import_node_fs6.default.existsSync(moduleSpec) && import_node_fs6.default.statSync(moduleSpec).isFile()) {
525
+ if (esmSuffixes.some((suffix) => moduleSpec.endsWith(suffix))) {
526
+ return await importAsEsm((0, import_node_url.pathToFileURL)(moduleSpec).toString());
527
+ }
528
+ if (tsSuffixes.some((suffix) => moduleSpec.endsWith(suffix))) {
529
+ return await importAsTs(moduleSpec);
530
+ }
531
+ }
532
+ for (const suffix of esmSuffixes) {
533
+ const indexPath = import_node_path4.default.join(moduleSpec, `index${suffix}`);
534
+ if (import_node_fs6.default.existsSync(indexPath)) {
535
+ return await importAsEsm((0, import_node_url.pathToFileURL)(indexPath).toString());
536
+ }
537
+ }
538
+ for (const suffix of tsSuffixes) {
539
+ const indexPath = import_node_path4.default.join(moduleSpec, `index${suffix}`);
540
+ if (import_node_fs6.default.existsSync(indexPath)) {
541
+ return await importAsTs(indexPath);
542
+ }
543
+ }
544
+ try {
545
+ return (await import(moduleSpec)).default;
546
+ } catch {
547
+ return void 0;
548
+ }
549
+ }
550
+ __name(loadPluginModule, "loadPluginModule");
390
551
 
391
552
  // src/actions/info.ts
392
- var import_colors3 = __toESM(require("colors"), 1);
553
+ var import_colors5 = __toESM(require("colors"), 1);
393
554
  var import_node_path5 = __toESM(require("path"), 1);
394
- async function run3(projectPath) {
555
+ async function run5(projectPath) {
395
556
  const packages = await getZenStackPackages(projectPath);
396
557
  if (!packages) {
397
558
  console.error("Unable to locate package.json. Are you in a valid project directory?");
@@ -403,13 +564,13 @@ async function run3(projectPath) {
403
564
  if (version2) {
404
565
  versions.add(version2);
405
566
  }
406
- console.log(` ${import_colors3.default.green(pkg.padEnd(20))} ${version2}`);
567
+ console.log(` ${import_colors5.default.green(pkg.padEnd(20))} ${version2}`);
407
568
  }
408
569
  if (versions.size > 1) {
409
- console.warn(import_colors3.default.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
570
+ console.warn(import_colors5.default.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
410
571
  }
411
572
  }
412
- __name(run3, "run");
573
+ __name(run5, "run");
413
574
  async function getZenStackPackages(projectPath) {
414
575
  let pkgJson;
415
576
  const resolvedPath = import_node_path5.default.resolve(projectPath);
@@ -452,8 +613,8 @@ async function getZenStackPackages(projectPath) {
452
613
  __name(getZenStackPackages, "getZenStackPackages");
453
614
 
454
615
  // src/actions/init.ts
455
- var import_colors4 = __toESM(require("colors"), 1);
456
- var import_node_fs5 = __toESM(require("fs"), 1);
616
+ var import_colors6 = __toESM(require("colors"), 1);
617
+ var import_node_fs7 = __toESM(require("fs"), 1);
457
618
  var import_node_path6 = __toESM(require("path"), 1);
458
619
  var import_ora2 = __toESM(require("ora"), 1);
459
620
  var import_package_manager_detector = require("package-manager-detector");
@@ -482,20 +643,20 @@ model Post {
482
643
  title String @length(1, 256)
483
644
  content String
484
645
  published Boolean @default(false)
485
- author User @relation(fields: [authorId], references: [id])
646
+ author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
486
647
  authorId String
487
648
  }
488
649
  `;
489
650
 
490
651
  // src/actions/init.ts
491
- async function run4(projectPath) {
652
+ async function run6(projectPath) {
492
653
  const packages = [
493
654
  {
494
655
  name: "@zenstackhq/cli@next",
495
656
  dev: true
496
657
  },
497
658
  {
498
- name: "@zenstackhq/runtime@next",
659
+ name: "@zenstackhq/orm@next",
499
660
  dev: false
500
661
  }
501
662
  ];
@@ -506,12 +667,12 @@ async function run4(projectPath) {
506
667
  name: "npm"
507
668
  };
508
669
  }
509
- console.log(import_colors4.default.gray(`Using package manager: ${pm.agent}`));
670
+ console.log(import_colors6.default.gray(`Using package manager: ${pm.agent}`));
510
671
  for (const pkg of packages) {
511
- const resolved = (0, import_package_manager_detector.resolveCommand)(pm.agent, "install", [
672
+ const resolved = (0, import_package_manager_detector.resolveCommand)(pm.agent, "add", [
512
673
  pkg.name,
513
674
  ...pkg.dev ? [
514
- pm.agent === "yarn" ? "--dev" : "--save-dev"
675
+ pm.agent.startsWith("yarn") || pm.agent === "bun" ? "--dev" : "--save-dev"
515
676
  ] : []
516
677
  ]);
517
678
  if (!resolved) {
@@ -529,25 +690,55 @@ async function run4(projectPath) {
529
690
  }
530
691
  }
531
692
  const generationFolder = "zenstack";
532
- if (!import_node_fs5.default.existsSync(import_node_path6.default.join(projectPath, generationFolder))) {
533
- import_node_fs5.default.mkdirSync(import_node_path6.default.join(projectPath, generationFolder));
693
+ if (!import_node_fs7.default.existsSync(import_node_path6.default.join(projectPath, generationFolder))) {
694
+ import_node_fs7.default.mkdirSync(import_node_path6.default.join(projectPath, generationFolder));
534
695
  }
535
- if (!import_node_fs5.default.existsSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"))) {
536
- import_node_fs5.default.writeFileSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
696
+ if (!import_node_fs7.default.existsSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"))) {
697
+ import_node_fs7.default.writeFileSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
537
698
  } else {
538
- console.log(import_colors4.default.yellow("Schema file already exists. Skipping generation of sample."));
699
+ console.log(import_colors6.default.yellow("Schema file already exists. Skipping generation of sample."));
539
700
  }
540
- console.log(import_colors4.default.green("ZenStack project initialized successfully!"));
541
- console.log(import_colors4.default.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
542
- console.log(import_colors4.default.gray("Run `zenstack generate` to compile the the schema into a TypeScript file."));
701
+ console.log(import_colors6.default.green("ZenStack project initialized successfully!"));
702
+ console.log(import_colors6.default.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
703
+ console.log(import_colors6.default.gray("Run `zenstack generate` to compile the the schema into a TypeScript file."));
543
704
  }
544
- __name(run4, "run");
705
+ __name(run6, "run");
545
706
 
546
707
  // src/actions/migrate.ts
547
- var import_node_fs6 = __toESM(require("fs"), 1);
708
+ var import_node_fs8 = __toESM(require("fs"), 1);
548
709
  var import_node_path7 = __toESM(require("path"), 1);
549
- async function run5(command, options) {
710
+
711
+ // src/actions/seed.ts
712
+ var import_colors7 = __toESM(require("colors"), 1);
713
+ var import_execa = require("execa");
714
+ async function run7(options, args) {
715
+ const pkgJsonConfig = getPkgJsonConfig(process.cwd());
716
+ if (!pkgJsonConfig.seed) {
717
+ if (!options.noWarnings) {
718
+ console.warn(import_colors7.default.yellow("No seed script defined in package.json. Skipping seeding."));
719
+ }
720
+ return;
721
+ }
722
+ const command = `${pkgJsonConfig.seed}${args.length > 0 ? " " + args.join(" ") : ""}`;
723
+ if (options.printStatus) {
724
+ console.log(import_colors7.default.gray(`Running seed script "${command}"...`));
725
+ }
726
+ try {
727
+ await (0, import_execa.execaCommand)(command, {
728
+ stdout: "inherit",
729
+ stderr: "inherit"
730
+ });
731
+ } catch (err) {
732
+ console.error(import_colors7.default.red(err instanceof Error ? err.message : String(err)));
733
+ throw new CliError("Failed to seed the database. Please check the error message above for details.");
734
+ }
735
+ }
736
+ __name(run7, "run");
737
+
738
+ // src/actions/migrate.ts
739
+ async function run8(command, options) {
550
740
  const schemaFile = getSchemaFile(options.schema);
741
+ await requireDataSourceUrl(schemaFile);
551
742
  const prismaSchemaDir = options.migrations ? import_node_path7.default.dirname(options.migrations) : void 0;
552
743
  const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
553
744
  try {
@@ -569,22 +760,23 @@ async function run5(command, options) {
569
760
  break;
570
761
  }
571
762
  } finally {
572
- if (import_node_fs6.default.existsSync(prismaSchemaFile)) {
573
- import_node_fs6.default.unlinkSync(prismaSchemaFile);
763
+ if (import_node_fs8.default.existsSync(prismaSchemaFile)) {
764
+ import_node_fs8.default.unlinkSync(prismaSchemaFile);
574
765
  }
575
766
  }
576
767
  }
577
- __name(run5, "run");
578
- async function runDev(prismaSchemaFile, options) {
768
+ __name(run8, "run");
769
+ function runDev(prismaSchemaFile, options) {
579
770
  try {
580
771
  const cmd = [
581
- "prisma migrate dev",
772
+ "migrate dev",
582
773
  ` --schema "${prismaSchemaFile}"`,
583
774
  " --skip-generate",
584
- options.name ? ` --name ${options.name}` : "",
775
+ " --skip-seed",
776
+ options.name ? ` --name "${options.name}"` : "",
585
777
  options.createOnly ? " --create-only" : ""
586
778
  ].join("");
587
- await execPackage(cmd);
779
+ execPrisma(cmd);
588
780
  } catch (err) {
589
781
  handleSubProcessError2(err);
590
782
  }
@@ -593,48 +785,56 @@ __name(runDev, "runDev");
593
785
  async function runReset(prismaSchemaFile, options) {
594
786
  try {
595
787
  const cmd = [
596
- "prisma migrate reset",
788
+ "migrate reset",
597
789
  ` --schema "${prismaSchemaFile}"`,
790
+ " --skip-generate",
791
+ " --skip-seed",
598
792
  options.force ? " --force" : ""
599
793
  ].join("");
600
- await execPackage(cmd);
794
+ execPrisma(cmd);
601
795
  } catch (err) {
602
796
  handleSubProcessError2(err);
603
797
  }
798
+ if (!options.skipSeed) {
799
+ await run7({
800
+ noWarnings: true,
801
+ printStatus: true
802
+ }, []);
803
+ }
604
804
  }
605
805
  __name(runReset, "runReset");
606
- async function runDeploy(prismaSchemaFile, _options) {
806
+ function runDeploy(prismaSchemaFile, _options) {
607
807
  try {
608
808
  const cmd = [
609
- "prisma migrate deploy",
809
+ "migrate deploy",
610
810
  ` --schema "${prismaSchemaFile}"`
611
811
  ].join("");
612
- await execPackage(cmd);
812
+ execPrisma(cmd);
613
813
  } catch (err) {
614
814
  handleSubProcessError2(err);
615
815
  }
616
816
  }
617
817
  __name(runDeploy, "runDeploy");
618
- async function runStatus(prismaSchemaFile, _options) {
818
+ function runStatus(prismaSchemaFile, _options) {
619
819
  try {
620
- await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`);
820
+ execPrisma(`migrate status --schema "${prismaSchemaFile}"`);
621
821
  } catch (err) {
622
822
  handleSubProcessError2(err);
623
823
  }
624
824
  }
625
825
  __name(runStatus, "runStatus");
626
- async function runResolve(prismaSchemaFile, options) {
826
+ function runResolve(prismaSchemaFile, options) {
627
827
  if (!options.applied && !options.rolledBack) {
628
828
  throw new CliError("Either --applied or --rolled-back option must be provided");
629
829
  }
630
830
  try {
631
831
  const cmd = [
632
- "prisma migrate resolve",
832
+ "migrate resolve",
633
833
  ` --schema "${prismaSchemaFile}"`,
634
- options.applied ? ` --applied ${options.applied}` : "",
635
- options.rolledBack ? ` --rolled-back ${options.rolledBack}` : ""
834
+ options.applied ? ` --applied "${options.applied}"` : "",
835
+ options.rolledBack ? ` --rolled-back "${options.rolledBack}"` : ""
636
836
  ].join("");
637
- await execPackage(cmd);
837
+ execPrisma(cmd);
638
838
  } catch (err) {
639
839
  handleSubProcessError2(err);
640
840
  }
@@ -649,24 +849,10 @@ function handleSubProcessError2(err) {
649
849
  }
650
850
  __name(handleSubProcessError2, "handleSubProcessError");
651
851
 
652
- // src/actions/check.ts
653
- var import_colors5 = __toESM(require("colors"), 1);
654
- async function run6(options) {
655
- const schemaFile = getSchemaFile(options.schema);
656
- try {
657
- await loadSchemaDocument(schemaFile);
658
- console.log(import_colors5.default.green("\u2713 Schema validation completed successfully."));
659
- } catch (error) {
660
- console.error(import_colors5.default.red("\u2717 Schema validation failed."));
661
- throw error;
662
- }
663
- }
664
- __name(run6, "run");
665
-
666
852
  // src/telemetry.ts
667
853
  var import_mixpanel = require("mixpanel");
668
854
  var import_node_crypto2 = require("crypto");
669
- var import_node_fs11 = __toESM(require("fs"), 1);
855
+ var import_node_fs13 = __toESM(require("fs"), 1);
670
856
  var os2 = __toESM(require("os"), 1);
671
857
 
672
858
  // src/constants.ts
@@ -677,14 +863,14 @@ var import_node_process = require("process");
677
863
  var isInCi = import_node_process.env["CI"] !== "0" && import_node_process.env["CI"] !== "false" && ("CI" in import_node_process.env || "CONTINUOUS_INTEGRATION" in import_node_process.env || Object.keys(import_node_process.env).some((key) => key.startsWith("CI_")));
678
864
 
679
865
  // src/utils/is-container.ts
680
- var import_node_fs8 = __toESM(require("fs"), 1);
866
+ var import_node_fs10 = __toESM(require("fs"), 1);
681
867
 
682
868
  // src/utils/is-docker.ts
683
- var import_node_fs7 = __toESM(require("fs"), 1);
869
+ var import_node_fs9 = __toESM(require("fs"), 1);
684
870
  var isDockerCached;
685
871
  function hasDockerEnv() {
686
872
  try {
687
- import_node_fs7.default.statSync("/.dockerenv");
873
+ import_node_fs9.default.statSync("/.dockerenv");
688
874
  return true;
689
875
  } catch {
690
876
  return false;
@@ -693,7 +879,7 @@ function hasDockerEnv() {
693
879
  __name(hasDockerEnv, "hasDockerEnv");
694
880
  function hasDockerCGroup() {
695
881
  try {
696
- return import_node_fs7.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
882
+ return import_node_fs9.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
697
883
  } catch {
698
884
  return false;
699
885
  }
@@ -711,7 +897,7 @@ __name(isDocker, "isDocker");
711
897
  var cachedResult;
712
898
  var hasContainerEnv = /* @__PURE__ */ __name(() => {
713
899
  try {
714
- import_node_fs8.default.statSync("/run/.containerenv");
900
+ import_node_fs10.default.statSync("/run/.containerenv");
715
901
  return true;
716
902
  } catch {
717
903
  return false;
@@ -728,7 +914,7 @@ __name(isInContainer, "isInContainer");
728
914
  // src/utils/is-wsl.ts
729
915
  var import_node_process2 = __toESM(require("process"), 1);
730
916
  var import_node_os = __toESM(require("os"), 1);
731
- var import_node_fs9 = __toESM(require("fs"), 1);
917
+ var import_node_fs11 = __toESM(require("fs"), 1);
732
918
  var isWsl = /* @__PURE__ */ __name(() => {
733
919
  if (import_node_process2.default.platform !== "linux") {
734
920
  return false;
@@ -737,7 +923,7 @@ var isWsl = /* @__PURE__ */ __name(() => {
737
923
  return true;
738
924
  }
739
925
  try {
740
- return import_node_fs9.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
926
+ return import_node_fs11.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
741
927
  } catch {
742
928
  return false;
743
929
  }
@@ -801,18 +987,18 @@ function getMachineId() {
801
987
  __name(getMachineId, "getMachineId");
802
988
 
803
989
  // src/utils/version-utils.ts
804
- var import_colors6 = __toESM(require("colors"), 1);
805
- var import_node_fs10 = __toESM(require("fs"), 1);
990
+ var import_colors8 = __toESM(require("colors"), 1);
991
+ var import_node_fs12 = __toESM(require("fs"), 1);
806
992
  var import_node_path8 = __toESM(require("path"), 1);
807
- var import_node_url = require("url");
993
+ var import_node_url2 = require("url");
808
994
  var import_semver = __toESM(require("semver"), 1);
809
- var import_meta = {};
995
+ var import_meta2 = {};
810
996
  var CHECK_VERSION_TIMEOUT = 2e3;
811
997
  var VERSION_CHECK_TAG = "next";
812
998
  function getVersion() {
813
999
  try {
814
- const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path8.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
815
- return JSON.parse(import_node_fs10.default.readFileSync(import_node_path8.default.join(_dirname, "../package.json"), "utf8")).version;
1000
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path8.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
1001
+ return JSON.parse(import_node_fs12.default.readFileSync(import_node_path8.default.join(_dirname, "../package.json"), "utf8")).version;
816
1002
  } catch {
817
1003
  return void 0;
818
1004
  }
@@ -827,7 +1013,7 @@ async function checkNewVersion() {
827
1013
  return;
828
1014
  }
829
1015
  if (latestVersion && currVersion && import_semver.default.gt(latestVersion, currVersion)) {
830
- console.log(`A newer version ${import_colors6.default.cyan(latestVersion)} is available.`);
1016
+ console.log(`A newer version ${import_colors8.default.cyan(latestVersion)} is available.`);
831
1017
  }
832
1018
  }
833
1019
  __name(checkNewVersion, "checkNewVersion");
@@ -850,7 +1036,7 @@ async function getLatestVersion() {
850
1036
  __name(getLatestVersion, "getLatestVersion");
851
1037
 
852
1038
  // src/telemetry.ts
853
- var import_meta2 = {};
1039
+ var import_meta3 = {};
854
1040
  var Telemetry = class {
855
1041
  static {
856
1042
  __name(this, "Telemetry");
@@ -941,9 +1127,9 @@ var Telemetry = class {
941
1127
  }
942
1128
  getPrismaVersion() {
943
1129
  try {
944
- const packageJsonPath = import_meta2.resolve("prisma/package.json");
1130
+ const packageJsonPath = import_meta3.resolve("prisma/package.json");
945
1131
  const packageJsonUrl = new URL(packageJsonPath);
946
- const packageJson = JSON.parse(import_node_fs11.default.readFileSync(packageJsonUrl, "utf8"));
1132
+ const packageJson = JSON.parse(import_node_fs13.default.readFileSync(packageJsonUrl, "utf8"));
947
1133
  return packageJson.version;
948
1134
  } catch {
949
1135
  return void 0;
@@ -954,45 +1140,62 @@ var telemetry = new Telemetry();
954
1140
 
955
1141
  // src/index.ts
956
1142
  var generateAction = /* @__PURE__ */ __name(async (options) => {
957
- await telemetry.trackCommand("generate", () => run2(options));
1143
+ await telemetry.trackCommand("generate", () => run4(options));
958
1144
  }, "generateAction");
959
1145
  var migrateAction = /* @__PURE__ */ __name(async (subCommand, options) => {
960
- await telemetry.trackCommand(`migrate ${subCommand}`, () => run5(subCommand, options));
1146
+ await telemetry.trackCommand(`migrate ${subCommand}`, () => run8(subCommand, options));
961
1147
  }, "migrateAction");
962
1148
  var dbAction = /* @__PURE__ */ __name(async (subCommand, options) => {
963
- await telemetry.trackCommand(`db ${subCommand}`, () => run(subCommand, options));
1149
+ await telemetry.trackCommand(`db ${subCommand}`, () => run2(subCommand, options));
964
1150
  }, "dbAction");
965
1151
  var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
966
- await telemetry.trackCommand("info", () => run3(projectPath));
1152
+ await telemetry.trackCommand("info", () => run5(projectPath));
967
1153
  }, "infoAction");
968
1154
  var initAction = /* @__PURE__ */ __name(async (projectPath) => {
969
- await telemetry.trackCommand("init", () => run4(projectPath));
1155
+ await telemetry.trackCommand("init", () => run6(projectPath));
970
1156
  }, "initAction");
971
1157
  var checkAction = /* @__PURE__ */ __name(async (options) => {
972
- await telemetry.trackCommand("check", () => run6(options));
1158
+ await telemetry.trackCommand("check", () => run(options));
973
1159
  }, "checkAction");
1160
+ var formatAction = /* @__PURE__ */ __name(async (options) => {
1161
+ await telemetry.trackCommand("format", () => run3(options));
1162
+ }, "formatAction");
1163
+ var seedAction = /* @__PURE__ */ __name(async (options, args) => {
1164
+ await telemetry.trackCommand("db seed", () => run7(options, args));
1165
+ }, "seedAction");
974
1166
  function createProgram() {
975
- const program = new import_commander.Command("zen");
976
- program.version(getVersion(), "-v --version", "display CLI version");
977
- const schemaExtensions = import_language2.ZModelLanguageMetaData.fileExtensions.join(", ");
978
- program.description(`${import_colors7.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
1167
+ const program = new import_commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
1168
+ const schemaExtensions = import_language3.ZModelLanguageMetaData.fileExtensions.join(", ");
1169
+ program.description(`${import_colors9.default.bold.blue("\u03B6")} ZenStack is the modern data layer for TypeScript apps.
979
1170
 
980
- Documentation: https://zenstack.dev/docs/3.x`).showHelpAfterError().showSuggestionAfterError();
1171
+ Documentation: https://zenstack.dev/docs`).showHelpAfterError().showSuggestionAfterError();
981
1172
  const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
982
1173
  const noVersionCheckOption = new import_commander.Option("--no-version-check", "do not check for new version");
983
- program.command("generate").description("Run code generation plugins.").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("-o, --output <path>", "default output directory for code generation")).addOption(new import_commander.Option("--silent", "suppress all output except errors").default(false)).action(generateAction);
1174
+ program.command("generate").description("Run code generation plugins").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("-o, --output <path>", "default output directory for code generation")).addOption(new import_commander.Option("--lite", "also generate a lite version of schema without attributes").default(false)).addOption(new import_commander.Option("--lite-only", "only generate lite version of schema without attributes").default(false)).addOption(new import_commander.Option("--silent", "suppress all output except errors").default(false)).action(generateAction);
984
1175
  const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
985
1176
  const migrationsOption = new import_commander.Option("--migrations <path>", 'path that contains the "migrations" directory');
986
- migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).addOption(migrationsOption).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
987
- migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(noVersionCheckOption).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
988
- migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database.").action((options) => migrateAction("deploy", options));
989
- migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations.").action((options) => migrateAction("status", options));
990
- migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(new import_commander.Option("--applied <migration>", "record a specific migration as applied")).addOption(new import_commander.Option("--rolled-back <migration>", "record a specific migration as rolled back")).description("Resolve issues with database migrations in deployment databases.").action((options) => migrateAction("resolve", options));
991
- const dbCommand = program.command("db").description("Manage your database schema during development.");
992
- dbCommand.command("push").description("Push the state from your schema to your database.").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new import_commander.Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
993
- program.command("info").description("Get information of installed ZenStack packages.").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(infoAction);
994
- program.command("init").description("Initialize an existing project for ZenStack.").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(initAction);
995
- program.command("check").description("Check a ZModel schema for syntax or semantic errors.").addOption(schemaOption).addOption(noVersionCheckOption).action(checkAction);
1177
+ migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).addOption(migrationsOption).description("Create a migration from changes in schema and apply it to the database").action((options) => migrateAction("dev", options));
1178
+ migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(new import_commander.Option("--skip-seed", "skip seeding the database after reset")).addOption(noVersionCheckOption).description("Reset your database and apply all migrations, all data will be lost").addHelpText("after", "\nIf there is a seed script defined in package.json, it will be run after the reset. Use --skip-seed to skip it.").action((options) => migrateAction("reset", options));
1179
+ migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
1180
+ migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
1181
+ migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(new import_commander.Option("--applied <migration>", "record a specific migration as applied")).addOption(new import_commander.Option("--rolled-back <migration>", "record a specific migration as rolled back")).description("Resolve issues with database migrations in deployment databases").action((options) => migrateAction("resolve", options));
1182
+ const dbCommand = program.command("db").description("Manage your database schema during development");
1183
+ dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new import_commander.Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
1184
+ dbCommand.command("seed").description("Seed the database").allowExcessArguments(true).addHelpText("after", `
1185
+ Seed script is configured under the "zenstack.seed" field in package.json.
1186
+ E.g.:
1187
+ {
1188
+ "zenstack": {
1189
+ "seed": "ts-node ./zenstack/seed.ts"
1190
+ }
1191
+ }
1192
+
1193
+ Arguments following -- are passed to the seed script. E.g.: "zen db seed -- --users 10"`).addOption(noVersionCheckOption).action((options, command) => seedAction(options, command.args));
1194
+ program.command("info").description("Get information of installed ZenStack packages").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(infoAction);
1195
+ program.command("init").description("Initialize an existing project for ZenStack").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(initAction);
1196
+ program.command("check").description("Check a ZModel schema for syntax or semantic errors").addOption(schemaOption).addOption(noVersionCheckOption).action(checkAction);
1197
+ program.command("format").description("Format a ZModel schema file").addOption(schemaOption).addOption(noVersionCheckOption).action(formatAction);
1198
+ program.addHelpCommand("help [command]", "Display help for a command");
996
1199
  program.hook("preAction", async (_thisCommand, actionCommand) => {
997
1200
  if (actionCommand.getOptionValue("versionCheck") !== false) {
998
1201
  await checkNewVersion();
@@ -1013,10 +1216,10 @@ async function main() {
1013
1216
  if (e instanceof import_commander.CommanderError) {
1014
1217
  exitCode = e.exitCode;
1015
1218
  } else if (e instanceof CliError) {
1016
- console.error(import_colors7.default.red(e.message));
1219
+ console.error(import_colors9.default.red(e.message));
1017
1220
  exitCode = 1;
1018
1221
  } else {
1019
- console.error(import_colors7.default.red(`Unhandled error: ${e}`));
1222
+ console.error(import_colors9.default.red(`Unhandled error: ${e}`));
1020
1223
  exitCode = 1;
1021
1224
  }
1022
1225
  }