@zenstackhq/cli 3.0.0-alpha.9 → 3.0.0-beta.2

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
@@ -26,16 +26,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
27
  mod
28
28
  ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
29
 
31
30
  // src/index.ts
32
- var src_exports = {};
33
- __export(src_exports, {
34
- createProgram: () => createProgram
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
31
  var import_language2 = require("@zenstackhq/language");
38
- var import_colors5 = __toESM(require("colors"), 1);
32
+ var import_colors7 = __toESM(require("colors"), 1);
39
33
  var import_commander = require("commander");
40
34
 
41
35
  // src/actions/db.ts
@@ -44,10 +38,10 @@ var import_node_fs2 = __toESM(require("fs"), 1);
44
38
  // src/utils/exec-utils.ts
45
39
  var import_child_process = require("child_process");
46
40
  function execSync(cmd, options) {
47
- const { env, ...restOptions } = options ?? {};
48
- const mergedEnv = env ? {
41
+ const { env: env2, ...restOptions } = options ?? {};
42
+ const mergedEnv = env2 ? {
49
43
  ...process.env,
50
- ...env
44
+ ...env2
51
45
  } : void 0;
52
46
  (0, import_child_process.execSync)(cmd, {
53
47
  encoding: "utf-8",
@@ -65,6 +59,7 @@ __name(execPackage, "execPackage");
65
59
 
66
60
  // src/actions/action-utils.ts
67
61
  var import_language = require("@zenstackhq/language");
62
+ var import_ast = require("@zenstackhq/language/ast");
68
63
  var import_sdk = require("@zenstackhq/sdk");
69
64
  var import_colors = __toESM(require("colors"), 1);
70
65
  var import_node_fs = __toESM(require("fs"), 1);
@@ -85,6 +80,13 @@ function getSchemaFile(file) {
85
80
  }
86
81
  return file;
87
82
  }
83
+ const pkgJsonConfig = getPkgJsonConfig(process.cwd());
84
+ if (pkgJsonConfig.schema) {
85
+ if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
86
+ throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
87
+ }
88
+ return pkgJsonConfig.schema;
89
+ }
88
90
  if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
89
91
  return "./zenstack/schema.zmodel";
90
92
  } else if (import_node_fs.default.existsSync("./schema.zmodel")) {
@@ -97,12 +99,14 @@ __name(getSchemaFile, "getSchemaFile");
97
99
  async function loadSchemaDocument(schemaFile) {
98
100
  const loadResult = await (0, import_language.loadDocument)(schemaFile);
99
101
  if (!loadResult.success) {
100
- console.error(import_colors.default.red("Error loading schema:"));
101
102
  loadResult.errors.forEach((err) => {
102
103
  console.error(import_colors.default.red(err));
103
104
  });
104
- throw new CliError("Failed to load schema");
105
+ throw new CliError("Schema contains errors. See above for details.");
105
106
  }
107
+ loadResult.warnings.forEach((warn) => {
108
+ console.warn(import_colors.default.yellow(warn));
109
+ });
106
110
  return loadResult.model;
107
111
  }
108
112
  __name(loadSchemaDocument, "loadSchemaDocument");
@@ -114,14 +118,62 @@ function handleSubProcessError(err) {
114
118
  }
115
119
  }
116
120
  __name(handleSubProcessError, "handleSubProcessError");
117
- async function generateTempPrismaSchema(zmodelPath) {
121
+ async function generateTempPrismaSchema(zmodelPath, folder) {
118
122
  const model = await loadSchemaDocument(zmodelPath);
123
+ if (!model.declarations.some(import_ast.isDataSource)) {
124
+ throw new CliError("Schema must define a datasource");
125
+ }
119
126
  const prismaSchema = await new import_sdk.PrismaSchemaGenerator(model).generate();
120
- const prismaSchemaFile = import_node_path.default.resolve(import_node_path.default.dirname(zmodelPath), "~schema.prisma");
127
+ if (!folder) {
128
+ folder = import_node_path.default.dirname(zmodelPath);
129
+ }
130
+ const prismaSchemaFile = import_node_path.default.resolve(folder, "~schema.prisma");
121
131
  import_node_fs.default.writeFileSync(prismaSchemaFile, prismaSchema);
122
132
  return prismaSchemaFile;
123
133
  }
124
134
  __name(generateTempPrismaSchema, "generateTempPrismaSchema");
135
+ function getPkgJsonConfig(startPath) {
136
+ const result = {
137
+ schema: void 0,
138
+ output: void 0
139
+ };
140
+ const pkgJsonFile = findUp([
141
+ "package.json"
142
+ ], startPath, false);
143
+ if (!pkgJsonFile) {
144
+ return result;
145
+ }
146
+ let pkgJson = void 0;
147
+ try {
148
+ pkgJson = JSON.parse(import_node_fs.default.readFileSync(pkgJsonFile, "utf8"));
149
+ } catch {
150
+ return result;
151
+ }
152
+ 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);
155
+ }
156
+ return result;
157
+ }
158
+ __name(getPkgJsonConfig, "getPkgJsonConfig");
159
+ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
160
+ if (!names.some((name) => !!name)) {
161
+ return void 0;
162
+ }
163
+ const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
164
+ if (multiple === false && target) {
165
+ return import_node_path.default.join(cwd, target);
166
+ }
167
+ if (target) {
168
+ result.push(import_node_path.default.join(cwd, target));
169
+ }
170
+ const up = import_node_path.default.resolve(cwd, "..");
171
+ if (up === cwd) {
172
+ return multiple && result.length > 0 ? result : void 0;
173
+ }
174
+ return findUp(names, up, multiple, result);
175
+ }
176
+ __name(findUp, "findUp");
125
177
 
126
178
  // src/actions/db.ts
127
179
  async function run(command, options) {
@@ -136,11 +188,15 @@ async function runPush(options) {
136
188
  const schemaFile = getSchemaFile(options.schema);
137
189
  const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
138
190
  try {
139
- const cmd = `prisma db push --schema "${prismaSchemaFile}"${options.acceptDataLoss ? " --accept-data-loss" : ""}${options.forceReset ? " --force-reset" : ""} --skip-generate`;
191
+ const cmd = [
192
+ "prisma db push",
193
+ ` --schema "${prismaSchemaFile}"`,
194
+ options.acceptDataLoss ? " --accept-data-loss" : "",
195
+ options.forceReset ? " --force-reset" : "",
196
+ " --skip-generate"
197
+ ].join("");
140
198
  try {
141
- await execPackage(cmd, {
142
- stdio: "inherit"
143
- });
199
+ await execPackage(cmd);
144
200
  } catch (err) {
145
201
  handleSubProcessError(err);
146
202
  }
@@ -154,31 +210,74 @@ __name(runPush, "runPush");
154
210
 
155
211
  // src/actions/generate.ts
156
212
  var import_common_helpers = require("@zenstackhq/common-helpers");
157
- var import_ast = require("@zenstackhq/language/ast");
158
- var import_sdk2 = require("@zenstackhq/sdk");
213
+ var import_ast2 = require("@zenstackhq/language/ast");
214
+ var import_utils = require("@zenstackhq/language/utils");
159
215
  var import_colors2 = __toESM(require("colors"), 1);
216
+ var import_node_path4 = __toESM(require("path"), 1);
217
+ var import_ora = __toESM(require("ora"), 1);
218
+
219
+ // src/plugins/index.ts
220
+ var plugins_exports = {};
221
+ __export(plugins_exports, {
222
+ prisma: () => prisma_default,
223
+ typescript: () => typescript_default
224
+ });
225
+
226
+ // src/plugins/prisma.ts
227
+ var import_sdk2 = require("@zenstackhq/sdk");
160
228
  var import_node_fs3 = __toESM(require("fs"), 1);
161
229
  var import_node_path2 = __toESM(require("path"), 1);
162
- async function run2(options) {
163
- const schemaFile = getSchemaFile(options.schema);
164
- const model = await loadSchemaDocument(schemaFile);
165
- const outputPath = options.output ?? import_node_path2.default.dirname(schemaFile);
166
- const tsSchemaFile = import_node_path2.default.join(outputPath, "schema.ts");
167
- await new import_sdk2.TsSchemaGenerator().generate(schemaFile, [], tsSchemaFile);
168
- await runPlugins(model, outputPath, tsSchemaFile);
169
- if (options.savePrismaSchema) {
230
+ var plugin = {
231
+ name: "Prisma Schema Generator",
232
+ statusText: "Generating Prisma schema",
233
+ async generate({ model, schemaFile, defaultOutputPath, pluginOptions }) {
234
+ let outFile = import_node_path2.default.join(defaultOutputPath, "schema.prisma");
235
+ 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), {
239
+ recursive: true
240
+ });
241
+ }
242
+ }
170
243
  const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
171
- let prismaSchemaFile = import_node_path2.default.join(outputPath, "schema.prisma");
172
- if (typeof options.savePrismaSchema === "string") {
173
- prismaSchemaFile = import_node_path2.default.resolve(outputPath, options.savePrismaSchema);
174
- import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(prismaSchemaFile), {
175
- recursive: true
176
- });
244
+ import_node_fs3.default.writeFileSync(outFile, prismaSchema);
245
+ }
246
+ };
247
+ var prisma_default = plugin;
248
+
249
+ // src/plugins/typescript.ts
250
+ var import_sdk3 = require("@zenstackhq/sdk");
251
+ var import_node_fs4 = __toESM(require("fs"), 1);
252
+ var import_node_path3 = __toESM(require("path"), 1);
253
+ var plugin2 = {
254
+ name: "TypeScript Schema Generator",
255
+ statusText: "Generating TypeScript schema",
256
+ async generate({ model, defaultOutputPath, pluginOptions }) {
257
+ let outDir = defaultOutputPath;
258
+ if (typeof pluginOptions["output"] === "string") {
259
+ outDir = import_node_path3.default.resolve(defaultOutputPath, pluginOptions["output"]);
260
+ if (!import_node_fs4.default.existsSync(outDir)) {
261
+ import_node_fs4.default.mkdirSync(outDir, {
262
+ recursive: true
263
+ });
264
+ }
177
265
  }
178
- import_node_fs3.default.writeFileSync(prismaSchemaFile, prismaSchema);
266
+ await new import_sdk3.TsSchemaGenerator().generate(model, outDir);
179
267
  }
268
+ };
269
+ var typescript_default = plugin2;
270
+
271
+ // src/actions/generate.ts
272
+ async function run2(options) {
273
+ const start = Date.now();
274
+ const schemaFile = getSchemaFile(options.schema);
275
+ const model = await loadSchemaDocument(schemaFile);
276
+ const outputPath = getOutputPath(options, schemaFile);
277
+ await runPlugins(schemaFile, model, outputPath, options);
180
278
  if (!options.silent) {
181
- console.log(import_colors2.default.green("Generation completed successfully."));
279
+ console.log(import_colors2.default.green(`Generation completed successfully in ${Date.now() - start}ms.
280
+ `));
182
281
  console.log(`You can now create a ZenStack client with it.
183
282
 
184
283
  \`\`\`ts
@@ -186,37 +285,112 @@ import { ZenStackClient } from '@zenstackhq/runtime';
186
285
  import { schema } from '${outputPath}/schema';
187
286
 
188
287
  const client = new ZenStackClient(schema, {
189
- dialectConfig: { ... }
288
+ dialect: { ... }
190
289
  });
191
290
  \`\`\`
192
- `);
291
+
292
+ Check documentation: https://zenstack.dev/docs/3.x`);
193
293
  }
194
294
  }
195
295
  __name(run2, "run");
196
- async function runPlugins(model, outputPath, tsSchemaFile) {
197
- const plugins = model.declarations.filter(import_ast.isPlugin);
198
- for (const plugin of plugins) {
199
- const providerField = plugin.fields.find((f) => f.name === "provider");
200
- (0, import_common_helpers.invariant)(providerField, `Plugin ${plugin.name} does not have a provider field`);
201
- const provider = providerField.value.value;
202
- let useProvider = provider;
203
- if (useProvider.startsWith("@core/")) {
204
- useProvider = `@zenstackhq/runtime/plugins/${useProvider.slice(6)}`;
296
+ function getOutputPath(options, schemaFile) {
297
+ if (options.output) {
298
+ return options.output;
299
+ }
300
+ const pkgJsonConfig = getPkgJsonConfig(process.cwd());
301
+ if (pkgJsonConfig.output) {
302
+ return pkgJsonConfig.output;
303
+ } else {
304
+ return import_node_path4.default.dirname(schemaFile);
305
+ }
306
+ }
307
+ __name(getOutputPath, "getOutputPath");
308
+ async function runPlugins(schemaFile, model, outputPath, options) {
309
+ const plugins = model.declarations.filter(import_ast2.isPlugin);
310
+ const processedPlugins = [];
311
+ for (const plugin3 of plugins) {
312
+ const provider = getPluginProvider(plugin3);
313
+ let cliPlugin;
314
+ if (provider.startsWith("@core/")) {
315
+ cliPlugin = plugins_exports[provider.slice("@core/".length)];
316
+ if (!cliPlugin) {
317
+ throw new CliError(`Unknown core plugin: ${provider}`);
318
+ }
319
+ } 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}`);
328
+ }
205
329
  }
206
- const generator = (await import(useProvider)).default;
207
- console.log("Running generator:", provider);
208
- await generator({
209
- model,
210
- outputPath,
211
- tsSchemaFile
330
+ processedPlugins.push({
331
+ cliPlugin,
332
+ pluginOptions: getPluginOptions(plugin3)
212
333
  });
213
334
  }
335
+ 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: {}
343
+ });
344
+ }
345
+ });
346
+ for (const { cliPlugin, pluginOptions } of processedPlugins) {
347
+ (0, import_common_helpers.invariant)(typeof cliPlugin.generate === "function", `Plugin ${cliPlugin.name} does not have a generate function`);
348
+ let spinner;
349
+ if (!options.silent) {
350
+ spinner = (0, import_ora.default)(cliPlugin.statusText ?? `Running plugin ${cliPlugin.name}`).start();
351
+ }
352
+ try {
353
+ await cliPlugin.generate({
354
+ schemaFile,
355
+ model,
356
+ defaultOutputPath: outputPath,
357
+ pluginOptions
358
+ });
359
+ spinner?.succeed();
360
+ } catch (err) {
361
+ spinner?.fail();
362
+ console.error(err);
363
+ }
364
+ }
214
365
  }
215
366
  __name(runPlugins, "runPlugins");
367
+ function getPluginProvider(plugin3) {
368
+ const providerField = plugin3.fields.find((f) => f.name === "provider");
369
+ (0, import_common_helpers.invariant)(providerField, `Plugin ${plugin3.name} does not have a provider field`);
370
+ const provider = providerField.value.value;
371
+ return provider;
372
+ }
373
+ __name(getPluginProvider, "getPluginProvider");
374
+ function getPluginOptions(plugin3) {
375
+ const result = {};
376
+ for (const field of plugin3.fields) {
377
+ if (field.name === "provider") {
378
+ continue;
379
+ }
380
+ const value = (0, import_utils.getLiteral)(field.value) ?? (0, import_utils.getLiteralArray)(field.value);
381
+ if (value === void 0) {
382
+ console.warn(`Plugin "${plugin3.name}" option "${field.name}" has unsupported value, skipping`);
383
+ continue;
384
+ }
385
+ result[field.name] = value;
386
+ }
387
+ return result;
388
+ }
389
+ __name(getPluginOptions, "getPluginOptions");
216
390
 
217
391
  // src/actions/info.ts
218
392
  var import_colors3 = __toESM(require("colors"), 1);
219
- var import_node_path3 = __toESM(require("path"), 1);
393
+ var import_node_path5 = __toESM(require("path"), 1);
220
394
  async function run3(projectPath) {
221
395
  const packages = await getZenStackPackages(projectPath);
222
396
  if (!packages) {
@@ -225,11 +399,11 @@ async function run3(projectPath) {
225
399
  }
226
400
  console.log("Installed ZenStack Packages:");
227
401
  const versions = /* @__PURE__ */ new Set();
228
- for (const { pkg, version } of packages) {
229
- if (version) {
230
- versions.add(version);
402
+ for (const { pkg, version: version2 } of packages) {
403
+ if (version2) {
404
+ versions.add(version2);
231
405
  }
232
- console.log(` ${import_colors3.default.green(pkg.padEnd(20))} ${version}`);
406
+ console.log(` ${import_colors3.default.green(pkg.padEnd(20))} ${version2}`);
233
407
  }
234
408
  if (versions.size > 1) {
235
409
  console.warn(import_colors3.default.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
@@ -238,9 +412,9 @@ async function run3(projectPath) {
238
412
  __name(run3, "run");
239
413
  async function getZenStackPackages(projectPath) {
240
414
  let pkgJson;
241
- const resolvedPath = import_node_path3.default.resolve(projectPath);
415
+ const resolvedPath = import_node_path5.default.resolve(projectPath);
242
416
  try {
243
- pkgJson = (await import(import_node_path3.default.join(resolvedPath, "package.json"), {
417
+ pkgJson = (await import(import_node_path5.default.join(resolvedPath, "package.json"), {
244
418
  with: {
245
419
  type: "json"
246
420
  }
@@ -259,6 +433,9 @@ async function getZenStackPackages(projectPath) {
259
433
  type: "json"
260
434
  }
261
435
  })).default;
436
+ if (depPkgJson.private) {
437
+ return void 0;
438
+ }
262
439
  return {
263
440
  pkg,
264
441
  version: depPkgJson.version
@@ -270,15 +447,15 @@ async function getZenStackPackages(projectPath) {
270
447
  };
271
448
  }
272
449
  }));
273
- return result;
450
+ return result.filter((p) => !!p);
274
451
  }
275
452
  __name(getZenStackPackages, "getZenStackPackages");
276
453
 
277
454
  // src/actions/init.ts
278
455
  var import_colors4 = __toESM(require("colors"), 1);
279
- var import_node_fs4 = __toESM(require("fs"), 1);
280
- var import_node_path4 = __toESM(require("path"), 1);
281
- var import_ora = __toESM(require("ora"), 1);
456
+ var import_node_fs5 = __toESM(require("fs"), 1);
457
+ var import_node_path6 = __toESM(require("path"), 1);
458
+ var import_ora2 = __toESM(require("ora"), 1);
282
459
  var import_package_manager_detector = require("package-manager-detector");
283
460
 
284
461
  // src/actions/templates.ts
@@ -340,7 +517,7 @@ async function run4(projectPath) {
340
517
  if (!resolved) {
341
518
  throw new CliError(`Unable to determine how to install package "${pkg.name}". Please install it manually.`);
342
519
  }
343
- const spinner = (0, import_ora.default)(`Installing "${pkg.name}"`).start();
520
+ const spinner = (0, import_ora2.default)(`Installing "${pkg.name}"`).start();
344
521
  try {
345
522
  execSync(`${resolved.command} ${resolved.args.join(" ")}`, {
346
523
  cwd: projectPath
@@ -352,11 +529,11 @@ async function run4(projectPath) {
352
529
  }
353
530
  }
354
531
  const generationFolder = "zenstack";
355
- if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder))) {
356
- import_node_fs4.default.mkdirSync(import_node_path4.default.join(projectPath, generationFolder));
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));
357
534
  }
358
- if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"))) {
359
- import_node_fs4.default.writeFileSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
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);
360
537
  } else {
361
538
  console.log(import_colors4.default.yellow("Schema file already exists. Skipping generation of sample."));
362
539
  }
@@ -367,10 +544,12 @@ async function run4(projectPath) {
367
544
  __name(run4, "run");
368
545
 
369
546
  // src/actions/migrate.ts
370
- var import_node_fs5 = __toESM(require("fs"), 1);
547
+ var import_node_fs6 = __toESM(require("fs"), 1);
548
+ var import_node_path7 = __toESM(require("path"), 1);
371
549
  async function run5(command, options) {
372
550
  const schemaFile = getSchemaFile(options.schema);
373
- const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
551
+ const prismaSchemaDir = options.migrations ? import_node_path7.default.dirname(options.migrations) : void 0;
552
+ const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
374
553
  try {
375
554
  switch (command) {
376
555
  case "dev":
@@ -385,19 +564,27 @@ async function run5(command, options) {
385
564
  case "status":
386
565
  await runStatus(prismaSchemaFile, options);
387
566
  break;
567
+ case "resolve":
568
+ await runResolve(prismaSchemaFile, options);
569
+ break;
388
570
  }
389
571
  } finally {
390
- if (import_node_fs5.default.existsSync(prismaSchemaFile)) {
391
- import_node_fs5.default.unlinkSync(prismaSchemaFile);
572
+ if (import_node_fs6.default.existsSync(prismaSchemaFile)) {
573
+ import_node_fs6.default.unlinkSync(prismaSchemaFile);
392
574
  }
393
575
  }
394
576
  }
395
577
  __name(run5, "run");
396
578
  async function runDev(prismaSchemaFile, options) {
397
579
  try {
398
- await execPackage(`prisma migrate dev --schema "${prismaSchemaFile}" --skip-generate${options.name ? ` --name ${options.name}` : ""}${options.createOnly ? " --create-only" : ""}`, {
399
- stdio: "inherit"
400
- });
580
+ const cmd = [
581
+ "prisma migrate dev",
582
+ ` --schema "${prismaSchemaFile}"`,
583
+ " --skip-generate",
584
+ options.name ? ` --name ${options.name}` : "",
585
+ options.createOnly ? " --create-only" : ""
586
+ ].join("");
587
+ await execPackage(cmd);
401
588
  } catch (err) {
402
589
  handleSubProcessError2(err);
403
590
  }
@@ -405,9 +592,12 @@ async function runDev(prismaSchemaFile, options) {
405
592
  __name(runDev, "runDev");
406
593
  async function runReset(prismaSchemaFile, options) {
407
594
  try {
408
- await execPackage(`prisma migrate reset --schema "${prismaSchemaFile}"${options.force ? " --force" : ""}`, {
409
- stdio: "inherit"
410
- });
595
+ const cmd = [
596
+ "prisma migrate reset",
597
+ ` --schema "${prismaSchemaFile}"`,
598
+ options.force ? " --force" : ""
599
+ ].join("");
600
+ await execPackage(cmd);
411
601
  } catch (err) {
412
602
  handleSubProcessError2(err);
413
603
  }
@@ -415,9 +605,11 @@ async function runReset(prismaSchemaFile, options) {
415
605
  __name(runReset, "runReset");
416
606
  async function runDeploy(prismaSchemaFile, _options) {
417
607
  try {
418
- await execPackage(`prisma migrate deploy --schema "${prismaSchemaFile}"`, {
419
- stdio: "inherit"
420
- });
608
+ const cmd = [
609
+ "prisma migrate deploy",
610
+ ` --schema "${prismaSchemaFile}"`
611
+ ].join("");
612
+ await execPackage(cmd);
421
613
  } catch (err) {
422
614
  handleSubProcessError2(err);
423
615
  }
@@ -425,14 +617,29 @@ async function runDeploy(prismaSchemaFile, _options) {
425
617
  __name(runDeploy, "runDeploy");
426
618
  async function runStatus(prismaSchemaFile, _options) {
427
619
  try {
428
- await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`, {
429
- stdio: "inherit"
430
- });
620
+ await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`);
431
621
  } catch (err) {
432
622
  handleSubProcessError2(err);
433
623
  }
434
624
  }
435
625
  __name(runStatus, "runStatus");
626
+ async function runResolve(prismaSchemaFile, options) {
627
+ if (!options.applied && !options.rolledBack) {
628
+ throw new CliError("Either --applied or --rolled-back option must be provided");
629
+ }
630
+ try {
631
+ const cmd = [
632
+ "prisma migrate resolve",
633
+ ` --schema "${prismaSchemaFile}"`,
634
+ options.applied ? ` --applied ${options.applied}` : "",
635
+ options.rolledBack ? ` --rolled-back ${options.rolledBack}` : ""
636
+ ].join("");
637
+ await execPackage(cmd);
638
+ } catch (err) {
639
+ handleSubProcessError2(err);
640
+ }
641
+ }
642
+ __name(runResolve, "runResolve");
436
643
  function handleSubProcessError2(err) {
437
644
  if (err instanceof Error && "status" in err && typeof err.status === "number") {
438
645
  process.exit(err.status);
@@ -442,62 +649,385 @@ function handleSubProcessError2(err) {
442
649
  }
443
650
  __name(handleSubProcessError2, "handleSubProcessError");
444
651
 
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
+ // src/telemetry.ts
667
+ var import_mixpanel = require("mixpanel");
668
+ var import_node_crypto2 = require("crypto");
669
+ var import_node_fs11 = __toESM(require("fs"), 1);
670
+ var os2 = __toESM(require("os"), 1);
671
+
672
+ // src/constants.ts
673
+ var TELEMETRY_TRACKING_TOKEN = "<TELEMETRY_TRACKING_TOKEN>";
674
+
675
+ // src/utils/is-ci.ts
676
+ var import_node_process = require("process");
677
+ 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
+
679
+ // src/utils/is-container.ts
680
+ var import_node_fs8 = __toESM(require("fs"), 1);
681
+
682
+ // src/utils/is-docker.ts
683
+ var import_node_fs7 = __toESM(require("fs"), 1);
684
+ var isDockerCached;
685
+ function hasDockerEnv() {
686
+ try {
687
+ import_node_fs7.default.statSync("/.dockerenv");
688
+ return true;
689
+ } catch {
690
+ return false;
691
+ }
692
+ }
693
+ __name(hasDockerEnv, "hasDockerEnv");
694
+ function hasDockerCGroup() {
695
+ try {
696
+ return import_node_fs7.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
697
+ } catch {
698
+ return false;
699
+ }
700
+ }
701
+ __name(hasDockerCGroup, "hasDockerCGroup");
702
+ function isDocker() {
703
+ if (isDockerCached === void 0) {
704
+ isDockerCached = hasDockerEnv() || hasDockerCGroup();
705
+ }
706
+ return isDockerCached;
707
+ }
708
+ __name(isDocker, "isDocker");
709
+
710
+ // src/utils/is-container.ts
711
+ var cachedResult;
712
+ var hasContainerEnv = /* @__PURE__ */ __name(() => {
713
+ try {
714
+ import_node_fs8.default.statSync("/run/.containerenv");
715
+ return true;
716
+ } catch {
717
+ return false;
718
+ }
719
+ }, "hasContainerEnv");
720
+ function isInContainer() {
721
+ if (cachedResult === void 0) {
722
+ cachedResult = hasContainerEnv() || isDocker();
723
+ }
724
+ return cachedResult;
725
+ }
726
+ __name(isInContainer, "isInContainer");
727
+
728
+ // src/utils/is-wsl.ts
729
+ var import_node_process2 = __toESM(require("process"), 1);
730
+ var import_node_os = __toESM(require("os"), 1);
731
+ var import_node_fs9 = __toESM(require("fs"), 1);
732
+ var isWsl = /* @__PURE__ */ __name(() => {
733
+ if (import_node_process2.default.platform !== "linux") {
734
+ return false;
735
+ }
736
+ if (import_node_os.default.release().toLowerCase().includes("microsoft")) {
737
+ return true;
738
+ }
739
+ try {
740
+ return import_node_fs9.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
741
+ } catch {
742
+ return false;
743
+ }
744
+ }, "isWsl");
745
+
746
+ // src/utils/machine-id-utils.ts
747
+ var import_child_process2 = require("child_process");
748
+ var import_node_crypto = require("crypto");
749
+ var { platform } = process;
750
+ var win32RegBinPath = {
751
+ native: "%windir%\\System32",
752
+ mixed: "%windir%\\sysnative\\cmd.exe /c %windir%\\System32"
753
+ };
754
+ var guid = {
755
+ darwin: "ioreg -rd1 -c IOPlatformExpertDevice",
756
+ win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid`,
757
+ linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname 2> /dev/null) | head -n 1 || :",
758
+ freebsd: "kenv -q smbios.system.uuid || sysctl -n kern.hostuuid"
759
+ };
760
+ function isWindowsProcessMixedOrNativeArchitecture() {
761
+ if (process.arch === "ia32" && process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432")) {
762
+ return "mixed";
763
+ }
764
+ return "native";
765
+ }
766
+ __name(isWindowsProcessMixedOrNativeArchitecture, "isWindowsProcessMixedOrNativeArchitecture");
767
+ function hash(guid2) {
768
+ return (0, import_node_crypto.createHash)("sha256").update(guid2).digest("hex");
769
+ }
770
+ __name(hash, "hash");
771
+ function expose(result) {
772
+ switch (platform) {
773
+ case "darwin":
774
+ return result.split("IOPlatformUUID")[1]?.split("\n")[0]?.replace(/=|\s+|"/gi, "").toLowerCase();
775
+ case "win32":
776
+ return result.toString().split("REG_SZ")[1]?.replace(/\r+|\n+|\s+/gi, "").toLowerCase();
777
+ case "linux":
778
+ return result.toString().replace(/\r+|\n+|\s+/gi, "").toLowerCase();
779
+ case "freebsd":
780
+ return result.toString().replace(/\r+|\n+|\s+/gi, "").toLowerCase();
781
+ default:
782
+ throw new Error(`Unsupported platform: ${process.platform}`);
783
+ }
784
+ }
785
+ __name(expose, "expose");
786
+ function getMachineId() {
787
+ if (!(platform in guid)) {
788
+ return (0, import_node_crypto.randomUUID)();
789
+ }
790
+ try {
791
+ const value = (0, import_child_process2.execSync)(guid[platform]);
792
+ const id = expose(value.toString());
793
+ if (!id) {
794
+ return (0, import_node_crypto.randomUUID)();
795
+ }
796
+ return hash(id);
797
+ } catch {
798
+ return (0, import_node_crypto.randomUUID)();
799
+ }
800
+ }
801
+ __name(getMachineId, "getMachineId");
802
+
445
803
  // src/utils/version-utils.ts
446
- var import_node_fs6 = __toESM(require("fs"), 1);
447
- var import_node_path5 = __toESM(require("path"), 1);
804
+ var import_colors6 = __toESM(require("colors"), 1);
805
+ var import_node_fs10 = __toESM(require("fs"), 1);
806
+ var import_node_path8 = __toESM(require("path"), 1);
448
807
  var import_node_url = require("url");
808
+ var import_semver = __toESM(require("semver"), 1);
449
809
  var import_meta = {};
810
+ var CHECK_VERSION_TIMEOUT = 2e3;
811
+ var VERSION_CHECK_TAG = "next";
450
812
  function getVersion() {
451
813
  try {
452
- const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path5.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
453
- return JSON.parse(import_node_fs6.default.readFileSync(import_node_path5.default.join(_dirname, "../package.json"), "utf8")).version;
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;
454
816
  } catch {
455
817
  return void 0;
456
818
  }
457
819
  }
458
820
  __name(getVersion, "getVersion");
821
+ async function checkNewVersion() {
822
+ const currVersion = getVersion();
823
+ let latestVersion;
824
+ try {
825
+ latestVersion = await getLatestVersion();
826
+ } catch {
827
+ return;
828
+ }
829
+ if (latestVersion && currVersion && import_semver.default.gt(latestVersion, currVersion)) {
830
+ console.log(`A newer version ${import_colors6.default.cyan(latestVersion)} is available.`);
831
+ }
832
+ }
833
+ __name(checkNewVersion, "checkNewVersion");
834
+ async function getLatestVersion() {
835
+ const fetchResult = await fetch(`https://registry.npmjs.org/@zenstackhq/cli/${VERSION_CHECK_TAG}`, {
836
+ headers: {
837
+ accept: "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"
838
+ },
839
+ signal: AbortSignal.timeout(CHECK_VERSION_TIMEOUT)
840
+ });
841
+ if (fetchResult.ok) {
842
+ const data = await fetchResult.json();
843
+ const latestVersion = data?.version;
844
+ if (typeof latestVersion === "string" && import_semver.default.valid(latestVersion)) {
845
+ return latestVersion;
846
+ }
847
+ }
848
+ throw new Error("invalid npm registry response");
849
+ }
850
+ __name(getLatestVersion, "getLatestVersion");
851
+
852
+ // src/telemetry.ts
853
+ var import_meta2 = {};
854
+ var Telemetry = class {
855
+ static {
856
+ __name(this, "Telemetry");
857
+ }
858
+ mixpanel;
859
+ hostId = getMachineId();
860
+ sessionid = (0, import_node_crypto2.randomUUID)();
861
+ _os_type = os2.type();
862
+ _os_release = os2.release();
863
+ _os_arch = os2.arch();
864
+ _os_version = os2.version();
865
+ _os_platform = os2.platform();
866
+ version = getVersion();
867
+ prismaVersion = this.getPrismaVersion();
868
+ isDocker = isDocker();
869
+ isWsl = isWsl();
870
+ isContainer = isInContainer();
871
+ isCi = isInCi;
872
+ constructor() {
873
+ if (process.env["DO_NOT_TRACK"] !== "1" && TELEMETRY_TRACKING_TOKEN) {
874
+ this.mixpanel = (0, import_mixpanel.init)(TELEMETRY_TRACKING_TOKEN, {
875
+ geolocate: true
876
+ });
877
+ }
878
+ }
879
+ get isTracking() {
880
+ return !!this.mixpanel;
881
+ }
882
+ track(event, properties = {}) {
883
+ if (this.mixpanel) {
884
+ const payload = {
885
+ distinct_id: this.hostId,
886
+ session: this.sessionid,
887
+ time: /* @__PURE__ */ new Date(),
888
+ $os: this._os_type,
889
+ osType: this._os_type,
890
+ osRelease: this._os_release,
891
+ osPlatform: this._os_platform,
892
+ osArch: this._os_arch,
893
+ osVersion: this._os_version,
894
+ nodeVersion: process.version,
895
+ version: this.version,
896
+ prismaVersion: this.prismaVersion,
897
+ isDocker: this.isDocker,
898
+ isWsl: this.isWsl,
899
+ isContainer: this.isContainer,
900
+ isCi: this.isCi,
901
+ ...properties
902
+ };
903
+ this.mixpanel.track(event, payload);
904
+ }
905
+ }
906
+ trackError(err) {
907
+ this.track("cli:error", {
908
+ message: err.message,
909
+ stack: err.stack
910
+ });
911
+ }
912
+ async trackSpan(startEvent, completeEvent, errorEvent, properties, action) {
913
+ this.track(startEvent, properties);
914
+ const start = Date.now();
915
+ let success = true;
916
+ try {
917
+ return await action();
918
+ } catch (err) {
919
+ this.track(errorEvent, {
920
+ message: err.message,
921
+ stack: err.stack,
922
+ ...properties
923
+ });
924
+ success = false;
925
+ throw err;
926
+ } finally {
927
+ this.track(completeEvent, {
928
+ duration: Date.now() - start,
929
+ success,
930
+ ...properties
931
+ });
932
+ }
933
+ }
934
+ async trackCommand(command, action) {
935
+ await this.trackSpan("cli:command:start", "cli:command:complete", "cli:command:error", {
936
+ command
937
+ }, action);
938
+ }
939
+ async trackCli(action) {
940
+ await this.trackSpan("cli:start", "cli:complete", "cli:error", {}, action);
941
+ }
942
+ getPrismaVersion() {
943
+ try {
944
+ const packageJsonPath = import_meta2.resolve("prisma/package.json");
945
+ const packageJsonUrl = new URL(packageJsonPath);
946
+ const packageJson = JSON.parse(import_node_fs11.default.readFileSync(packageJsonUrl, "utf8"));
947
+ return packageJson.version;
948
+ } catch {
949
+ return void 0;
950
+ }
951
+ }
952
+ };
953
+ var telemetry = new Telemetry();
459
954
 
460
955
  // src/index.ts
461
956
  var generateAction = /* @__PURE__ */ __name(async (options) => {
462
- await run2(options);
957
+ await telemetry.trackCommand("generate", () => run2(options));
463
958
  }, "generateAction");
464
- var migrateAction = /* @__PURE__ */ __name(async (command, options) => {
465
- await run5(command, options);
959
+ var migrateAction = /* @__PURE__ */ __name(async (subCommand, options) => {
960
+ await telemetry.trackCommand(`migrate ${subCommand}`, () => run5(subCommand, options));
466
961
  }, "migrateAction");
467
- var dbAction = /* @__PURE__ */ __name(async (command, options) => {
468
- await run(command, options);
962
+ var dbAction = /* @__PURE__ */ __name(async (subCommand, options) => {
963
+ await telemetry.trackCommand(`db ${subCommand}`, () => run(subCommand, options));
469
964
  }, "dbAction");
470
965
  var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
471
- await run3(projectPath);
966
+ await telemetry.trackCommand("info", () => run3(projectPath));
472
967
  }, "infoAction");
473
968
  var initAction = /* @__PURE__ */ __name(async (projectPath) => {
474
- await run4(projectPath);
969
+ await telemetry.trackCommand("init", () => run4(projectPath));
475
970
  }, "initAction");
971
+ var checkAction = /* @__PURE__ */ __name(async (options) => {
972
+ await telemetry.trackCommand("check", () => run6(options));
973
+ }, "checkAction");
476
974
  function createProgram() {
477
- const program2 = new import_commander.Command("zenstack");
478
- program2.version(getVersion(), "-v --version", "display CLI version");
975
+ const program = new import_commander.Command("zen");
976
+ program.version(getVersion(), "-v --version", "display CLI version");
479
977
  const schemaExtensions = import_language2.ZModelLanguageMetaData.fileExtensions.join(", ");
480
- program2.description(`${import_colors5.default.bold.blue("\u03B6")} ZenStack is a Prisma power pack for building full-stack apps.
481
-
482
- Documentation: https://zenstack.dev.`).showHelpAfterError().showSuggestionAfterError();
483
- const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "schema.zmodel" unless specified in package.json.`);
484
- program2.command("generate").description("Run code generation.").addOption(schemaOption).addOption(new import_commander.Option("--silent", "do not print any output")).addOption(new import_commander.Option("--save-prisma-schema [path]", "save a Prisma schema file, by default into the output directory")).addOption(new import_commander.Option("-o, --output <path>", "default output directory for core plugins")).action(generateAction);
485
- const migrateCommand = program2.command("migrate").description("Update the database schema with migrations.");
486
- migrateCommand.command("dev").addOption(schemaOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
487
- migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
488
- migrateCommand.command("deploy").addOption(schemaOption).description("Deploy your pending migrations to your production/staging database.").action((options) => migrateAction("deploy", options));
489
- migrateCommand.command("status").addOption(schemaOption).description("check the status of your database migrations.").action((options) => migrateAction("status", options));
490
- const dbCommand = program2.command("db").description("Manage your database schema during development.");
491
- dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).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));
492
- program2.command("info").description("Get information of installed ZenStack and related packages.").argument("[path]", "project path", ".").action(infoAction);
493
- program2.command("init").description("Initialize an existing project for ZenStack.").argument("[path]", "project path", ".").action(initAction);
494
- return program2;
978
+ program.description(`${import_colors7.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
979
+
980
+ Documentation: https://zenstack.dev/docs/3.x`).showHelpAfterError().showSuggestionAfterError();
981
+ const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
982
+ 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);
984
+ const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
985
+ 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);
996
+ program.hook("preAction", async (_thisCommand, actionCommand) => {
997
+ if (actionCommand.getOptionValue("versionCheck") !== false) {
998
+ await checkNewVersion();
999
+ }
1000
+ });
1001
+ return program;
495
1002
  }
496
1003
  __name(createProgram, "createProgram");
497
- var program = createProgram();
498
- program.parse(process.argv);
499
- // Annotate the CommonJS export names for ESM import in node:
500
- 0 && (module.exports = {
501
- createProgram
502
- });
1004
+ async function main() {
1005
+ let exitCode = 0;
1006
+ const program = createProgram();
1007
+ program.exitOverride();
1008
+ try {
1009
+ await telemetry.trackCli(async () => {
1010
+ await program.parseAsync();
1011
+ });
1012
+ } catch (e) {
1013
+ if (e instanceof import_commander.CommanderError) {
1014
+ exitCode = e.exitCode;
1015
+ } else if (e instanceof CliError) {
1016
+ console.error(import_colors7.default.red(e.message));
1017
+ exitCode = 1;
1018
+ } else {
1019
+ console.error(import_colors7.default.red(`Unhandled error: ${e}`));
1020
+ exitCode = 1;
1021
+ }
1022
+ }
1023
+ if (telemetry.isTracking) {
1024
+ setTimeout(() => {
1025
+ process.exit(exitCode);
1026
+ }, 200);
1027
+ } else {
1028
+ process.exit(exitCode);
1029
+ }
1030
+ }
1031
+ __name(main, "main");
1032
+ main();
503
1033
  //# sourceMappingURL=index.cjs.map