@zenstackhq/cli 3.0.0-beta.23 → 3.0.0-beta.24
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/.turbo/turbo-build.log +8 -26
- package/dist/index.cjs +175 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +172 -122
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/actions/action-utils.ts +4 -4
- package/src/actions/format.ts +27 -0
- package/src/actions/generate.ts +13 -1
- package/src/actions/index.ts +3 -2
- package/src/index.ts +28 -14
- package/src/plugins/typescript.ts +12 -1
- package/src/utils/exec-utils.ts +18 -7
- package/test/format.test.ts +33 -0
package/dist/index.js
CHANGED
|
@@ -13,39 +13,11 @@ var __export = (target, all) => {
|
|
|
13
13
|
|
|
14
14
|
// src/index.ts
|
|
15
15
|
import { ZModelLanguageMetaData } from "@zenstackhq/language";
|
|
16
|
-
import
|
|
16
|
+
import colors8 from "colors";
|
|
17
17
|
import { Command, CommanderError, Option } from "commander";
|
|
18
18
|
|
|
19
|
-
// src/actions/
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
// src/utils/exec-utils.ts
|
|
23
|
-
import { execSync as _exec } from "child_process";
|
|
24
|
-
import { fileURLToPath } from "url";
|
|
25
|
-
function execSync(cmd, options) {
|
|
26
|
-
const { env: env2, ...restOptions } = options ?? {};
|
|
27
|
-
const mergedEnv = env2 ? {
|
|
28
|
-
...process.env,
|
|
29
|
-
...env2
|
|
30
|
-
} : void 0;
|
|
31
|
-
_exec(cmd, {
|
|
32
|
-
encoding: "utf-8",
|
|
33
|
-
stdio: options?.stdio ?? "inherit",
|
|
34
|
-
env: mergedEnv,
|
|
35
|
-
...restOptions
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
__name(execSync, "execSync");
|
|
39
|
-
function execPrisma(args, options) {
|
|
40
|
-
let prismaPath;
|
|
41
|
-
if (typeof import.meta.resolve === "function") {
|
|
42
|
-
prismaPath = fileURLToPath(import.meta.resolve("prisma/build/index.js"));
|
|
43
|
-
} else {
|
|
44
|
-
prismaPath = __require.resolve("prisma/build/index.js");
|
|
45
|
-
}
|
|
46
|
-
execSync(`node ${prismaPath} ${args}`, options);
|
|
47
|
-
}
|
|
48
|
-
__name(execPrisma, "execPrisma");
|
|
19
|
+
// src/actions/check.ts
|
|
20
|
+
import colors2 from "colors";
|
|
49
21
|
|
|
50
22
|
// src/actions/action-utils.ts
|
|
51
23
|
import { loadDocument } from "@zenstackhq/language";
|
|
@@ -85,12 +57,12 @@ function getSchemaFile(file) {
|
|
|
85
57
|
return pkgJsonConfig.schema;
|
|
86
58
|
}
|
|
87
59
|
}
|
|
88
|
-
if (fs.existsSync("./
|
|
89
|
-
return "./zenstack/schema.zmodel";
|
|
90
|
-
} else if (fs.existsSync("./schema.zmodel")) {
|
|
60
|
+
if (fs.existsSync("./schema.zmodel")) {
|
|
91
61
|
return "./schema.zmodel";
|
|
62
|
+
} else if (fs.existsSync("./zenstack/schema.zmodel")) {
|
|
63
|
+
return "./zenstack/schema.zmodel";
|
|
92
64
|
} else {
|
|
93
|
-
throw new CliError('Schema file not found in default locations ("./
|
|
65
|
+
throw new CliError('Schema file not found in default locations ("./schema.zmodel" or "./zenstack/schema.zmodel").');
|
|
94
66
|
}
|
|
95
67
|
}
|
|
96
68
|
__name(getSchemaFile, "getSchemaFile");
|
|
@@ -173,15 +145,71 @@ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
|
173
145
|
}
|
|
174
146
|
__name(findUp, "findUp");
|
|
175
147
|
|
|
148
|
+
// src/actions/check.ts
|
|
149
|
+
async function run(options) {
|
|
150
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
151
|
+
try {
|
|
152
|
+
await loadSchemaDocument(schemaFile);
|
|
153
|
+
console.log(colors2.green("\u2713 Schema validation completed successfully."));
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error(colors2.red("\u2717 Schema validation failed."));
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
__name(run, "run");
|
|
160
|
+
|
|
161
|
+
// src/actions/db.ts
|
|
162
|
+
import fs2 from "fs";
|
|
163
|
+
|
|
164
|
+
// src/utils/exec-utils.ts
|
|
165
|
+
import { execSync as _exec } from "child_process";
|
|
166
|
+
import { fileURLToPath } from "url";
|
|
167
|
+
function execSync(cmd, options) {
|
|
168
|
+
const { env: env2, ...restOptions } = options ?? {};
|
|
169
|
+
const mergedEnv = env2 ? {
|
|
170
|
+
...process.env,
|
|
171
|
+
...env2
|
|
172
|
+
} : void 0;
|
|
173
|
+
_exec(cmd, {
|
|
174
|
+
encoding: "utf-8",
|
|
175
|
+
stdio: options?.stdio ?? "inherit",
|
|
176
|
+
env: mergedEnv,
|
|
177
|
+
...restOptions
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
__name(execSync, "execSync");
|
|
181
|
+
function execPackage(cmd, options) {
|
|
182
|
+
const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
|
|
183
|
+
execSync(`${packageManager} ${cmd}`, options);
|
|
184
|
+
}
|
|
185
|
+
__name(execPackage, "execPackage");
|
|
186
|
+
function execPrisma(args, options) {
|
|
187
|
+
let prismaPath;
|
|
188
|
+
try {
|
|
189
|
+
if (typeof import.meta.resolve === "function") {
|
|
190
|
+
prismaPath = fileURLToPath(import.meta.resolve("prisma/build/index.js"));
|
|
191
|
+
} else {
|
|
192
|
+
prismaPath = __require.resolve("prisma/build/index.js");
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
if (!prismaPath) {
|
|
197
|
+
execPackage(`prisma ${args}`, options);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
execSync(`node ${prismaPath} ${args}`, options);
|
|
201
|
+
}
|
|
202
|
+
__name(execPrisma, "execPrisma");
|
|
203
|
+
|
|
176
204
|
// src/actions/db.ts
|
|
177
|
-
async function
|
|
205
|
+
async function run2(command, options) {
|
|
178
206
|
switch (command) {
|
|
179
207
|
case "push":
|
|
180
208
|
await runPush(options);
|
|
181
209
|
break;
|
|
182
210
|
}
|
|
183
211
|
}
|
|
184
|
-
__name(
|
|
212
|
+
__name(run2, "run");
|
|
185
213
|
async function runPush(options) {
|
|
186
214
|
const schemaFile = getSchemaFile(options.schema);
|
|
187
215
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
@@ -206,11 +234,29 @@ async function runPush(options) {
|
|
|
206
234
|
}
|
|
207
235
|
__name(runPush, "runPush");
|
|
208
236
|
|
|
237
|
+
// src/actions/format.ts
|
|
238
|
+
import { formatDocument } from "@zenstackhq/language";
|
|
239
|
+
import colors3 from "colors";
|
|
240
|
+
import fs3 from "fs";
|
|
241
|
+
async function run3(options) {
|
|
242
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
243
|
+
let formattedContent;
|
|
244
|
+
try {
|
|
245
|
+
formattedContent = await formatDocument(fs3.readFileSync(schemaFile, "utf-8"));
|
|
246
|
+
} catch (error) {
|
|
247
|
+
console.error(colors3.red("\u2717 Schema formatting failed."));
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
fs3.writeFileSync(schemaFile, formattedContent, "utf-8");
|
|
251
|
+
console.log(colors3.green("\u2713 Schema formatting completed successfully."));
|
|
252
|
+
}
|
|
253
|
+
__name(run3, "run");
|
|
254
|
+
|
|
209
255
|
// src/actions/generate.ts
|
|
210
256
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
211
257
|
import { isPlugin } from "@zenstackhq/language/ast";
|
|
212
258
|
import { getLiteral, getLiteralArray } from "@zenstackhq/language/utils";
|
|
213
|
-
import
|
|
259
|
+
import colors4 from "colors";
|
|
214
260
|
import path4 from "path";
|
|
215
261
|
import ora from "ora";
|
|
216
262
|
|
|
@@ -223,7 +269,7 @@ __export(plugins_exports, {
|
|
|
223
269
|
|
|
224
270
|
// src/plugins/prisma.ts
|
|
225
271
|
import { PrismaSchemaGenerator as PrismaSchemaGenerator2 } from "@zenstackhq/sdk";
|
|
226
|
-
import
|
|
272
|
+
import fs4 from "fs";
|
|
227
273
|
import path2 from "path";
|
|
228
274
|
var plugin = {
|
|
229
275
|
name: "Prisma Schema Generator",
|
|
@@ -232,21 +278,21 @@ var plugin = {
|
|
|
232
278
|
let outFile = path2.join(defaultOutputPath, "schema.prisma");
|
|
233
279
|
if (typeof pluginOptions["output"] === "string") {
|
|
234
280
|
outFile = path2.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
235
|
-
if (!
|
|
236
|
-
|
|
281
|
+
if (!fs4.existsSync(path2.dirname(outFile))) {
|
|
282
|
+
fs4.mkdirSync(path2.dirname(outFile), {
|
|
237
283
|
recursive: true
|
|
238
284
|
});
|
|
239
285
|
}
|
|
240
286
|
}
|
|
241
287
|
const prismaSchema = await new PrismaSchemaGenerator2(model).generate();
|
|
242
|
-
|
|
288
|
+
fs4.writeFileSync(outFile, prismaSchema);
|
|
243
289
|
}
|
|
244
290
|
};
|
|
245
291
|
var prisma_default = plugin;
|
|
246
292
|
|
|
247
293
|
// src/plugins/typescript.ts
|
|
248
294
|
import { TsSchemaGenerator } from "@zenstackhq/sdk";
|
|
249
|
-
import
|
|
295
|
+
import fs5 from "fs";
|
|
250
296
|
import path3 from "path";
|
|
251
297
|
var plugin2 = {
|
|
252
298
|
name: "TypeScript Schema Generator",
|
|
@@ -255,32 +301,37 @@ var plugin2 = {
|
|
|
255
301
|
let outDir = defaultOutputPath;
|
|
256
302
|
if (typeof pluginOptions["output"] === "string") {
|
|
257
303
|
outDir = path3.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
258
|
-
if (!
|
|
259
|
-
|
|
304
|
+
if (!fs5.existsSync(outDir)) {
|
|
305
|
+
fs5.mkdirSync(outDir, {
|
|
260
306
|
recursive: true
|
|
261
307
|
});
|
|
262
308
|
}
|
|
263
309
|
}
|
|
264
310
|
const lite = pluginOptions["lite"] === true;
|
|
265
311
|
const liteOnly = pluginOptions["liteOnly"] === true;
|
|
312
|
+
const importWithFileExtension = pluginOptions["importWithFileExtension"];
|
|
313
|
+
if (importWithFileExtension && typeof importWithFileExtension !== "string") {
|
|
314
|
+
throw new Error('The "importWithFileExtension" option must be a string if specified.');
|
|
315
|
+
}
|
|
266
316
|
await new TsSchemaGenerator().generate(model, {
|
|
267
317
|
outDir,
|
|
268
318
|
lite,
|
|
269
|
-
liteOnly
|
|
319
|
+
liteOnly,
|
|
320
|
+
importWithFileExtension
|
|
270
321
|
});
|
|
271
322
|
}
|
|
272
323
|
};
|
|
273
324
|
var typescript_default = plugin2;
|
|
274
325
|
|
|
275
326
|
// src/actions/generate.ts
|
|
276
|
-
async function
|
|
327
|
+
async function run4(options) {
|
|
277
328
|
const start = Date.now();
|
|
278
329
|
const schemaFile = getSchemaFile(options.schema);
|
|
279
330
|
const model = await loadSchemaDocument(schemaFile);
|
|
280
331
|
const outputPath = getOutputPath(options, schemaFile);
|
|
281
332
|
await runPlugins(schemaFile, model, outputPath, options);
|
|
282
333
|
if (!options.silent) {
|
|
283
|
-
console.log(
|
|
334
|
+
console.log(colors4.green(`Generation completed successfully in ${Date.now() - start}ms.
|
|
284
335
|
`));
|
|
285
336
|
console.log(`You can now create a ZenStack client with it.
|
|
286
337
|
|
|
@@ -296,7 +347,7 @@ const client = new ZenStackClient(schema, {
|
|
|
296
347
|
Check documentation: https://zenstack.dev/docs/3.x`);
|
|
297
348
|
}
|
|
298
349
|
}
|
|
299
|
-
__name(
|
|
350
|
+
__name(run4, "run");
|
|
300
351
|
function getOutputPath(options, schemaFile) {
|
|
301
352
|
if (options.output) {
|
|
302
353
|
return options.output;
|
|
@@ -331,9 +382,18 @@ async function runPlugins(schemaFile, model, outputPath, options) {
|
|
|
331
382
|
}
|
|
332
383
|
}
|
|
333
384
|
if (cliPlugin) {
|
|
385
|
+
const pluginOptions = getPluginOptions(plugin3);
|
|
386
|
+
if (provider === "@core/typescript") {
|
|
387
|
+
if (pluginOptions["lite"] === void 0) {
|
|
388
|
+
pluginOptions["lite"] = options.lite;
|
|
389
|
+
}
|
|
390
|
+
if (pluginOptions["liteOnly"] === void 0) {
|
|
391
|
+
pluginOptions["liteOnly"] = options.liteOnly;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
334
394
|
processedPlugins.push({
|
|
335
395
|
cliPlugin,
|
|
336
|
-
pluginOptions
|
|
396
|
+
pluginOptions
|
|
337
397
|
});
|
|
338
398
|
}
|
|
339
399
|
}
|
|
@@ -400,9 +460,9 @@ function getPluginOptions(plugin3) {
|
|
|
400
460
|
__name(getPluginOptions, "getPluginOptions");
|
|
401
461
|
|
|
402
462
|
// src/actions/info.ts
|
|
403
|
-
import
|
|
463
|
+
import colors5 from "colors";
|
|
404
464
|
import path5 from "path";
|
|
405
|
-
async function
|
|
465
|
+
async function run5(projectPath) {
|
|
406
466
|
const packages = await getZenStackPackages(projectPath);
|
|
407
467
|
if (!packages) {
|
|
408
468
|
console.error("Unable to locate package.json. Are you in a valid project directory?");
|
|
@@ -414,13 +474,13 @@ async function run3(projectPath) {
|
|
|
414
474
|
if (version2) {
|
|
415
475
|
versions.add(version2);
|
|
416
476
|
}
|
|
417
|
-
console.log(` ${
|
|
477
|
+
console.log(` ${colors5.green(pkg.padEnd(20))} ${version2}`);
|
|
418
478
|
}
|
|
419
479
|
if (versions.size > 1) {
|
|
420
|
-
console.warn(
|
|
480
|
+
console.warn(colors5.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
|
|
421
481
|
}
|
|
422
482
|
}
|
|
423
|
-
__name(
|
|
483
|
+
__name(run5, "run");
|
|
424
484
|
async function getZenStackPackages(projectPath) {
|
|
425
485
|
let pkgJson;
|
|
426
486
|
const resolvedPath = path5.resolve(projectPath);
|
|
@@ -463,8 +523,8 @@ async function getZenStackPackages(projectPath) {
|
|
|
463
523
|
__name(getZenStackPackages, "getZenStackPackages");
|
|
464
524
|
|
|
465
525
|
// src/actions/init.ts
|
|
466
|
-
import
|
|
467
|
-
import
|
|
526
|
+
import colors6 from "colors";
|
|
527
|
+
import fs6 from "fs";
|
|
468
528
|
import path6 from "path";
|
|
469
529
|
import ora2 from "ora";
|
|
470
530
|
import { detect, resolveCommand } from "package-manager-detector";
|
|
@@ -499,7 +559,7 @@ model Post {
|
|
|
499
559
|
`;
|
|
500
560
|
|
|
501
561
|
// src/actions/init.ts
|
|
502
|
-
async function
|
|
562
|
+
async function run6(projectPath) {
|
|
503
563
|
const packages = [
|
|
504
564
|
{
|
|
505
565
|
name: "@zenstackhq/cli@next",
|
|
@@ -517,7 +577,7 @@ async function run4(projectPath) {
|
|
|
517
577
|
name: "npm"
|
|
518
578
|
};
|
|
519
579
|
}
|
|
520
|
-
console.log(
|
|
580
|
+
console.log(colors6.gray(`Using package manager: ${pm.agent}`));
|
|
521
581
|
for (const pkg of packages) {
|
|
522
582
|
const resolved = resolveCommand(pm.agent, "install", [
|
|
523
583
|
pkg.name,
|
|
@@ -540,24 +600,24 @@ async function run4(projectPath) {
|
|
|
540
600
|
}
|
|
541
601
|
}
|
|
542
602
|
const generationFolder = "zenstack";
|
|
543
|
-
if (!
|
|
544
|
-
|
|
603
|
+
if (!fs6.existsSync(path6.join(projectPath, generationFolder))) {
|
|
604
|
+
fs6.mkdirSync(path6.join(projectPath, generationFolder));
|
|
545
605
|
}
|
|
546
|
-
if (!
|
|
547
|
-
|
|
606
|
+
if (!fs6.existsSync(path6.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
607
|
+
fs6.writeFileSync(path6.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
548
608
|
} else {
|
|
549
|
-
console.log(
|
|
609
|
+
console.log(colors6.yellow("Schema file already exists. Skipping generation of sample."));
|
|
550
610
|
}
|
|
551
|
-
console.log(
|
|
552
|
-
console.log(
|
|
553
|
-
console.log(
|
|
611
|
+
console.log(colors6.green("ZenStack project initialized successfully!"));
|
|
612
|
+
console.log(colors6.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
|
|
613
|
+
console.log(colors6.gray("Run `zenstack generate` to compile the the schema into a TypeScript file."));
|
|
554
614
|
}
|
|
555
|
-
__name(
|
|
615
|
+
__name(run6, "run");
|
|
556
616
|
|
|
557
617
|
// src/actions/migrate.ts
|
|
558
|
-
import
|
|
618
|
+
import fs7 from "fs";
|
|
559
619
|
import path7 from "path";
|
|
560
|
-
async function
|
|
620
|
+
async function run7(command, options) {
|
|
561
621
|
const schemaFile = getSchemaFile(options.schema);
|
|
562
622
|
const prismaSchemaDir = options.migrations ? path7.dirname(options.migrations) : void 0;
|
|
563
623
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
|
|
@@ -580,12 +640,12 @@ async function run5(command, options) {
|
|
|
580
640
|
break;
|
|
581
641
|
}
|
|
582
642
|
} finally {
|
|
583
|
-
if (
|
|
584
|
-
|
|
643
|
+
if (fs7.existsSync(prismaSchemaFile)) {
|
|
644
|
+
fs7.unlinkSync(prismaSchemaFile);
|
|
585
645
|
}
|
|
586
646
|
}
|
|
587
647
|
}
|
|
588
|
-
__name(
|
|
648
|
+
__name(run7, "run");
|
|
589
649
|
function runDev(prismaSchemaFile, options) {
|
|
590
650
|
try {
|
|
591
651
|
const cmd = [
|
|
@@ -661,24 +721,10 @@ function handleSubProcessError2(err) {
|
|
|
661
721
|
}
|
|
662
722
|
__name(handleSubProcessError2, "handleSubProcessError");
|
|
663
723
|
|
|
664
|
-
// src/actions/check.ts
|
|
665
|
-
import colors5 from "colors";
|
|
666
|
-
async function run6(options) {
|
|
667
|
-
const schemaFile = getSchemaFile(options.schema);
|
|
668
|
-
try {
|
|
669
|
-
await loadSchemaDocument(schemaFile);
|
|
670
|
-
console.log(colors5.green("\u2713 Schema validation completed successfully."));
|
|
671
|
-
} catch (error) {
|
|
672
|
-
console.error(colors5.red("\u2717 Schema validation failed."));
|
|
673
|
-
throw error;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
__name(run6, "run");
|
|
677
|
-
|
|
678
724
|
// src/telemetry.ts
|
|
679
725
|
import { init } from "mixpanel";
|
|
680
726
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
681
|
-
import
|
|
727
|
+
import fs12 from "fs";
|
|
682
728
|
import * as os2 from "os";
|
|
683
729
|
|
|
684
730
|
// src/constants.ts
|
|
@@ -689,14 +735,14 @@ import { env } from "process";
|
|
|
689
735
|
var isInCi = env["CI"] !== "0" && env["CI"] !== "false" && ("CI" in env || "CONTINUOUS_INTEGRATION" in env || Object.keys(env).some((key) => key.startsWith("CI_")));
|
|
690
736
|
|
|
691
737
|
// src/utils/is-container.ts
|
|
692
|
-
import
|
|
738
|
+
import fs9 from "fs";
|
|
693
739
|
|
|
694
740
|
// src/utils/is-docker.ts
|
|
695
|
-
import
|
|
741
|
+
import fs8 from "fs";
|
|
696
742
|
var isDockerCached;
|
|
697
743
|
function hasDockerEnv() {
|
|
698
744
|
try {
|
|
699
|
-
|
|
745
|
+
fs8.statSync("/.dockerenv");
|
|
700
746
|
return true;
|
|
701
747
|
} catch {
|
|
702
748
|
return false;
|
|
@@ -705,7 +751,7 @@ function hasDockerEnv() {
|
|
|
705
751
|
__name(hasDockerEnv, "hasDockerEnv");
|
|
706
752
|
function hasDockerCGroup() {
|
|
707
753
|
try {
|
|
708
|
-
return
|
|
754
|
+
return fs8.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
709
755
|
} catch {
|
|
710
756
|
return false;
|
|
711
757
|
}
|
|
@@ -723,7 +769,7 @@ __name(isDocker, "isDocker");
|
|
|
723
769
|
var cachedResult;
|
|
724
770
|
var hasContainerEnv = /* @__PURE__ */ __name(() => {
|
|
725
771
|
try {
|
|
726
|
-
|
|
772
|
+
fs9.statSync("/run/.containerenv");
|
|
727
773
|
return true;
|
|
728
774
|
} catch {
|
|
729
775
|
return false;
|
|
@@ -740,7 +786,7 @@ __name(isInContainer, "isInContainer");
|
|
|
740
786
|
// src/utils/is-wsl.ts
|
|
741
787
|
import process2 from "process";
|
|
742
788
|
import os from "os";
|
|
743
|
-
import
|
|
789
|
+
import fs10 from "fs";
|
|
744
790
|
var isWsl = /* @__PURE__ */ __name(() => {
|
|
745
791
|
if (process2.platform !== "linux") {
|
|
746
792
|
return false;
|
|
@@ -749,7 +795,7 @@ var isWsl = /* @__PURE__ */ __name(() => {
|
|
|
749
795
|
return true;
|
|
750
796
|
}
|
|
751
797
|
try {
|
|
752
|
-
return
|
|
798
|
+
return fs10.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
|
|
753
799
|
} catch {
|
|
754
800
|
return false;
|
|
755
801
|
}
|
|
@@ -813,8 +859,8 @@ function getMachineId() {
|
|
|
813
859
|
__name(getMachineId, "getMachineId");
|
|
814
860
|
|
|
815
861
|
// src/utils/version-utils.ts
|
|
816
|
-
import
|
|
817
|
-
import
|
|
862
|
+
import colors7 from "colors";
|
|
863
|
+
import fs11 from "fs";
|
|
818
864
|
import path8 from "path";
|
|
819
865
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
820
866
|
import semver from "semver";
|
|
@@ -823,7 +869,7 @@ var VERSION_CHECK_TAG = "next";
|
|
|
823
869
|
function getVersion() {
|
|
824
870
|
try {
|
|
825
871
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : path8.dirname(fileURLToPath2(import.meta.url));
|
|
826
|
-
return JSON.parse(
|
|
872
|
+
return JSON.parse(fs11.readFileSync(path8.join(_dirname, "../package.json"), "utf8")).version;
|
|
827
873
|
} catch {
|
|
828
874
|
return void 0;
|
|
829
875
|
}
|
|
@@ -838,7 +884,7 @@ async function checkNewVersion() {
|
|
|
838
884
|
return;
|
|
839
885
|
}
|
|
840
886
|
if (latestVersion && currVersion && semver.gt(latestVersion, currVersion)) {
|
|
841
|
-
console.log(`A newer version ${
|
|
887
|
+
console.log(`A newer version ${colors7.cyan(latestVersion)} is available.`);
|
|
842
888
|
}
|
|
843
889
|
}
|
|
844
890
|
__name(checkNewVersion, "checkNewVersion");
|
|
@@ -953,7 +999,7 @@ var Telemetry = class {
|
|
|
953
999
|
try {
|
|
954
1000
|
const packageJsonPath = import.meta.resolve("prisma/package.json");
|
|
955
1001
|
const packageJsonUrl = new URL(packageJsonPath);
|
|
956
|
-
const packageJson = JSON.parse(
|
|
1002
|
+
const packageJson = JSON.parse(fs12.readFileSync(packageJsonUrl, "utf8"));
|
|
957
1003
|
return packageJson.version;
|
|
958
1004
|
} catch {
|
|
959
1005
|
return void 0;
|
|
@@ -964,45 +1010,49 @@ var telemetry = new Telemetry();
|
|
|
964
1010
|
|
|
965
1011
|
// src/index.ts
|
|
966
1012
|
var generateAction = /* @__PURE__ */ __name(async (options) => {
|
|
967
|
-
await telemetry.trackCommand("generate", () =>
|
|
1013
|
+
await telemetry.trackCommand("generate", () => run4(options));
|
|
968
1014
|
}, "generateAction");
|
|
969
1015
|
var migrateAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
970
|
-
await telemetry.trackCommand(`migrate ${subCommand}`, () =>
|
|
1016
|
+
await telemetry.trackCommand(`migrate ${subCommand}`, () => run7(subCommand, options));
|
|
971
1017
|
}, "migrateAction");
|
|
972
1018
|
var dbAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
973
|
-
await telemetry.trackCommand(`db ${subCommand}`, () =>
|
|
1019
|
+
await telemetry.trackCommand(`db ${subCommand}`, () => run2(subCommand, options));
|
|
974
1020
|
}, "dbAction");
|
|
975
1021
|
var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
976
|
-
await telemetry.trackCommand("info", () =>
|
|
1022
|
+
await telemetry.trackCommand("info", () => run5(projectPath));
|
|
977
1023
|
}, "infoAction");
|
|
978
1024
|
var initAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
979
|
-
await telemetry.trackCommand("init", () =>
|
|
1025
|
+
await telemetry.trackCommand("init", () => run6(projectPath));
|
|
980
1026
|
}, "initAction");
|
|
981
1027
|
var checkAction = /* @__PURE__ */ __name(async (options) => {
|
|
982
|
-
await telemetry.trackCommand("check", () =>
|
|
1028
|
+
await telemetry.trackCommand("check", () => run(options));
|
|
983
1029
|
}, "checkAction");
|
|
1030
|
+
var formatAction = /* @__PURE__ */ __name(async (options) => {
|
|
1031
|
+
await telemetry.trackCommand("format", () => run3(options));
|
|
1032
|
+
}, "formatAction");
|
|
984
1033
|
function createProgram() {
|
|
985
|
-
const program = new Command("zen");
|
|
986
|
-
program.version(getVersion(), "-v --version", "display CLI version");
|
|
1034
|
+
const program = new Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
|
|
987
1035
|
const schemaExtensions = ZModelLanguageMetaData.fileExtensions.join(", ");
|
|
988
|
-
program.description(`${
|
|
1036
|
+
program.description(`${colors8.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
|
|
989
1037
|
|
|
990
1038
|
Documentation: https://zenstack.dev/docs/3.x`).showHelpAfterError().showSuggestionAfterError();
|
|
991
1039
|
const schemaOption = new Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
|
|
992
1040
|
const noVersionCheckOption = new Option("--no-version-check", "do not check for new version");
|
|
993
|
-
program.command("generate").description("Run code generation plugins
|
|
1041
|
+
program.command("generate").description("Run code generation plugins").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new Option("-o, --output <path>", "default output directory for code generation")).addOption(new Option("--lite", "also generate a lite version of schema without attributes").default(false)).addOption(new Option("--lite-only", "only generate lite version of schema without attributes").default(false)).addOption(new Option("--silent", "suppress all output except errors").default(false)).action(generateAction);
|
|
994
1042
|
const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
|
|
995
1043
|
const migrationsOption = new Option("--migrations <path>", 'path that contains the "migrations" directory');
|
|
996
|
-
migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new Option("-n, --name <name>", "migration name")).addOption(new 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
|
|
997
|
-
migrateCommand.command("reset").addOption(schemaOption).addOption(new Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(noVersionCheckOption).description("Reset your database and apply all migrations, all data will be lost
|
|
998
|
-
migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database
|
|
999
|
-
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations
|
|
1000
|
-
migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(new Option("--applied <migration>", "record a specific migration as applied")).addOption(new Option("--rolled-back <migration>", "record a specific migration as rolled back")).description("Resolve issues with database migrations in deployment databases
|
|
1001
|
-
const dbCommand = program.command("db").description("Manage your database schema during development
|
|
1002
|
-
dbCommand.command("push").description("Push the state from your schema to your database
|
|
1003
|
-
program.command("info").description("Get information of installed ZenStack packages
|
|
1004
|
-
program.command("init").description("Initialize an existing project for ZenStack
|
|
1005
|
-
program.command("check").description("Check a ZModel schema for syntax or semantic errors
|
|
1044
|
+
migrateCommand.command("dev").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new Option("-n, --name <name>", "migration name")).addOption(new 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));
|
|
1045
|
+
migrateCommand.command("reset").addOption(schemaOption).addOption(new 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));
|
|
1046
|
+
migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
|
|
1047
|
+
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
|
|
1048
|
+
migrateCommand.command("resolve").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).addOption(new Option("--applied <migration>", "record a specific migration as applied")).addOption(new 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));
|
|
1049
|
+
const dbCommand = program.command("db").description("Manage your database schema during development");
|
|
1050
|
+
dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new Option("--accept-data-loss", "ignore data loss warnings")).addOption(new Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
|
|
1051
|
+
program.command("info").description("Get information of installed ZenStack packages").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(infoAction);
|
|
1052
|
+
program.command("init").description("Initialize an existing project for ZenStack").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(initAction);
|
|
1053
|
+
program.command("check").description("Check a ZModel schema for syntax or semantic errors").addOption(schemaOption).addOption(noVersionCheckOption).action(checkAction);
|
|
1054
|
+
program.command("format").description("Format a ZModel schema file").addOption(schemaOption).addOption(noVersionCheckOption).action(formatAction);
|
|
1055
|
+
program.addHelpCommand("help [command]", "Display help for a command");
|
|
1006
1056
|
program.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
1007
1057
|
if (actionCommand.getOptionValue("versionCheck") !== false) {
|
|
1008
1058
|
await checkNewVersion();
|
|
@@ -1023,10 +1073,10 @@ async function main() {
|
|
|
1023
1073
|
if (e instanceof CommanderError) {
|
|
1024
1074
|
exitCode = e.exitCode;
|
|
1025
1075
|
} else if (e instanceof CliError) {
|
|
1026
|
-
console.error(
|
|
1076
|
+
console.error(colors8.red(e.message));
|
|
1027
1077
|
exitCode = 1;
|
|
1028
1078
|
} else {
|
|
1029
|
-
console.error(
|
|
1079
|
+
console.error(colors8.red(`Unhandled error: ${e}`));
|
|
1030
1080
|
exitCode = 1;
|
|
1031
1081
|
}
|
|
1032
1082
|
}
|