@zenstackhq/cli 3.0.0-beta.3 → 3.0.0-beta.30
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 -8
- package/dist/index.cjs +307 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +308 -155
- package/dist/index.js.map +1 -1
- package/package.json +12 -13
- package/src/actions/action-utils.ts +36 -8
- package/src/actions/db.ts +9 -5
- package/src/actions/format.ts +27 -0
- package/src/actions/generate.ts +30 -9
- package/src/actions/index.ts +4 -2
- package/src/actions/init.ts +1 -1
- package/src/actions/migrate.ts +35 -24
- package/src/actions/seed.ts +38 -0
- package/src/actions/templates.ts +1 -1
- package/src/constants.ts +3 -0
- package/src/index.ts +59 -14
- package/src/plugins/prisma.ts +2 -2
- package/src/plugins/typescript.ts +20 -1
- package/src/utils/exec-utils.ts +35 -0
- package/test/db.test.ts +43 -0
- package/test/format.test.ts +33 -0
- package/test/generate.test.ts +29 -0
- package/test/migrate.test.ts +1 -2
- package/test/plugins/prisma-plugin.test.ts +21 -0
- package/test/ts-schema-gen.test.ts +83 -1
package/dist/index.cjs
CHANGED
|
@@ -28,34 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
));
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
var
|
|
31
|
+
var import_language3 = require("@zenstackhq/language");
|
|
32
|
+
var import_colors9 = __toESM(require("colors"), 1);
|
|
33
33
|
var import_commander = require("commander");
|
|
34
34
|
|
|
35
|
-
// src/actions/
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
// src/utils/exec-utils.ts
|
|
39
|
-
var import_child_process = require("child_process");
|
|
40
|
-
function execSync(cmd, options) {
|
|
41
|
-
const { env: env2, ...restOptions } = options ?? {};
|
|
42
|
-
const mergedEnv = env2 ? {
|
|
43
|
-
...process.env,
|
|
44
|
-
...env2
|
|
45
|
-
} : void 0;
|
|
46
|
-
(0, import_child_process.execSync)(cmd, {
|
|
47
|
-
encoding: "utf-8",
|
|
48
|
-
stdio: options?.stdio ?? "inherit",
|
|
49
|
-
env: mergedEnv,
|
|
50
|
-
...restOptions
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
__name(execSync, "execSync");
|
|
54
|
-
function execPackage(cmd, options) {
|
|
55
|
-
const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
|
|
56
|
-
execSync(`${packageManager} ${cmd}`, options);
|
|
57
|
-
}
|
|
58
|
-
__name(execPackage, "execPackage");
|
|
35
|
+
// src/actions/check.ts
|
|
36
|
+
var import_colors2 = __toESM(require("colors"), 1);
|
|
59
37
|
|
|
60
38
|
// src/actions/action-utils.ts
|
|
61
39
|
var import_language = require("@zenstackhq/language");
|
|
@@ -85,14 +63,22 @@ function getSchemaFile(file) {
|
|
|
85
63
|
if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
|
|
86
64
|
throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
|
|
87
65
|
}
|
|
88
|
-
|
|
66
|
+
if (import_node_fs.default.statSync(pkgJsonConfig.schema).isDirectory()) {
|
|
67
|
+
const schemaPath = import_node_path.default.join(pkgJsonConfig.schema, "schema.zmodel");
|
|
68
|
+
if (!import_node_fs.default.existsSync(schemaPath)) {
|
|
69
|
+
throw new CliError(`Schema file not found: ${schemaPath}`);
|
|
70
|
+
}
|
|
71
|
+
return schemaPath;
|
|
72
|
+
} else {
|
|
73
|
+
return pkgJsonConfig.schema;
|
|
74
|
+
}
|
|
89
75
|
}
|
|
90
|
-
if (import_node_fs.default.existsSync("./
|
|
91
|
-
return "./zenstack/schema.zmodel";
|
|
92
|
-
} else if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
76
|
+
if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
93
77
|
return "./schema.zmodel";
|
|
78
|
+
} else if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
|
|
79
|
+
return "./zenstack/schema.zmodel";
|
|
94
80
|
} else {
|
|
95
|
-
throw new CliError('Schema file not found in default locations ("./
|
|
81
|
+
throw new CliError('Schema file not found in default locations ("./schema.zmodel" or "./zenstack/schema.zmodel").');
|
|
96
82
|
}
|
|
97
83
|
}
|
|
98
84
|
__name(getSchemaFile, "getSchemaFile");
|
|
@@ -135,7 +121,8 @@ __name(generateTempPrismaSchema, "generateTempPrismaSchema");
|
|
|
135
121
|
function getPkgJsonConfig(startPath) {
|
|
136
122
|
const result = {
|
|
137
123
|
schema: void 0,
|
|
138
|
-
output: void 0
|
|
124
|
+
output: void 0,
|
|
125
|
+
seed: void 0
|
|
139
126
|
};
|
|
140
127
|
const pkgJsonFile = findUp([
|
|
141
128
|
"package.json"
|
|
@@ -150,8 +137,9 @@ function getPkgJsonConfig(startPath) {
|
|
|
150
137
|
return result;
|
|
151
138
|
}
|
|
152
139
|
if (pkgJson.zenstack && typeof pkgJson.zenstack === "object") {
|
|
153
|
-
result.schema = pkgJson.zenstack.schema && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema);
|
|
154
|
-
result.output = pkgJson.zenstack.output && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output);
|
|
140
|
+
result.schema = pkgJson.zenstack.schema && typeof pkgJson.zenstack.schema === "string" ? import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema) : void 0;
|
|
141
|
+
result.output = pkgJson.zenstack.output && typeof pkgJson.zenstack.output === "string" ? import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output) : void 0;
|
|
142
|
+
result.seed = typeof pkgJson.zenstack.seed === "string" && pkgJson.zenstack.seed ? pkgJson.zenstack.seed : void 0;
|
|
155
143
|
}
|
|
156
144
|
return result;
|
|
157
145
|
}
|
|
@@ -174,29 +162,102 @@ function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
|
174
162
|
return findUp(names, up, multiple, result);
|
|
175
163
|
}
|
|
176
164
|
__name(findUp, "findUp");
|
|
165
|
+
async function requireDataSourceUrl(schemaFile) {
|
|
166
|
+
const zmodel = await loadSchemaDocument(schemaFile);
|
|
167
|
+
const dataSource = zmodel.declarations.find(import_ast.isDataSource);
|
|
168
|
+
if (!dataSource?.fields.some((f) => f.name === "url")) {
|
|
169
|
+
throw new CliError(`The schema's "datasource" must have a "url" field to use this command.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
__name(requireDataSourceUrl, "requireDataSourceUrl");
|
|
173
|
+
|
|
174
|
+
// src/actions/check.ts
|
|
175
|
+
async function run(options) {
|
|
176
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
177
|
+
try {
|
|
178
|
+
await loadSchemaDocument(schemaFile);
|
|
179
|
+
console.log(import_colors2.default.green("\u2713 Schema validation completed successfully."));
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error(import_colors2.default.red("\u2717 Schema validation failed."));
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
__name(run, "run");
|
|
177
186
|
|
|
178
187
|
// src/actions/db.ts
|
|
179
|
-
|
|
188
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
189
|
+
|
|
190
|
+
// src/utils/exec-utils.ts
|
|
191
|
+
var import_child_process = require("child_process");
|
|
192
|
+
var import_url = require("url");
|
|
193
|
+
var import_meta = {};
|
|
194
|
+
function execSync(cmd, options) {
|
|
195
|
+
const { env: env2, ...restOptions } = options ?? {};
|
|
196
|
+
const mergedEnv = env2 ? {
|
|
197
|
+
...process.env,
|
|
198
|
+
...env2
|
|
199
|
+
} : void 0;
|
|
200
|
+
(0, import_child_process.execSync)(cmd, {
|
|
201
|
+
encoding: "utf-8",
|
|
202
|
+
stdio: options?.stdio ?? "inherit",
|
|
203
|
+
env: mergedEnv,
|
|
204
|
+
...restOptions
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
__name(execSync, "execSync");
|
|
208
|
+
function execPackage(cmd, options) {
|
|
209
|
+
const packageManager = process?.versions?.["bun"] ? "bunx" : "npx";
|
|
210
|
+
execSync(`${packageManager} ${cmd}`, options);
|
|
211
|
+
}
|
|
212
|
+
__name(execPackage, "execPackage");
|
|
213
|
+
function execPrisma(args, options) {
|
|
214
|
+
let prismaPath;
|
|
215
|
+
try {
|
|
216
|
+
if (typeof import_meta.resolve === "function") {
|
|
217
|
+
prismaPath = (0, import_url.fileURLToPath)(import_meta.resolve("prisma/build/index.js"));
|
|
218
|
+
} else {
|
|
219
|
+
prismaPath = require.resolve("prisma/build/index.js");
|
|
220
|
+
}
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
const _options = {
|
|
224
|
+
...options,
|
|
225
|
+
env: {
|
|
226
|
+
...options?.env,
|
|
227
|
+
PRISMA_HIDE_UPDATE_MESSAGE: "1"
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
if (!prismaPath) {
|
|
231
|
+
execPackage(`prisma ${args}`, _options);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
execSync(`node ${prismaPath} ${args}`, _options);
|
|
235
|
+
}
|
|
236
|
+
__name(execPrisma, "execPrisma");
|
|
237
|
+
|
|
238
|
+
// src/actions/db.ts
|
|
239
|
+
async function run2(command, options) {
|
|
180
240
|
switch (command) {
|
|
181
241
|
case "push":
|
|
182
242
|
await runPush(options);
|
|
183
243
|
break;
|
|
184
244
|
}
|
|
185
245
|
}
|
|
186
|
-
__name(
|
|
246
|
+
__name(run2, "run");
|
|
187
247
|
async function runPush(options) {
|
|
188
248
|
const schemaFile = getSchemaFile(options.schema);
|
|
249
|
+
await requireDataSourceUrl(schemaFile);
|
|
189
250
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
190
251
|
try {
|
|
191
252
|
const cmd = [
|
|
192
|
-
"
|
|
253
|
+
"db push",
|
|
193
254
|
` --schema "${prismaSchemaFile}"`,
|
|
194
255
|
options.acceptDataLoss ? " --accept-data-loss" : "",
|
|
195
256
|
options.forceReset ? " --force-reset" : "",
|
|
196
257
|
" --skip-generate"
|
|
197
258
|
].join("");
|
|
198
259
|
try {
|
|
199
|
-
|
|
260
|
+
execPrisma(cmd);
|
|
200
261
|
} catch (err) {
|
|
201
262
|
handleSubProcessError(err);
|
|
202
263
|
}
|
|
@@ -208,11 +269,29 @@ async function runPush(options) {
|
|
|
208
269
|
}
|
|
209
270
|
__name(runPush, "runPush");
|
|
210
271
|
|
|
272
|
+
// src/actions/format.ts
|
|
273
|
+
var import_language2 = require("@zenstackhq/language");
|
|
274
|
+
var import_colors3 = __toESM(require("colors"), 1);
|
|
275
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
276
|
+
async function run3(options) {
|
|
277
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
278
|
+
let formattedContent;
|
|
279
|
+
try {
|
|
280
|
+
formattedContent = await (0, import_language2.formatDocument)(import_node_fs3.default.readFileSync(schemaFile, "utf-8"));
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error(import_colors3.default.red("\u2717 Schema formatting failed."));
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
import_node_fs3.default.writeFileSync(schemaFile, formattedContent, "utf-8");
|
|
286
|
+
console.log(import_colors3.default.green("\u2713 Schema formatting completed successfully."));
|
|
287
|
+
}
|
|
288
|
+
__name(run3, "run");
|
|
289
|
+
|
|
211
290
|
// src/actions/generate.ts
|
|
212
291
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
213
292
|
var import_ast2 = require("@zenstackhq/language/ast");
|
|
214
293
|
var import_utils = require("@zenstackhq/language/utils");
|
|
215
|
-
var
|
|
294
|
+
var import_colors4 = __toESM(require("colors"), 1);
|
|
216
295
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
217
296
|
var import_ora = __toESM(require("ora"), 1);
|
|
218
297
|
|
|
@@ -225,30 +304,30 @@ __export(plugins_exports, {
|
|
|
225
304
|
|
|
226
305
|
// src/plugins/prisma.ts
|
|
227
306
|
var import_sdk2 = require("@zenstackhq/sdk");
|
|
228
|
-
var
|
|
307
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
229
308
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
230
309
|
var plugin = {
|
|
231
310
|
name: "Prisma Schema Generator",
|
|
232
311
|
statusText: "Generating Prisma schema",
|
|
233
|
-
async generate({ model,
|
|
312
|
+
async generate({ model, defaultOutputPath, pluginOptions }) {
|
|
234
313
|
let outFile = import_node_path2.default.join(defaultOutputPath, "schema.prisma");
|
|
235
314
|
if (typeof pluginOptions["output"] === "string") {
|
|
236
|
-
outFile = import_node_path2.default.resolve(
|
|
237
|
-
if (!
|
|
238
|
-
|
|
315
|
+
outFile = import_node_path2.default.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
316
|
+
if (!import_node_fs4.default.existsSync(import_node_path2.default.dirname(outFile))) {
|
|
317
|
+
import_node_fs4.default.mkdirSync(import_node_path2.default.dirname(outFile), {
|
|
239
318
|
recursive: true
|
|
240
319
|
});
|
|
241
320
|
}
|
|
242
321
|
}
|
|
243
322
|
const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
|
|
244
|
-
|
|
323
|
+
import_node_fs4.default.writeFileSync(outFile, prismaSchema);
|
|
245
324
|
}
|
|
246
325
|
};
|
|
247
326
|
var prisma_default = plugin;
|
|
248
327
|
|
|
249
328
|
// src/plugins/typescript.ts
|
|
250
329
|
var import_sdk3 = require("@zenstackhq/sdk");
|
|
251
|
-
var
|
|
330
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
252
331
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
253
332
|
var plugin2 = {
|
|
254
333
|
name: "TypeScript Schema Generator",
|
|
@@ -257,31 +336,42 @@ var plugin2 = {
|
|
|
257
336
|
let outDir = defaultOutputPath;
|
|
258
337
|
if (typeof pluginOptions["output"] === "string") {
|
|
259
338
|
outDir = import_node_path3.default.resolve(defaultOutputPath, pluginOptions["output"]);
|
|
260
|
-
if (!
|
|
261
|
-
|
|
339
|
+
if (!import_node_fs5.default.existsSync(outDir)) {
|
|
340
|
+
import_node_fs5.default.mkdirSync(outDir, {
|
|
262
341
|
recursive: true
|
|
263
342
|
});
|
|
264
343
|
}
|
|
265
344
|
}
|
|
266
|
-
|
|
345
|
+
const lite = pluginOptions["lite"] === true;
|
|
346
|
+
const liteOnly = pluginOptions["liteOnly"] === true;
|
|
347
|
+
const importWithFileExtension = pluginOptions["importWithFileExtension"];
|
|
348
|
+
if (importWithFileExtension && typeof importWithFileExtension !== "string") {
|
|
349
|
+
throw new Error('The "importWithFileExtension" option must be a string if specified.');
|
|
350
|
+
}
|
|
351
|
+
await new import_sdk3.TsSchemaGenerator().generate(model, {
|
|
352
|
+
outDir,
|
|
353
|
+
lite,
|
|
354
|
+
liteOnly,
|
|
355
|
+
importWithFileExtension
|
|
356
|
+
});
|
|
267
357
|
}
|
|
268
358
|
};
|
|
269
359
|
var typescript_default = plugin2;
|
|
270
360
|
|
|
271
361
|
// src/actions/generate.ts
|
|
272
|
-
async function
|
|
362
|
+
async function run4(options) {
|
|
273
363
|
const start = Date.now();
|
|
274
364
|
const schemaFile = getSchemaFile(options.schema);
|
|
275
365
|
const model = await loadSchemaDocument(schemaFile);
|
|
276
366
|
const outputPath = getOutputPath(options, schemaFile);
|
|
277
367
|
await runPlugins(schemaFile, model, outputPath, options);
|
|
278
368
|
if (!options.silent) {
|
|
279
|
-
console.log(
|
|
369
|
+
console.log(import_colors4.default.green(`Generation completed successfully in ${Date.now() - start}ms.
|
|
280
370
|
`));
|
|
281
371
|
console.log(`You can now create a ZenStack client with it.
|
|
282
372
|
|
|
283
373
|
\`\`\`ts
|
|
284
|
-
import { ZenStackClient } from '@zenstackhq/
|
|
374
|
+
import { ZenStackClient } from '@zenstackhq/orm';
|
|
285
375
|
import { schema } from '${outputPath}/schema';
|
|
286
376
|
|
|
287
377
|
const client = new ZenStackClient(schema, {
|
|
@@ -292,7 +382,7 @@ const client = new ZenStackClient(schema, {
|
|
|
292
382
|
Check documentation: https://zenstack.dev/docs/3.x`);
|
|
293
383
|
}
|
|
294
384
|
}
|
|
295
|
-
__name(
|
|
385
|
+
__name(run4, "run");
|
|
296
386
|
function getOutputPath(options, schemaFile) {
|
|
297
387
|
if (options.output) {
|
|
298
388
|
return options.output;
|
|
@@ -323,23 +413,39 @@ async function runPlugins(schemaFile, model, outputPath, options) {
|
|
|
323
413
|
}
|
|
324
414
|
try {
|
|
325
415
|
cliPlugin = (await import(moduleSpec)).default;
|
|
326
|
-
} catch
|
|
327
|
-
throw new CliError(`Failed to load plugin ${provider}: ${error}`);
|
|
416
|
+
} catch {
|
|
328
417
|
}
|
|
329
418
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
419
|
+
if (cliPlugin) {
|
|
420
|
+
const pluginOptions = getPluginOptions(plugin3);
|
|
421
|
+
if (provider === "@core/typescript") {
|
|
422
|
+
if (pluginOptions["lite"] === void 0) {
|
|
423
|
+
pluginOptions["lite"] = options.lite;
|
|
424
|
+
}
|
|
425
|
+
if (pluginOptions["liteOnly"] === void 0) {
|
|
426
|
+
pluginOptions["liteOnly"] = options.liteOnly;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
processedPlugins.push({
|
|
430
|
+
cliPlugin,
|
|
431
|
+
pluginOptions
|
|
432
|
+
});
|
|
433
|
+
}
|
|
334
434
|
}
|
|
335
435
|
const defaultPlugins = [
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
436
|
+
{
|
|
437
|
+
plugin: typescript_default,
|
|
438
|
+
options: {
|
|
439
|
+
lite: options.lite,
|
|
440
|
+
liteOnly: options.liteOnly
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
];
|
|
444
|
+
defaultPlugins.forEach(({ plugin: plugin3, options: options2 }) => {
|
|
445
|
+
if (!processedPlugins.some((p) => p.cliPlugin === plugin3)) {
|
|
340
446
|
processedPlugins.push({
|
|
341
|
-
cliPlugin:
|
|
342
|
-
pluginOptions:
|
|
447
|
+
cliPlugin: plugin3,
|
|
448
|
+
pluginOptions: options2
|
|
343
449
|
});
|
|
344
450
|
}
|
|
345
451
|
});
|
|
@@ -389,9 +495,9 @@ function getPluginOptions(plugin3) {
|
|
|
389
495
|
__name(getPluginOptions, "getPluginOptions");
|
|
390
496
|
|
|
391
497
|
// src/actions/info.ts
|
|
392
|
-
var
|
|
498
|
+
var import_colors5 = __toESM(require("colors"), 1);
|
|
393
499
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
394
|
-
async function
|
|
500
|
+
async function run5(projectPath) {
|
|
395
501
|
const packages = await getZenStackPackages(projectPath);
|
|
396
502
|
if (!packages) {
|
|
397
503
|
console.error("Unable to locate package.json. Are you in a valid project directory?");
|
|
@@ -403,13 +509,13 @@ async function run3(projectPath) {
|
|
|
403
509
|
if (version2) {
|
|
404
510
|
versions.add(version2);
|
|
405
511
|
}
|
|
406
|
-
console.log(` ${
|
|
512
|
+
console.log(` ${import_colors5.default.green(pkg.padEnd(20))} ${version2}`);
|
|
407
513
|
}
|
|
408
514
|
if (versions.size > 1) {
|
|
409
|
-
console.warn(
|
|
515
|
+
console.warn(import_colors5.default.yellow("WARNING: Multiple versions of Zenstack packages detected. This may cause issues."));
|
|
410
516
|
}
|
|
411
517
|
}
|
|
412
|
-
__name(
|
|
518
|
+
__name(run5, "run");
|
|
413
519
|
async function getZenStackPackages(projectPath) {
|
|
414
520
|
let pkgJson;
|
|
415
521
|
const resolvedPath = import_node_path5.default.resolve(projectPath);
|
|
@@ -452,8 +558,8 @@ async function getZenStackPackages(projectPath) {
|
|
|
452
558
|
__name(getZenStackPackages, "getZenStackPackages");
|
|
453
559
|
|
|
454
560
|
// src/actions/init.ts
|
|
455
|
-
var
|
|
456
|
-
var
|
|
561
|
+
var import_colors6 = __toESM(require("colors"), 1);
|
|
562
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
457
563
|
var import_node_path6 = __toESM(require("path"), 1);
|
|
458
564
|
var import_ora2 = __toESM(require("ora"), 1);
|
|
459
565
|
var import_package_manager_detector = require("package-manager-detector");
|
|
@@ -488,14 +594,14 @@ model Post {
|
|
|
488
594
|
`;
|
|
489
595
|
|
|
490
596
|
// src/actions/init.ts
|
|
491
|
-
async function
|
|
597
|
+
async function run6(projectPath) {
|
|
492
598
|
const packages = [
|
|
493
599
|
{
|
|
494
600
|
name: "@zenstackhq/cli@next",
|
|
495
601
|
dev: true
|
|
496
602
|
},
|
|
497
603
|
{
|
|
498
|
-
name: "@zenstackhq/
|
|
604
|
+
name: "@zenstackhq/orm@next",
|
|
499
605
|
dev: false
|
|
500
606
|
}
|
|
501
607
|
];
|
|
@@ -506,7 +612,7 @@ async function run4(projectPath) {
|
|
|
506
612
|
name: "npm"
|
|
507
613
|
};
|
|
508
614
|
}
|
|
509
|
-
console.log(
|
|
615
|
+
console.log(import_colors6.default.gray(`Using package manager: ${pm.agent}`));
|
|
510
616
|
for (const pkg of packages) {
|
|
511
617
|
const resolved = (0, import_package_manager_detector.resolveCommand)(pm.agent, "install", [
|
|
512
618
|
pkg.name,
|
|
@@ -529,25 +635,55 @@ async function run4(projectPath) {
|
|
|
529
635
|
}
|
|
530
636
|
}
|
|
531
637
|
const generationFolder = "zenstack";
|
|
532
|
-
if (!
|
|
533
|
-
|
|
638
|
+
if (!import_node_fs6.default.existsSync(import_node_path6.default.join(projectPath, generationFolder))) {
|
|
639
|
+
import_node_fs6.default.mkdirSync(import_node_path6.default.join(projectPath, generationFolder));
|
|
534
640
|
}
|
|
535
|
-
if (!
|
|
536
|
-
|
|
641
|
+
if (!import_node_fs6.default.existsSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
642
|
+
import_node_fs6.default.writeFileSync(import_node_path6.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
537
643
|
} else {
|
|
538
|
-
console.log(
|
|
644
|
+
console.log(import_colors6.default.yellow("Schema file already exists. Skipping generation of sample."));
|
|
539
645
|
}
|
|
540
|
-
console.log(
|
|
541
|
-
console.log(
|
|
542
|
-
console.log(
|
|
646
|
+
console.log(import_colors6.default.green("ZenStack project initialized successfully!"));
|
|
647
|
+
console.log(import_colors6.default.gray(`See "${generationFolder}/schema.zmodel" for your database schema.`));
|
|
648
|
+
console.log(import_colors6.default.gray("Run `zenstack generate` to compile the the schema into a TypeScript file."));
|
|
543
649
|
}
|
|
544
|
-
__name(
|
|
650
|
+
__name(run6, "run");
|
|
545
651
|
|
|
546
652
|
// src/actions/migrate.ts
|
|
547
|
-
var
|
|
653
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
548
654
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
549
|
-
|
|
655
|
+
|
|
656
|
+
// src/actions/seed.ts
|
|
657
|
+
var import_colors7 = __toESM(require("colors"), 1);
|
|
658
|
+
var import_execa = require("execa");
|
|
659
|
+
async function run7(options, args) {
|
|
660
|
+
const pkgJsonConfig = getPkgJsonConfig(process.cwd());
|
|
661
|
+
if (!pkgJsonConfig.seed) {
|
|
662
|
+
if (!options.noWarnings) {
|
|
663
|
+
console.warn(import_colors7.default.yellow("No seed script defined in package.json. Skipping seeding."));
|
|
664
|
+
}
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const command = `${pkgJsonConfig.seed}${args.length > 0 ? " " + args.join(" ") : ""}`;
|
|
668
|
+
if (options.printStatus) {
|
|
669
|
+
console.log(import_colors7.default.gray(`Running seed script "${command}"...`));
|
|
670
|
+
}
|
|
671
|
+
try {
|
|
672
|
+
await (0, import_execa.execaCommand)(command, {
|
|
673
|
+
stdout: "inherit",
|
|
674
|
+
stderr: "inherit"
|
|
675
|
+
});
|
|
676
|
+
} catch (err) {
|
|
677
|
+
console.error(import_colors7.default.red(err instanceof Error ? err.message : String(err)));
|
|
678
|
+
throw new CliError("Failed to seed the database. Please check the error message above for details.");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
__name(run7, "run");
|
|
682
|
+
|
|
683
|
+
// src/actions/migrate.ts
|
|
684
|
+
async function run8(command, options) {
|
|
550
685
|
const schemaFile = getSchemaFile(options.schema);
|
|
686
|
+
await requireDataSourceUrl(schemaFile);
|
|
551
687
|
const prismaSchemaDir = options.migrations ? import_node_path7.default.dirname(options.migrations) : void 0;
|
|
552
688
|
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
|
|
553
689
|
try {
|
|
@@ -569,22 +705,23 @@ async function run5(command, options) {
|
|
|
569
705
|
break;
|
|
570
706
|
}
|
|
571
707
|
} finally {
|
|
572
|
-
if (
|
|
573
|
-
|
|
708
|
+
if (import_node_fs7.default.existsSync(prismaSchemaFile)) {
|
|
709
|
+
import_node_fs7.default.unlinkSync(prismaSchemaFile);
|
|
574
710
|
}
|
|
575
711
|
}
|
|
576
712
|
}
|
|
577
|
-
__name(
|
|
578
|
-
|
|
713
|
+
__name(run8, "run");
|
|
714
|
+
function runDev(prismaSchemaFile, options) {
|
|
579
715
|
try {
|
|
580
716
|
const cmd = [
|
|
581
|
-
"
|
|
717
|
+
"migrate dev",
|
|
582
718
|
` --schema "${prismaSchemaFile}"`,
|
|
583
719
|
" --skip-generate",
|
|
584
|
-
|
|
720
|
+
" --skip-seed",
|
|
721
|
+
options.name ? ` --name "${options.name}"` : "",
|
|
585
722
|
options.createOnly ? " --create-only" : ""
|
|
586
723
|
].join("");
|
|
587
|
-
|
|
724
|
+
execPrisma(cmd);
|
|
588
725
|
} catch (err) {
|
|
589
726
|
handleSubProcessError2(err);
|
|
590
727
|
}
|
|
@@ -593,48 +730,56 @@ __name(runDev, "runDev");
|
|
|
593
730
|
async function runReset(prismaSchemaFile, options) {
|
|
594
731
|
try {
|
|
595
732
|
const cmd = [
|
|
596
|
-
"
|
|
733
|
+
"migrate reset",
|
|
597
734
|
` --schema "${prismaSchemaFile}"`,
|
|
735
|
+
" --skip-generate",
|
|
736
|
+
" --skip-seed",
|
|
598
737
|
options.force ? " --force" : ""
|
|
599
738
|
].join("");
|
|
600
|
-
|
|
739
|
+
execPrisma(cmd);
|
|
601
740
|
} catch (err) {
|
|
602
741
|
handleSubProcessError2(err);
|
|
603
742
|
}
|
|
743
|
+
if (!options.skipSeed) {
|
|
744
|
+
await run7({
|
|
745
|
+
noWarnings: true,
|
|
746
|
+
printStatus: true
|
|
747
|
+
}, []);
|
|
748
|
+
}
|
|
604
749
|
}
|
|
605
750
|
__name(runReset, "runReset");
|
|
606
|
-
|
|
751
|
+
function runDeploy(prismaSchemaFile, _options) {
|
|
607
752
|
try {
|
|
608
753
|
const cmd = [
|
|
609
|
-
"
|
|
754
|
+
"migrate deploy",
|
|
610
755
|
` --schema "${prismaSchemaFile}"`
|
|
611
756
|
].join("");
|
|
612
|
-
|
|
757
|
+
execPrisma(cmd);
|
|
613
758
|
} catch (err) {
|
|
614
759
|
handleSubProcessError2(err);
|
|
615
760
|
}
|
|
616
761
|
}
|
|
617
762
|
__name(runDeploy, "runDeploy");
|
|
618
|
-
|
|
763
|
+
function runStatus(prismaSchemaFile, _options) {
|
|
619
764
|
try {
|
|
620
|
-
|
|
765
|
+
execPrisma(`migrate status --schema "${prismaSchemaFile}"`);
|
|
621
766
|
} catch (err) {
|
|
622
767
|
handleSubProcessError2(err);
|
|
623
768
|
}
|
|
624
769
|
}
|
|
625
770
|
__name(runStatus, "runStatus");
|
|
626
|
-
|
|
771
|
+
function runResolve(prismaSchemaFile, options) {
|
|
627
772
|
if (!options.applied && !options.rolledBack) {
|
|
628
773
|
throw new CliError("Either --applied or --rolled-back option must be provided");
|
|
629
774
|
}
|
|
630
775
|
try {
|
|
631
776
|
const cmd = [
|
|
632
|
-
"
|
|
777
|
+
"migrate resolve",
|
|
633
778
|
` --schema "${prismaSchemaFile}"`,
|
|
634
|
-
options.applied ? ` --applied ${options.applied}` : "",
|
|
635
|
-
options.rolledBack ? ` --rolled-back ${options.rolledBack}` : ""
|
|
779
|
+
options.applied ? ` --applied "${options.applied}"` : "",
|
|
780
|
+
options.rolledBack ? ` --rolled-back "${options.rolledBack}"` : ""
|
|
636
781
|
].join("");
|
|
637
|
-
|
|
782
|
+
execPrisma(cmd);
|
|
638
783
|
} catch (err) {
|
|
639
784
|
handleSubProcessError2(err);
|
|
640
785
|
}
|
|
@@ -649,24 +794,10 @@ function handleSubProcessError2(err) {
|
|
|
649
794
|
}
|
|
650
795
|
__name(handleSubProcessError2, "handleSubProcessError");
|
|
651
796
|
|
|
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
797
|
// src/telemetry.ts
|
|
667
798
|
var import_mixpanel = require("mixpanel");
|
|
668
799
|
var import_node_crypto2 = require("crypto");
|
|
669
|
-
var
|
|
800
|
+
var import_node_fs12 = __toESM(require("fs"), 1);
|
|
670
801
|
var os2 = __toESM(require("os"), 1);
|
|
671
802
|
|
|
672
803
|
// src/constants.ts
|
|
@@ -677,14 +808,14 @@ var import_node_process = require("process");
|
|
|
677
808
|
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
809
|
|
|
679
810
|
// src/utils/is-container.ts
|
|
680
|
-
var
|
|
811
|
+
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
681
812
|
|
|
682
813
|
// src/utils/is-docker.ts
|
|
683
|
-
var
|
|
814
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
684
815
|
var isDockerCached;
|
|
685
816
|
function hasDockerEnv() {
|
|
686
817
|
try {
|
|
687
|
-
|
|
818
|
+
import_node_fs8.default.statSync("/.dockerenv");
|
|
688
819
|
return true;
|
|
689
820
|
} catch {
|
|
690
821
|
return false;
|
|
@@ -693,7 +824,7 @@ function hasDockerEnv() {
|
|
|
693
824
|
__name(hasDockerEnv, "hasDockerEnv");
|
|
694
825
|
function hasDockerCGroup() {
|
|
695
826
|
try {
|
|
696
|
-
return
|
|
827
|
+
return import_node_fs8.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
697
828
|
} catch {
|
|
698
829
|
return false;
|
|
699
830
|
}
|
|
@@ -711,7 +842,7 @@ __name(isDocker, "isDocker");
|
|
|
711
842
|
var cachedResult;
|
|
712
843
|
var hasContainerEnv = /* @__PURE__ */ __name(() => {
|
|
713
844
|
try {
|
|
714
|
-
|
|
845
|
+
import_node_fs9.default.statSync("/run/.containerenv");
|
|
715
846
|
return true;
|
|
716
847
|
} catch {
|
|
717
848
|
return false;
|
|
@@ -728,7 +859,7 @@ __name(isInContainer, "isInContainer");
|
|
|
728
859
|
// src/utils/is-wsl.ts
|
|
729
860
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
730
861
|
var import_node_os = __toESM(require("os"), 1);
|
|
731
|
-
var
|
|
862
|
+
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
732
863
|
var isWsl = /* @__PURE__ */ __name(() => {
|
|
733
864
|
if (import_node_process2.default.platform !== "linux") {
|
|
734
865
|
return false;
|
|
@@ -737,7 +868,7 @@ var isWsl = /* @__PURE__ */ __name(() => {
|
|
|
737
868
|
return true;
|
|
738
869
|
}
|
|
739
870
|
try {
|
|
740
|
-
return
|
|
871
|
+
return import_node_fs10.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
|
|
741
872
|
} catch {
|
|
742
873
|
return false;
|
|
743
874
|
}
|
|
@@ -801,18 +932,18 @@ function getMachineId() {
|
|
|
801
932
|
__name(getMachineId, "getMachineId");
|
|
802
933
|
|
|
803
934
|
// src/utils/version-utils.ts
|
|
804
|
-
var
|
|
805
|
-
var
|
|
935
|
+
var import_colors8 = __toESM(require("colors"), 1);
|
|
936
|
+
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
806
937
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
807
938
|
var import_node_url = require("url");
|
|
808
939
|
var import_semver = __toESM(require("semver"), 1);
|
|
809
|
-
var
|
|
940
|
+
var import_meta2 = {};
|
|
810
941
|
var CHECK_VERSION_TIMEOUT = 2e3;
|
|
811
942
|
var VERSION_CHECK_TAG = "next";
|
|
812
943
|
function getVersion() {
|
|
813
944
|
try {
|
|
814
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path8.default.dirname((0, import_node_url.fileURLToPath)(
|
|
815
|
-
return JSON.parse(
|
|
945
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path8.default.dirname((0, import_node_url.fileURLToPath)(import_meta2.url));
|
|
946
|
+
return JSON.parse(import_node_fs11.default.readFileSync(import_node_path8.default.join(_dirname, "../package.json"), "utf8")).version;
|
|
816
947
|
} catch {
|
|
817
948
|
return void 0;
|
|
818
949
|
}
|
|
@@ -827,7 +958,7 @@ async function checkNewVersion() {
|
|
|
827
958
|
return;
|
|
828
959
|
}
|
|
829
960
|
if (latestVersion && currVersion && import_semver.default.gt(latestVersion, currVersion)) {
|
|
830
|
-
console.log(`A newer version ${
|
|
961
|
+
console.log(`A newer version ${import_colors8.default.cyan(latestVersion)} is available.`);
|
|
831
962
|
}
|
|
832
963
|
}
|
|
833
964
|
__name(checkNewVersion, "checkNewVersion");
|
|
@@ -850,7 +981,7 @@ async function getLatestVersion() {
|
|
|
850
981
|
__name(getLatestVersion, "getLatestVersion");
|
|
851
982
|
|
|
852
983
|
// src/telemetry.ts
|
|
853
|
-
var
|
|
984
|
+
var import_meta3 = {};
|
|
854
985
|
var Telemetry = class {
|
|
855
986
|
static {
|
|
856
987
|
__name(this, "Telemetry");
|
|
@@ -941,9 +1072,9 @@ var Telemetry = class {
|
|
|
941
1072
|
}
|
|
942
1073
|
getPrismaVersion() {
|
|
943
1074
|
try {
|
|
944
|
-
const packageJsonPath =
|
|
1075
|
+
const packageJsonPath = import_meta3.resolve("prisma/package.json");
|
|
945
1076
|
const packageJsonUrl = new URL(packageJsonPath);
|
|
946
|
-
const packageJson = JSON.parse(
|
|
1077
|
+
const packageJson = JSON.parse(import_node_fs12.default.readFileSync(packageJsonUrl, "utf8"));
|
|
947
1078
|
return packageJson.version;
|
|
948
1079
|
} catch {
|
|
949
1080
|
return void 0;
|
|
@@ -954,45 +1085,62 @@ var telemetry = new Telemetry();
|
|
|
954
1085
|
|
|
955
1086
|
// src/index.ts
|
|
956
1087
|
var generateAction = /* @__PURE__ */ __name(async (options) => {
|
|
957
|
-
await telemetry.trackCommand("generate", () =>
|
|
1088
|
+
await telemetry.trackCommand("generate", () => run4(options));
|
|
958
1089
|
}, "generateAction");
|
|
959
1090
|
var migrateAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
960
|
-
await telemetry.trackCommand(`migrate ${subCommand}`, () =>
|
|
1091
|
+
await telemetry.trackCommand(`migrate ${subCommand}`, () => run8(subCommand, options));
|
|
961
1092
|
}, "migrateAction");
|
|
962
1093
|
var dbAction = /* @__PURE__ */ __name(async (subCommand, options) => {
|
|
963
|
-
await telemetry.trackCommand(`db ${subCommand}`, () =>
|
|
1094
|
+
await telemetry.trackCommand(`db ${subCommand}`, () => run2(subCommand, options));
|
|
964
1095
|
}, "dbAction");
|
|
965
1096
|
var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
966
|
-
await telemetry.trackCommand("info", () =>
|
|
1097
|
+
await telemetry.trackCommand("info", () => run5(projectPath));
|
|
967
1098
|
}, "infoAction");
|
|
968
1099
|
var initAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
969
|
-
await telemetry.trackCommand("init", () =>
|
|
1100
|
+
await telemetry.trackCommand("init", () => run6(projectPath));
|
|
970
1101
|
}, "initAction");
|
|
971
1102
|
var checkAction = /* @__PURE__ */ __name(async (options) => {
|
|
972
|
-
await telemetry.trackCommand("check", () =>
|
|
1103
|
+
await telemetry.trackCommand("check", () => run(options));
|
|
973
1104
|
}, "checkAction");
|
|
1105
|
+
var formatAction = /* @__PURE__ */ __name(async (options) => {
|
|
1106
|
+
await telemetry.trackCommand("format", () => run3(options));
|
|
1107
|
+
}, "formatAction");
|
|
1108
|
+
var seedAction = /* @__PURE__ */ __name(async (options, args) => {
|
|
1109
|
+
await telemetry.trackCommand("db seed", () => run7(options, args));
|
|
1110
|
+
}, "seedAction");
|
|
974
1111
|
function createProgram() {
|
|
975
|
-
const program = new import_commander.Command("zen");
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
program.description(`${import_colors7.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
|
|
1112
|
+
const program = new import_commander.Command("zen").alias("zenstack").helpOption("-h, --help", "Show this help message").version(getVersion(), "-v --version", "Show CLI version");
|
|
1113
|
+
const schemaExtensions = import_language3.ZModelLanguageMetaData.fileExtensions.join(", ");
|
|
1114
|
+
program.description(`${import_colors9.default.bold.blue("\u03B6")} ZenStack is the data layer for modern TypeScript apps.
|
|
979
1115
|
|
|
980
1116
|
Documentation: https://zenstack.dev/docs/3.x`).showHelpAfterError().showSuggestionAfterError();
|
|
981
1117
|
const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "zenstack/schema.zmodel" unless specified in package.json.`);
|
|
982
1118
|
const noVersionCheckOption = new import_commander.Option("--no-version-check", "do not check for new version");
|
|
983
|
-
program.command("generate").description("Run code generation plugins
|
|
1119
|
+
program.command("generate").description("Run code generation plugins").addOption(schemaOption).addOption(noVersionCheckOption).addOption(new import_commander.Option("-o, --output <path>", "default output directory for code generation")).addOption(new import_commander.Option("--lite", "also generate a lite version of schema without attributes").default(false)).addOption(new import_commander.Option("--lite-only", "only generate lite version of schema without attributes").default(false)).addOption(new import_commander.Option("--silent", "suppress all output except errors").default(false)).action(generateAction);
|
|
984
1120
|
const migrateCommand = program.command("migrate").description("Run database schema migration related tasks.");
|
|
985
1121
|
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
|
|
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
|
|
989
|
-
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations
|
|
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
|
|
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
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1122
|
+
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));
|
|
1123
|
+
migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).addOption(new import_commander.Option("--skip-seed", "skip seeding the database after reset")).addOption(noVersionCheckOption).description("Reset your database and apply all migrations, all data will be lost").addHelpText("after", "\nIf there is a seed script defined in package.json, it will be run after the reset. Use --skip-seed to skip it.").action((options) => migrateAction("reset", options));
|
|
1124
|
+
migrateCommand.command("deploy").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database").action((options) => migrateAction("deploy", options));
|
|
1125
|
+
migrateCommand.command("status").addOption(schemaOption).addOption(noVersionCheckOption).addOption(migrationsOption).description("Check the status of your database migrations").action((options) => migrateAction("status", options));
|
|
1126
|
+
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));
|
|
1127
|
+
const dbCommand = program.command("db").description("Manage your database schema during development");
|
|
1128
|
+
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));
|
|
1129
|
+
dbCommand.command("seed").description("Seed the database").allowExcessArguments(true).addHelpText("after", `
|
|
1130
|
+
Seed script is configured under the "zenstack.seed" field in package.json.
|
|
1131
|
+
E.g.:
|
|
1132
|
+
{
|
|
1133
|
+
"zenstack": {
|
|
1134
|
+
"seed": "ts-node ./zenstack/seed.ts"
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
Arguments following -- are passed to the seed script. E.g.: "zen db seed -- --users 10"`).addOption(noVersionCheckOption).action((options, command) => seedAction(options, command.args));
|
|
1139
|
+
program.command("info").description("Get information of installed ZenStack packages").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(infoAction);
|
|
1140
|
+
program.command("init").description("Initialize an existing project for ZenStack").argument("[path]", "project path", ".").addOption(noVersionCheckOption).action(initAction);
|
|
1141
|
+
program.command("check").description("Check a ZModel schema for syntax or semantic errors").addOption(schemaOption).addOption(noVersionCheckOption).action(checkAction);
|
|
1142
|
+
program.command("format").description("Format a ZModel schema file").addOption(schemaOption).addOption(noVersionCheckOption).action(formatAction);
|
|
1143
|
+
program.addHelpCommand("help [command]", "Display help for a command");
|
|
996
1144
|
program.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
997
1145
|
if (actionCommand.getOptionValue("versionCheck") !== false) {
|
|
998
1146
|
await checkNewVersion();
|
|
@@ -1013,10 +1161,10 @@ async function main() {
|
|
|
1013
1161
|
if (e instanceof import_commander.CommanderError) {
|
|
1014
1162
|
exitCode = e.exitCode;
|
|
1015
1163
|
} else if (e instanceof CliError) {
|
|
1016
|
-
console.error(
|
|
1164
|
+
console.error(import_colors9.default.red(e.message));
|
|
1017
1165
|
exitCode = 1;
|
|
1018
1166
|
} else {
|
|
1019
|
-
console.error(
|
|
1167
|
+
console.error(import_colors9.default.red(`Unhandled error: ${e}`));
|
|
1020
1168
|
exitCode = 1;
|
|
1021
1169
|
}
|
|
1022
1170
|
}
|