@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/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @zenstackhq/cli@3.0.0-beta.
|
|
2
|
+
> @zenstackhq/cli@3.0.0-beta.24 build /home/runner/work/zenstack-v3/zenstack-v3/packages/cli
|
|
3
3
|
> tsc --noEmit && tsup-node
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts"}
|
|
@@ -10,31 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
You need to set the output format to "esm" for "import.meta" to work correctly.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m"import.meta" is not available with the "cjs" output format and will be empty[0m [empty-import-meta]
|
|
23
|
-
|
|
24
|
-
src/utils/exec-utils.ts:30:35:
|
|
25
|
-
[37m 30 │ ...rismaPath = fileURLToPath([32mimport.meta[37m.resolve('prisma/build/ind...
|
|
26
|
-
╵ [32m~~~~~~~~~~~[0m
|
|
27
|
-
|
|
28
|
-
You need to set the output format to "esm" for "import.meta" to work correctly.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[32mESM[39m [1mdist/index.js [22m[32m33.49 KB[39m
|
|
32
|
-
[32mESM[39m [1mdist/index.js.map [22m[32m70.32 KB[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in 195ms
|
|
34
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m37.29 KB[39m
|
|
35
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m70.85 KB[39m
|
|
36
|
-
[32mCJS[39m ⚡️ Build success in 196ms
|
|
13
|
+
[32mESM[39m [1mdist/index.js [22m[32m35.39 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m74.24 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 184ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m39.33 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m74.81 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 188ms
|
|
37
19
|
[34mDTS[39m Build start
|
|
38
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 3367ms
|
|
39
21
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.00 B[39m
|
|
40
22
|
[32mDTS[39m [1mdist/index.d.cts [22m[32m13.00 B[39m
|
package/dist/index.cjs
CHANGED
|
@@ -28,41 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
));
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
var
|
|
31
|
+
var import_language3 = require("@zenstackhq/language");
|
|
32
|
+
var import_colors8 = __toESM(require("colors"), 1);
|
|
33
33
|
var import_commander = require("commander");
|
|
34
34
|
|
|
35
|
-
// src/actions/
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
// src/utils/exec-utils.ts
|
|
39
|
-
var import_child_process = require("child_process");
|
|
40
|
-
var import_url = require("url");
|
|
41
|
-
var import_meta = {};
|
|
42
|
-
function execSync(cmd, options) {
|
|
43
|
-
const { env: env2, ...restOptions } = options ?? {};
|
|
44
|
-
const mergedEnv = env2 ? {
|
|
45
|
-
...process.env,
|
|
46
|
-
...env2
|
|
47
|
-
} : void 0;
|
|
48
|
-
(0, import_child_process.execSync)(cmd, {
|
|
49
|
-
encoding: "utf-8",
|
|
50
|
-
stdio: options?.stdio ?? "inherit",
|
|
51
|
-
env: mergedEnv,
|
|
52
|
-
...restOptions
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
__name(execSync, "execSync");
|
|
56
|
-
function execPrisma(args, options) {
|
|
57
|
-
let prismaPath;
|
|
58
|
-
if (typeof import_meta.resolve === "function") {
|
|
59
|
-
prismaPath = (0, import_url.fileURLToPath)(import_meta.resolve("prisma/build/index.js"));
|
|
60
|
-
} else {
|
|
61
|
-
prismaPath = require.resolve("prisma/build/index.js");
|
|
62
|
-
}
|
|
63
|
-
execSync(`node ${prismaPath} ${args}`, options);
|
|
64
|
-
}
|
|
65
|
-
__name(execPrisma, "execPrisma");
|
|
35
|
+
// src/actions/check.ts
|
|
36
|
+
var import_colors2 = __toESM(require("colors"), 1);
|
|
66
37
|
|
|
67
38
|
// src/actions/action-utils.ts
|
|
68
39
|
var import_language = require("@zenstackhq/language");
|
|
@@ -102,12 +73,12 @@ function getSchemaFile(file) {
|
|
|
102
73
|
return pkgJsonConfig.schema;
|
|
103
74
|
}
|
|
104
75
|
}
|
|
105
|
-
if (import_node_fs.default.existsSync("./
|
|
106
|
-
return "./zenstack/schema.zmodel";
|
|
107
|
-
} else if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
76
|
+
if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
108
77
|
return "./schema.zmodel";
|
|
78
|
+
} else if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
|
|
79
|
+
return "./zenstack/schema.zmodel";
|
|
109
80
|
} else {
|
|
110
|
-
throw new CliError('Schema file not found in default locations ("./
|
|
81
|
+
throw new CliError('Schema file not found in default locations ("./schema.zmodel" or "./zenstack/schema.zmodel").');
|
|
111
82
|
}
|
|
112
83
|
}
|
|
113
84
|
__name(getSchemaFile, "getSchemaFile");
|
|
@@ -190,15 +161,72 @@ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
|
190
161
|
}
|
|
191
162
|
__name(findUp, "findUp");
|
|
192
163
|
|
|
164
|
+
// src/actions/check.ts
|
|
165
|
+
async function run(options) {
|
|
166
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
167
|
+
try {
|
|
168
|
+
await loadSchemaDocument(schemaFile);
|
|
169
|
+
console.log(import_colors2.default.green("\u2713 Schema validation completed successfully."));
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error(import_colors2.default.red("\u2717 Schema validation failed."));
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
__name(run, "run");
|
|
176
|
+
|
|
177
|
+
// src/actions/db.ts
|
|
178
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
179
|
+
|
|
180
|
+
// src/utils/exec-utils.ts
|
|
181
|
+
var import_child_process = require("child_process");
|
|
182
|
+
var import_url = require("url");
|
|
183
|
+
var import_meta = {};
|
|
184
|
+
function execSync(cmd, options) {
|
|
185
|
+
const { env: env2, ...restOptions } = options ?? {};
|
|
186
|
+
const mergedEnv = env2 ? {
|
|
187
|
+
...process.env,
|
|
188
|
+
...env2
|
|
189
|
+
} : void 0;
|
|
190
|
+
(0, import_child_process.execSync)(cmd, {
|
|
191
|
+
encoding: "utf-8",
|
|
192
|
+
stdio: options?.stdio ?? "inherit",
|
|
193
|
+
env: mergedEnv,
|
|
194
|
+
...restOptions
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
__name(execSync, "execSync");
|
|
198
|
+
function execPackage(cmd, options) {
|
|
199
|
+
const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
|
|
200
|
+
execSync(`${packageManager} ${cmd}`, options);
|
|
201
|
+
}
|
|
202
|
+
__name(execPackage, "execPackage");
|
|
203
|
+
function execPrisma(args, options) {
|
|
204
|
+
let prismaPath;
|
|
205
|
+
try {
|
|
206
|
+
if (typeof import_meta.resolve === "function") {
|
|
207
|
+
prismaPath = (0, import_url.fileURLToPath)(import_meta.resolve("prisma/build/index.js"));
|
|
208
|
+
} else {
|
|
209
|
+
prismaPath = require.resolve("prisma/build/index.js");
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
if (!prismaPath) {
|
|
214
|
+
execPackage(`prisma ${args}`, options);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
execSync(`node ${prismaPath} ${args}`, options);
|
|
218
|
+
}
|
|
219
|
+
__name(execPrisma, "execPrisma");
|
|
220
|
+
|
|
193
221
|
// src/actions/db.ts
|
|
194
|
-
async function
|
|
222
|
+
async function run2(command, options) {
|
|
195
223
|
switch (command) {
|
|
196
224
|
case "push":
|
|
197
225
|
await runPush(options);
|
|
198
226
|
break;
|
|
199
227
|
}
|
|
200
228
|
}
|
|
201
|
-
__name(
|
|
229
|
+
__name(run2, "run");
|
|
202
230
|
async function runPush(options) {
|
|
203
231
|
const schemaFile = getSchemaFile(options.schema);
|
|
204
232
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
@@ -223,11 +251,29 @@ async function runPush(options) {
|
|
|
223
251
|
}
|
|
224
252
|
__name(runPush, "runPush");
|
|
225
253
|
|
|
254
|
+
// src/actions/format.ts
|
|
255
|
+
var import_language2 = require("@zenstackhq/language");
|
|
256
|
+
var import_colors3 = __toESM(require("colors"), 1);
|
|
257
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
258
|
+
async function run3(options) {
|
|
259
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
260
|
+
let formattedContent;
|
|
261
|
+
try {
|
|
262
|
+
formattedContent = await (0, import_language2.formatDocument)(import_node_fs3.default.readFileSync(schemaFile, "utf-8"));
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.error(import_colors3.default.red("\u2717 Schema formatting failed."));
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
import_node_fs3.default.writeFileSync(schemaFile, formattedContent, "utf-8");
|
|
268
|
+
console.log(import_colors3.default.green("\u2713 Schema formatting completed successfully."));
|
|
269
|
+
}
|
|
270
|
+
__name(run3, "run");
|
|
271
|
+
|
|
226
272
|
// src/actions/generate.ts
|
|
227
273
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
228
274
|
var import_ast2 = require("@zenstackhq/language/ast");
|
|
229
275
|
var import_utils = require("@zenstackhq/language/utils");
|
|
230
|
-
var
|
|
276
|
+
var import_colors4 = __toESM(require("colors"), 1);
|
|
231
277
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
232
278
|
var import_ora = __toESM(require("ora"), 1);
|
|
233
279
|
|
|
@@ -240,7 +286,7 @@ __export(plugins_exports, {
|
|
|
240
286
|
|
|
241
287
|
// src/plugins/prisma.ts
|
|
242
288
|
var import_sdk2 = require("@zenstackhq/sdk");
|
|
243
|
-
var
|
|
289
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
244
290
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
245
291
|
var plugin = {
|
|
246
292
|
name: "Prisma Schema Generator",
|
|
@@ -249,21 +295,21 @@ var plugin = {
|
|
|
249
295
|
let outFile = import_node_path2.default.join(defaultOutputPath, "schema.prisma");
|
|
250
296
|
if (typeof pluginOptions["output"] === "string") {
|
|
251
297
|
outFile = import_node_path2.default.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
252
|
-
if (!
|
|
253
|
-
|
|
298
|
+
if (!import_node_fs4.default.existsSync(import_node_path2.default.dirname(outFile))) {
|
|
299
|
+
import_node_fs4.default.mkdirSync(import_node_path2.default.dirname(outFile), {
|
|
254
300
|
recursive: true
|
|
255
301
|
});
|
|
256
302
|
}
|
|
257
303
|
}
|
|
258
304
|
const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
|
|
259
|
-
|
|
305
|
+
import_node_fs4.default.writeFileSync(outFile, prismaSchema);
|
|
260
306
|
}
|
|
261
307
|
};
|
|
262
308
|
var prisma_default = plugin;
|
|
263
309
|
|
|
264
310
|
// src/plugins/typescript.ts
|
|
265
311
|
var import_sdk3 = require("@zenstackhq/sdk");
|
|
266
|
-
var
|
|
312
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
267
313
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
268
314
|
var plugin2 = {
|
|
269
315
|
name: "TypeScript Schema Generator",
|
|
@@ -272,32 +318,37 @@ var plugin2 = {
|
|
|
272
318
|
let outDir = defaultOutputPath;
|
|
273
319
|
if (typeof pluginOptions["output"] === "string") {
|
|
274
320
|
outDir = import_node_path3.default.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
275
|
-
if (!
|
|
276
|
-
|
|
321
|
+
if (!import_node_fs5.default.existsSync(outDir)) {
|
|
322
|
+
import_node_fs5.default.mkdirSync(outDir, {
|
|
277
323
|
recursive: true
|
|
278
324
|
});
|
|
279
325
|
}
|
|
280
326
|
}
|
|
281
327
|
const lite = pluginOptions["lite"] === true;
|
|
282
328
|
const liteOnly = pluginOptions["liteOnly"] === true;
|
|
329
|
+
const importWithFileExtension = pluginOptions["importWithFileExtension"];
|
|
330
|
+
if (importWithFileExtension && typeof importWithFileExtension !== "string") {
|
|
331
|
+
throw new Error('The "importWithFileExtension" option must be a string if specified.');
|
|
332
|
+
}
|
|
283
333
|
await new import_sdk3.TsSchemaGenerator().generate(model, {
|
|
284
334
|
outDir,
|
|
285
335
|
lite,
|
|
286
|
-
liteOnly
|
|
336
|
+
liteOnly,
|
|
337
|
+
importWithFileExtension
|
|
287
338
|
});
|
|
288
339
|
}
|
|
289
340
|
};
|
|
290
341
|
var typescript_default = plugin2;
|
|
291
342
|
|
|
292
343
|
// src/actions/generate.ts
|
|
293
|
-
async function
|
|
344
|
+
async function run4(options) {
|
|
294
345
|
const start = Date.now();
|
|
295
346
|
const schemaFile = getSchemaFile(options.schema);
|
|
296
347
|
const model = await loadSchemaDocument(schemaFile);
|
|
297
348
|
const outputPath = getOutputPath(options, schemaFile);
|
|
298
349
|
await runPlugins(schemaFile, model, outputPath, options);
|
|
299
350
|
if (!options.silent) {
|
|
300
|
-
console.log(
|
|
351
|
+
console.log(import_colors4.default.green(`Generation completed successfully in ${Date.now() - start}ms.
|
|
301
352
|
`));
|
|
302
353
|
console.log(`You can now create a ZenStack client with it.
|
|
303
354
|
|
|
@@ -313,7 +364,7 @@ const client = new ZenStackClient(schema, {
|
|
|
313
364
|
Check documentation: https://zenstack.dev/docs/3.x`);
|
|
314
365
|
}
|
|
315
366
|
}
|
|
316
|
-
__name(
|
|
367
|
+
__name(run4, "run");
|
|
317
368
|
function getOutputPath(options, schemaFile) {
|
|
318
369
|
if (options.output) {
|
|
319
370
|
return options.output;
|
|
@@ -348,9 +399,18 @@ async function runPlugins(schemaFile, model, outputPath, options) {
|
|
|
348
399
|
}
|
|
349
400
|
}
|
|
350
401
|
if (cliPlugin) {
|
|
402
|
+
const pluginOptions = getPluginOptions(plugin3);
|
|
403
|
+
if (provider === "@core/typescript") {
|
|
404
|
+
if (pluginOptions["lite"] === void 0) {
|
|
405
|
+
pluginOptions["lite"] = options.lite;
|
|
406
|
+
}
|
|
407
|
+
if (pluginOptions["liteOnly"] === void 0) {
|
|
408
|
+
pluginOptions["liteOnly"] = options.liteOnly;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
351
411
|
processedPlugins.push({
|
|
352
412
|
cliPlugin,
|
|
353
|
-
pluginOptions
|
|
413
|
+
pluginOptions
|
|
354
414
|
});
|
|
355
415
|
}
|
|
356
416
|
}
|
|
@@ -417,9 +477,9 @@ function getPluginOptions(plugin3) {
|
|
|
417
477
|
__name(getPluginOptions, "getPluginOptions");
|
|
418
478
|
|
|
419
479
|
// src/actions/info.ts
|
|
420
|
-
var
|
|
480
|
+
var import_colors5 = __toESM(require("colors"), 1);
|
|
421
481
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
422
|
-
async function
|
|
482
|
+
async function run5(projectPath) {
|
|
423
483
|
const packages = await getZenStackPackages(projectPath);
|
|
424
484
|
if (!packages) {
|
|
425
485
|
console.error("Unable to locate package.json. Are you in a valid project directory?");
|
|
@@ -431,13 +491,13 @@ async function run3(projectPath) {
|
|
|
431
491
|
if (version2) {
|
|
432
492
|
versions.add(version2);
|
|
433
493
|
}
|
|
434
|
-
console.log(` ${
|
|
494
|
+
console.log(` ${import_colors5.default.green(pkg.padEnd(20))} ${version2}`);
|
|
435
495
|
}
|
|
436
496
|
if (versions.size > 1) {
|
|
437
|
-
console.warn(
|
|
497
|
+
console.warn(import_colors5.default.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
|
|
438
498
|
}
|
|
439
499
|
}
|
|
440
|
-
__name(
|
|
500
|
+
__name(run5, "run");
|
|
441
501
|
async function getZenStackPackages(projectPath) {
|
|
442
502
|
let pkgJson;
|
|
443
503
|
const resolvedPath = import_node_path5.default.resolve(projectPath);
|
|
@@ -480,8 +540,8 @@ async function getZenStackPackages(projectPath) {
|
|
|
480
540
|
__name(getZenStackPackages, "getZenStackPackages");
|
|
481
541
|
|
|
482
542
|
// src/actions/init.ts
|
|
483
|
-
var
|
|
484
|
-
var
|
|
543
|
+
var import_colors6 = __toESM(require("colors"), 1);
|
|
544
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
485
545
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
486
546
|
var import_ora2 = __toESM(require("ora"), 1);
|
|
487
547
|
var import_package_manager_detector = require("package-manager-detector");
|
|
@@ -516,7 +576,7 @@ model Post {
|
|
|
516
576
|
`;
|
|
517
577
|
|
|
518
578
|
// src/actions/init.ts
|
|
519
|
-
async function
|
|
579
|
+
async function run6(projectPath) {
|
|
520
580
|
const packages = [
|
|
521
581
|
{
|
|
522
582
|
name: "@zenstackhq/cli@next",
|
|
@@ -534,7 +594,7 @@ async function run4(projectPath) {
|
|
|
534
594
|
name: "npm"
|
|
535
595
|
};
|
|
536
596
|
}
|
|
537
|
-
console.log(
|
|
597
|
+
console.log(import_colors6.default.gray(`Using package manager: ${pm.agent}`));
|
|
538
598
|
for (const pkg of packages) {
|
|
539
599
|
const resolved = (0, import_package_manager_detector.resolveCommand)(pm.agent, "install", [
|
|
540
600
|
pkg.name,
|
|
@@ -557,24 +617,24 @@ async function run4(projectPath) {
|
|
|
557
617
|
}
|
|
558
618
|
}
|
|
559
619
|
const generationFolder = "zenstack";
|
|
560
|
-
if (!
|
|
561
|
-
|
|
620
|
+
if (!import_node_fs6.default.existsSync(import_node_path6.default.join(projectPath, generationFolder))) {
|
|
621
|
+
import_node_fs6.default.mkdirSync(import_node_path6.default.join(projectPath, generationFolder));
|
|
562
622
|
}
|
|
563
|
-
if (!
|
|
564
|
-
|
|
623
|
+
if (!import_node_fs6.default.existsSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
624
|
+
import_node_fs6.default.writeFileSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
565
625
|
} else {
|
|
566
|
-
console.log(
|
|
626
|
+
console.log(import_colors6.default.yellow("Schema file already exists. Skipping generation of sample."));
|
|
567
627
|
}
|
|
568
|
-
console.log(
|
|
569
|
-
console.log(
|
|
570
|
-
console.log(
|
|
628
|
+
console.log(import_colors6.default.green("ZenStack project initialized successfully!"));
|
|
629
|
+
console.log(import_colors6.default.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
|
|
630
|
+
console.log(import_colors6.default.gray("Run `zenstack generate` to compile the the schema into a TypeScript file."));
|
|
571
631
|
}
|
|
572
|
-
__name(
|
|
632
|
+
__name(run6, "run");
|
|
573
633
|
|
|
574
634
|
// src/actions/migrate.ts
|
|
575
|
-
var
|
|
635
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
576
636
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
577
|
-
async function
|
|
637
|
+
async function run7(command, options) {
|
|
578
638
|
const schemaFile = getSchemaFile(options.schema);
|
|
579
639
|
const prismaSchemaDir = options.migrations ? import_node_path7.default.dirname(options.migrations) : void 0;
|
|
580
640
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
|
|
@@ -597,12 +657,12 @@ async function run5(command, options) {
|
|
|
597
657
|
break;
|
|
598
658
|
}
|
|
599
659
|
} finally {
|
|
600
|
-
if (
|
|
601
|
-
|
|
660
|
+
if (import_node_fs7.default.existsSync(prismaSchemaFile)) {
|
|
661
|
+
import_node_fs7.default.unlinkSync(prismaSchemaFile);
|
|
602
662
|
}
|
|
603
663
|
}
|
|
604
664
|
}
|
|
605
|
-
__name(
|
|
665
|
+
__name(run7, "run");
|
|
606
666
|
function runDev(prismaSchemaFile, options) {
|
|
607
667
|
try {
|
|
608
668
|
const cmd = [
|
|
@@ -678,24 +738,10 @@ function handleSubProcessError2(err) {
|
|
|
678
738
|
}
|
|
679
739
|
__name(handleSubProcessError2, "handleSubProcessError");
|
|
680
740
|
|
|
681
|
-
// src/actions/check.ts
|
|
682
|
-
var import_colors5 = __toESM(require("colors"), 1);
|
|
683
|
-
async function run6(options) {
|
|
684
|
-
const schemaFile = getSchemaFile(options.schema);
|
|
685
|
-
try {
|
|
686
|
-
await loadSchemaDocument(schemaFile);
|
|
687
|
-
console.log(import_colors5.default.green("\u2713 Schema validation completed successfully."));
|
|
688
|
-
} catch (error) {
|
|
689
|
-
console.error(import_colors5.default.red("\u2717 Schema validation failed."));
|
|
690
|
-
throw error;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
__name(run6, "run");
|
|
694
|
-
|
|
695
741
|
// src/telemetry.ts
|
|
696
742
|
var import_mixpanel = require("mixpanel");
|
|
697
743
|
var import_node_crypto2 = require("crypto");
|
|
698
|
-
var
|
|
744
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
699
745
|
var os2 = __toESM(require("os"), 1);
|
|
700
746
|
|
|
701
747
|
// src/constants.ts
|
|
@@ -706,14 +752,14 @@ var import_node_process = require("process");
|
|
|
706
752
|
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_")));
|
|
707
753
|
|
|
708
754
|
// src/utils/is-container.ts
|
|
709
|
-
var
|
|
755
|
+
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
710
756
|
|
|
711
757
|
// src/utils/is-docker.ts
|
|
712
|
-
var
|
|
758
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
713
759
|
var isDockerCached;
|
|
714
760
|
function hasDockerEnv() {
|
|
715
761
|
try {
|
|
716
|
-
|
|
762
|
+
import_node_fs8.default.statSync("/.dockerenv");
|
|
717
763
|
return true;
|
|
718
764
|
} catch {
|
|
719
765
|
return false;
|
|
@@ -722,7 +768,7 @@ function hasDockerEnv() {
|
|
|
722
768
|
__name(hasDockerEnv, "hasDockerEnv");
|
|
723
769
|
function hasDockerCGroup() {
|
|
724
770
|
try {
|
|
725
|
-
return
|
|
771
|
+
return import_node_fs8.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
726
772
|
} catch {
|
|
727
773
|
return false;
|
|
728
774
|
}
|
|
@@ -740,7 +786,7 @@ __name(isDocker, "isDocker");
|
|
|
740
786
|
var cachedResult;
|
|
741
787
|
var hasContainerEnv = /* @__PURE__ */ __name(() => {
|
|
742
788
|
try {
|
|
743
|
-
|
|
789
|
+
import_node_fs9.default.statSync("/run/.containerenv");
|
|
744
790
|
return true;
|
|
745
791
|
} catch {
|
|
746
792
|
return false;
|
|
@@ -757,7 +803,7 @@ __name(isInContainer, "isInContainer");
|
|
|
757
803
|
// src/utils/is-wsl.ts
|
|
758
804
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
759
805
|
var import_node_os = __toESM(require("os"), 1);
|
|
760
|
-
var
|
|
806
|
+
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
761
807
|
var isWsl = /* @__PURE__ */ __name(() => {
|
|
762
808
|
if (import_node_process2.default.platform !== "linux") {
|
|
763
809
|
return false;
|
|
@@ -766,7 +812,7 @@ var isWsl = /* @__PURE__ */ __name(() => {
|
|
|
766
812
|
return true;
|
|
767
813
|
}
|
|
768
814
|
try {
|
|
769
|
-
return
|
|
815
|
+
return import_node_fs10.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
|
|
770
816
|
} catch {
|
|
771
817
|
return false;
|
|
772
818
|
}
|
|
@@ -830,8 +876,8 @@ function getMachineId() {
|
|
|
830
876
|
__name(getMachineId, "getMachineId");
|
|
831
877
|
|
|
832
878
|
// src/utils/version-utils.ts
|
|
833
|
-
var
|
|
834
|
-
var
|
|
879
|
+
var import_colors7 = __toESM(require("colors"), 1);
|
|
880
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
835
881
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
836
882
|
var import_node_url = require("url");
|
|
837
883
|
var import_semver = __toESM(require("semver"), 1);
|
|
@@ -841,7 +887,7 @@ var VERSION_CHECK_TAG = "next";
|
|
|
841
887
|
function getVersion() {
|
|
842
888
|
try {
|
|
843
889
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path8.default.dirname((0, import_node_url.fileURLToPath)(import_meta2.url));
|
|
844
|
-
return JSON.parse(
|
|
890
|
+
return JSON.parse(import_node_fs11.default.readFileSync(import_node_path8.default.join(_dirname, "../package.json"), "utf8")).version;
|
|
845
891
|
} catch {
|
|
846
892
|
return void 0;
|
|
847
893
|
}
|
|
@@ -856,7 +902,7 @@ async function checkNewVersion() {
|
|
|
856
902
|
return;
|
|
857
903
|
}
|
|
858
904
|
if (latestVersion && currVersion && import_semver.default.gt(latestVersion, currVersion)) {
|
|
859
|
-
console.log(`A newer version ${
|
|
905
|
+
console.log(`A newer version ${import_colors7.default.cyan(latestVersion)} is available.`);
|
|
860
906
|
}
|
|
861
907
|
}
|
|
862
908
|
__name(checkNewVersion, "checkNewVersion");
|
|
@@ -972,7 +1018,7 @@ var Telemetry = class {
|
|
|
972
1018
|
try {
|
|
973
1019
|
const packageJsonPath = import_meta3.resolve("prisma/package.json");
|
|
974
1020
|
const packageJsonUrl = new URL(packageJsonPath);
|
|
975
|
-
const packageJson = JSON.parse(
|
|
1021
|
+
const packageJson = JSON.parse(import_node_fs12.default.readFileSync(packageJsonUrl, "utf8"));
|
|
976
1022
|
return packageJson.version;
|
|
977
1023
|
} catch {
|
|
978
1024
|
return void 0;
|
|
@@ -983,45 +1029,49 @@ var telemetry = new Telemetry();
|
|
|
983
1029
|
|
|
984
1030
|
// src/index.ts
|
|
985
1031
|
var generateAction = /* @__PURE__ */ __name(async (options) => {
|
|
986
|
-
await telemetry.trackCommand("generate", () =>
|
|
1032
|
+
await telemetry.trackCommand("generate", () => run4(options));
|
|
987
1033
|
}, "generateAction");
|
|
988
1034
|
var migrateAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
989
|
-
await telemetry.trackCommand(`migrate ${subCommand}`, () =>
|
|
1035
|
+
await telemetry.trackCommand(`migrate ${subCommand}`, () => run7(subCommand, options));
|
|
990
1036
|
}, "migrateAction");
|
|
991
1037
|
var dbAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
992
|
-
await telemetry.trackCommand(`db ${subCommand}`, () =>
|
|
1038
|
+
await telemetry.trackCommand(`db ${subCommand}`, () => run2(subCommand, options));
|
|
993
1039
|
}, "dbAction");
|
|
994
1040
|
var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
995
|
-
await telemetry.trackCommand("info", () =>
|
|
1041
|
+
await telemetry.trackCommand("info", () => run5(projectPath));
|
|
996
1042
|
}, "infoAction");
|
|
997
1043
|
var initAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
998
|
-
await telemetry.trackCommand("init", () =>
|
|
1044
|
+
await telemetry.trackCommand("init", () => run6(projectPath));
|
|
999
1045
|
}, "initAction");
|
|
1000
1046
|
var checkAction = /* @__PURE__ */ __name(async (options) => {
|
|
1001
|
-
await telemetry.trackCommand("check", () =>
|
|
1047
|
+
await telemetry.trackCommand("check", () => run(options));
|
|
1002
1048
|
}, "checkAction");
|
|
1049
|
+
var formatAction = /* @__PURE__ */ __name(async (options) => {
|
|
1050
|
+
await telemetry.trackCommand("format", () => run3(options));
|
|
1051
|
+
}, "formatAction");
|
|
1003
1052
|
function createProgram() {
|
|
1004
|
-
const program = new import_commander.Command("zen");
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
program.description(`${import_colors7.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
|
|
1053
|
+
const program = new import_commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
|
|
1054
|
+
const schemaExtensions = import_language3.ZModelLanguageMetaData.fileExtensions.join(", ");
|
|
1055
|
+
program.description(`${import_colors8.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
|
|
1008
1056
|
|
|
1009
1057
|
Documentation: https://zenstack.dev/docs/3.x`).showHelpAfterError().showSuggestionAfterError();
|
|
1010
1058
|
const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
|
|
1011
1059
|
const noVersionCheckOption = new import_commander.Option("--no-version-check", "do not check for new version");
|
|
1012
|
-
program.command("generate").description("Run code generation plugins
|
|
1060
|
+
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);
|
|
1013
1061
|
const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
|
|
1014
1062
|
const migrationsOption = new import_commander.Option("--migrations <path>", 'path that contains the "migrations" directory');
|
|
1015
|
-
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
|
|
1016
|
-
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
|
|
1017
|
-
migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database
|
|
1018
|
-
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations
|
|
1019
|
-
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
|
|
1020
|
-
const dbCommand = program.command("db").description("Manage your database schema during development
|
|
1021
|
-
dbCommand.command("push").description("Push the state from your schema to your database
|
|
1022
|
-
program.command("info").description("Get information of installed ZenStack packages
|
|
1023
|
-
program.command("init").description("Initialize an existing project for ZenStack
|
|
1024
|
-
program.command("check").description("Check a ZModel schema for syntax or semantic errors
|
|
1063
|
+
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));
|
|
1064
|
+
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));
|
|
1065
|
+
migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
|
|
1066
|
+
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
|
|
1067
|
+
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));
|
|
1068
|
+
const dbCommand = program.command("db").description("Manage your database schema during development");
|
|
1069
|
+
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));
|
|
1070
|
+
program.command("info").description("Get information of installed ZenStack packages").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(infoAction);
|
|
1071
|
+
program.command("init").description("Initialize an existing project for ZenStack").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(initAction);
|
|
1072
|
+
program.command("check").description("Check a ZModel schema for syntax or semantic errors").addOption(schemaOption).addOption(noVersionCheckOption).action(checkAction);
|
|
1073
|
+
program.command("format").description("Format a ZModel schema file").addOption(schemaOption).addOption(noVersionCheckOption).action(formatAction);
|
|
1074
|
+
program.addHelpCommand("help [command]", "Display help for a command");
|
|
1025
1075
|
program.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
1026
1076
|
if (actionCommand.getOptionValue("versionCheck") !== false) {
|
|
1027
1077
|
await checkNewVersion();
|
|
@@ -1042,10 +1092,10 @@ async function main() {
|
|
|
1042
1092
|
if (e instanceof import_commander.CommanderError) {
|
|
1043
1093
|
exitCode = e.exitCode;
|
|
1044
1094
|
} else if (e instanceof CliError) {
|
|
1045
|
-
console.error(
|
|
1095
|
+
console.error(import_colors8.default.red(e.message));
|
|
1046
1096
|
exitCode = 1;
|
|
1047
1097
|
} else {
|
|
1048
|
-
console.error(
|
|
1098
|
+
console.error(import_colors8.default.red(`Unhandled error: ${e}`));
|
|
1049
1099
|
exitCode = 1;
|
|
1050
1100
|
}
|
|
1051
1101
|
}
|