@zenstackhq/cli 3.0.0-alpha.0 → 3.0.0-alpha.10
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 +22 -23
- package/bin/cli +1 -1
- package/dist/index.cjs +175 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +175 -167
- package/dist/index.js.map +1 -1
- package/eslint.config.js +4 -0
- package/package.json +13 -15
- package/src/actions/action-utils.ts +46 -8
- package/src/actions/db.ts +30 -29
- package/src/actions/generate.ts +32 -18
- package/src/actions/info.ts +9 -18
- package/src/actions/init.ts +8 -29
- package/src/actions/migrate.ts +59 -64
- package/src/actions/templates.ts +6 -1
- package/src/index.ts +18 -39
- package/src/utils/exec-utils.ts +2 -5
- package/src/utils/version-utils.ts +9 -9
- package/test/db.test.ts +18 -0
- package/test/generate.test.ts +59 -0
- package/test/init.test.ts +13 -0
- package/test/migrate.test.ts +41 -0
- package/test/ts-schema-gen.test.ts +0 -1
- package/test/utils.ts +23 -0
- package/tsconfig.json +1 -1
- package/.turbo/turbo-lint.log +0 -18
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m
|
|
7
|
-
[34mCLI[39m
|
|
8
|
-
[34mCLI[39m tsup
|
|
9
|
-
[34mCLI[39m
|
|
10
|
-
[34mCLI[39m
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[32mESM[39m [1mdist/index.js
|
|
15
|
-
[32mESM[39m
|
|
16
|
-
[
|
|
17
|
-
[32mCJS[39m [1mdist/index.cjs
|
|
18
|
-
[32mCJS[39m
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
DTS dist/index.d.cts 108.00 B
|
|
1
|
+
|
|
2
|
+
> @zenstackhq/cli@3.0.0-alpha.10 build /home/runner/work/zenstack-v3/zenstack-v3/packages/cli
|
|
3
|
+
> tsup-node
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: {"index":"src/index.ts"}
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.0
|
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/zenstack-v3/zenstack-v3/packages/cli/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Target: esnext
|
|
10
|
+
[34mCLI[39m Cleaning output folder
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[34mCJS[39m Build start
|
|
13
|
+
[32mESM[39m [1mdist/index.js [22m[32m17.39 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m35.93 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 91ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m20.63 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m36.14 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 91ms
|
|
19
|
+
[34mDTS[39m Build start
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 3366ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m108.00 B[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m108.00 B[39m
|
package/bin/cli
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6,9 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
-
};
|
|
12
9
|
var __export = (target, all) => {
|
|
13
10
|
for (var name in all)
|
|
14
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -31,69 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
28
|
));
|
|
32
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
30
|
|
|
34
|
-
// package.json
|
|
35
|
-
var require_package = __commonJS({
|
|
36
|
-
"package.json"(exports2, module2) {
|
|
37
|
-
module2.exports = {
|
|
38
|
-
name: "@zenstackhq/cli",
|
|
39
|
-
publisher: "zenstack",
|
|
40
|
-
displayName: "ZenStack CLI",
|
|
41
|
-
description: "FullStack database toolkit with built-in access control and automatic API generation.",
|
|
42
|
-
version: "3.0.0-alpha.0",
|
|
43
|
-
type: "module",
|
|
44
|
-
author: {
|
|
45
|
-
name: "ZenStack Team"
|
|
46
|
-
},
|
|
47
|
-
homepage: "https://zenstack.dev",
|
|
48
|
-
license: "MIT",
|
|
49
|
-
keywords: [
|
|
50
|
-
"orm",
|
|
51
|
-
"fullstack",
|
|
52
|
-
"react",
|
|
53
|
-
"typescript",
|
|
54
|
-
"data modeling"
|
|
55
|
-
],
|
|
56
|
-
bin: {
|
|
57
|
-
zenstack: "bin/cli"
|
|
58
|
-
},
|
|
59
|
-
scripts: {
|
|
60
|
-
build: "tsup-node",
|
|
61
|
-
watch: "tsup-node --watch",
|
|
62
|
-
lint: "eslint src --ext ts",
|
|
63
|
-
test: "vitest",
|
|
64
|
-
pack: "pnpm pack"
|
|
65
|
-
},
|
|
66
|
-
dependencies: {
|
|
67
|
-
"@types/node": "^20.0.0",
|
|
68
|
-
"@zenstackhq/language": "workspace:*",
|
|
69
|
-
"@zenstackhq/sdk": "workspace:*",
|
|
70
|
-
"async-exit-hook": "^2.0.1",
|
|
71
|
-
colors: "1.4.0",
|
|
72
|
-
commander: "^8.3.0",
|
|
73
|
-
langium: "~3.3.0",
|
|
74
|
-
ora: "^5.4.1",
|
|
75
|
-
"package-manager-detector": "^1.3.0",
|
|
76
|
-
"tiny-invariant": "^1.3.3",
|
|
77
|
-
"ts-pattern": "^4.3.0"
|
|
78
|
-
},
|
|
79
|
-
peerDependencies: {
|
|
80
|
-
prisma: "^6.0.0",
|
|
81
|
-
typescript: "^5.0.0"
|
|
82
|
-
},
|
|
83
|
-
devDependencies: {
|
|
84
|
-
"@types/async-exit-hook": "^2.0.0",
|
|
85
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
86
|
-
"@types/semver": "^7.3.13",
|
|
87
|
-
"@types/tmp": "^0.2.6",
|
|
88
|
-
"@zenstackhq/runtime": "workspace:*",
|
|
89
|
-
"@zenstackhq/testtools": "workspace:*",
|
|
90
|
-
"better-sqlite3": "^11.8.1",
|
|
91
|
-
tmp: "^0.2.3"
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
31
|
// src/index.ts
|
|
98
32
|
var src_exports = {};
|
|
99
33
|
__export(src_exports, {
|
|
@@ -105,7 +39,7 @@ var import_colors5 = __toESM(require("colors"), 1);
|
|
|
105
39
|
var import_commander = require("commander");
|
|
106
40
|
|
|
107
41
|
// src/actions/db.ts
|
|
108
|
-
var
|
|
42
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
109
43
|
|
|
110
44
|
// src/utils/exec-utils.ts
|
|
111
45
|
var import_child_process = require("child_process");
|
|
@@ -130,7 +64,12 @@ function execPackage(cmd, options) {
|
|
|
130
64
|
__name(execPackage, "execPackage");
|
|
131
65
|
|
|
132
66
|
// src/actions/action-utils.ts
|
|
67
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
68
|
+
var import_language = require("@zenstackhq/language");
|
|
69
|
+
var import_sdk = require("@zenstackhq/sdk");
|
|
70
|
+
var import_colors = __toESM(require("colors"), 1);
|
|
133
71
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
72
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
134
73
|
|
|
135
74
|
// src/cli-error.ts
|
|
136
75
|
var CliError = class extends Error {
|
|
@@ -140,8 +79,6 @@ var CliError = class extends Error {
|
|
|
140
79
|
};
|
|
141
80
|
|
|
142
81
|
// src/actions/action-utils.ts
|
|
143
|
-
var import_language = require("@zenstackhq/language");
|
|
144
|
-
var import_colors = __toESM(require("colors"), 1);
|
|
145
82
|
function getSchemaFile(file) {
|
|
146
83
|
if (file) {
|
|
147
84
|
if (!import_node_fs.default.existsSync(file)) {
|
|
@@ -149,6 +86,13 @@ function getSchemaFile(file) {
|
|
|
149
86
|
}
|
|
150
87
|
return file;
|
|
151
88
|
}
|
|
89
|
+
const pkgJsonConfig = getPkgJsonConfig(process.cwd());
|
|
90
|
+
if (pkgJsonConfig.schema) {
|
|
91
|
+
if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
|
|
92
|
+
throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
|
|
93
|
+
}
|
|
94
|
+
return pkgJsonConfig.schema;
|
|
95
|
+
}
|
|
152
96
|
if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
|
|
153
97
|
return "./zenstack/schema.zmodel";
|
|
154
98
|
} else if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
@@ -178,42 +122,130 @@ function handleSubProcessError(err) {
|
|
|
178
122
|
}
|
|
179
123
|
}
|
|
180
124
|
__name(handleSubProcessError, "handleSubProcessError");
|
|
125
|
+
async function generateTempPrismaSchema(zmodelPath) {
|
|
126
|
+
const model = await loadSchemaDocument(zmodelPath);
|
|
127
|
+
const prismaSchema = await new import_sdk.PrismaSchemaGenerator(model).generate();
|
|
128
|
+
const prismaSchemaFile = import_node_path.default.resolve(import_node_path.default.dirname(zmodelPath), "~schema.prisma");
|
|
129
|
+
import_node_fs.default.writeFileSync(prismaSchemaFile, prismaSchema);
|
|
130
|
+
return prismaSchemaFile;
|
|
131
|
+
}
|
|
132
|
+
__name(generateTempPrismaSchema, "generateTempPrismaSchema");
|
|
133
|
+
function getPkgJsonConfig(startPath) {
|
|
134
|
+
const result = {
|
|
135
|
+
schema: void 0,
|
|
136
|
+
output: void 0
|
|
137
|
+
};
|
|
138
|
+
const pkgJsonFile = (0, import_common_helpers.findUp)([
|
|
139
|
+
"package.json"
|
|
140
|
+
], startPath, false);
|
|
141
|
+
if (!pkgJsonFile) {
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
let pkgJson = void 0;
|
|
145
|
+
try {
|
|
146
|
+
pkgJson = JSON.parse(import_node_fs.default.readFileSync(pkgJsonFile, "utf8"));
|
|
147
|
+
} catch {
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
if (pkgJson.zenstack && typeof pkgJson.zenstack === "object") {
|
|
151
|
+
result.schema = pkgJson.zenstack.schema && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema);
|
|
152
|
+
result.output = pkgJson.zenstack.output && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output);
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
__name(getPkgJsonConfig, "getPkgJsonConfig");
|
|
157
|
+
|
|
158
|
+
// src/actions/db.ts
|
|
159
|
+
async function run(command, options) {
|
|
160
|
+
switch (command) {
|
|
161
|
+
case "push":
|
|
162
|
+
await runPush(options);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
__name(run, "run");
|
|
167
|
+
async function runPush(options) {
|
|
168
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
169
|
+
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
170
|
+
try {
|
|
171
|
+
const cmd = [
|
|
172
|
+
"prisma db push",
|
|
173
|
+
` --schema "${prismaSchemaFile}"`,
|
|
174
|
+
options.acceptDataLoss ? " --accept-data-loss" : "",
|
|
175
|
+
options.forceReset ? " --force-reset" : "",
|
|
176
|
+
" --skip-generate"
|
|
177
|
+
].join("");
|
|
178
|
+
try {
|
|
179
|
+
await execPackage(cmd);
|
|
180
|
+
} catch (err) {
|
|
181
|
+
handleSubProcessError(err);
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
if (import_node_fs2.default.existsSync(prismaSchemaFile)) {
|
|
185
|
+
import_node_fs2.default.unlinkSync(prismaSchemaFile);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
__name(runPush, "runPush");
|
|
181
190
|
|
|
182
191
|
// src/actions/generate.ts
|
|
192
|
+
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
183
193
|
var import_ast = require("@zenstackhq/language/ast");
|
|
184
|
-
var
|
|
194
|
+
var import_sdk2 = require("@zenstackhq/sdk");
|
|
185
195
|
var import_colors2 = __toESM(require("colors"), 1);
|
|
186
|
-
var
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
async function run(options) {
|
|
196
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
197
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
198
|
+
async function run2(options) {
|
|
190
199
|
const schemaFile = getSchemaFile(options.schema);
|
|
191
200
|
const model = await loadSchemaDocument(schemaFile);
|
|
192
|
-
const outputPath = options
|
|
193
|
-
const tsSchemaFile =
|
|
194
|
-
await new
|
|
201
|
+
const outputPath = getOutputPath(options, schemaFile);
|
|
202
|
+
const tsSchemaFile = import_node_path2.default.join(outputPath, "schema.ts");
|
|
203
|
+
await new import_sdk2.TsSchemaGenerator().generate(schemaFile, [], tsSchemaFile);
|
|
195
204
|
await runPlugins(model, outputPath, tsSchemaFile);
|
|
196
|
-
|
|
197
|
-
|
|
205
|
+
if (options.savePrismaSchema) {
|
|
206
|
+
const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
|
|
207
|
+
let prismaSchemaFile = import_node_path2.default.join(outputPath, "schema.prisma");
|
|
208
|
+
if (typeof options.savePrismaSchema === "string") {
|
|
209
|
+
prismaSchemaFile = import_node_path2.default.resolve(outputPath, options.savePrismaSchema);
|
|
210
|
+
import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(prismaSchemaFile), {
|
|
211
|
+
recursive: true
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
import_node_fs3.default.writeFileSync(prismaSchemaFile, prismaSchema);
|
|
215
|
+
}
|
|
198
216
|
if (!options.silent) {
|
|
199
217
|
console.log(import_colors2.default.green("Generation completed successfully."));
|
|
200
218
|
console.log(`You can now create a ZenStack client with it.
|
|
201
219
|
|
|
202
|
-
\`\`\`
|
|
220
|
+
\`\`\`ts
|
|
203
221
|
import { ZenStackClient } from '@zenstackhq/runtime';
|
|
204
222
|
import { schema } from '${outputPath}/schema';
|
|
205
223
|
|
|
206
|
-
const client = new ZenStackClient(schema
|
|
224
|
+
const client = new ZenStackClient(schema, {
|
|
225
|
+
dialectConfig: { ... }
|
|
226
|
+
});
|
|
207
227
|
\`\`\`
|
|
208
228
|
`);
|
|
209
229
|
}
|
|
210
230
|
}
|
|
211
|
-
__name(
|
|
231
|
+
__name(run2, "run");
|
|
232
|
+
function getOutputPath(options, schemaFile) {
|
|
233
|
+
if (options.output) {
|
|
234
|
+
return options.output;
|
|
235
|
+
}
|
|
236
|
+
const pkgJsonConfig = getPkgJsonConfig(process.cwd());
|
|
237
|
+
if (pkgJsonConfig.output) {
|
|
238
|
+
return pkgJsonConfig.output;
|
|
239
|
+
} else {
|
|
240
|
+
return import_node_path2.default.dirname(schemaFile);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
__name(getOutputPath, "getOutputPath");
|
|
212
244
|
async function runPlugins(model, outputPath, tsSchemaFile) {
|
|
213
245
|
const plugins = model.declarations.filter(import_ast.isPlugin);
|
|
214
246
|
for (const plugin of plugins) {
|
|
215
247
|
const providerField = plugin.fields.find((f) => f.name === "provider");
|
|
216
|
-
(0,
|
|
248
|
+
(0, import_common_helpers2.invariant)(providerField, `Plugin ${plugin.name} does not have a provider field`);
|
|
217
249
|
const provider = providerField.value.value;
|
|
218
250
|
let useProvider = provider;
|
|
219
251
|
if (useProvider.startsWith("@core/")) {
|
|
@@ -230,33 +262,6 @@ async function runPlugins(model, outputPath, tsSchemaFile) {
|
|
|
230
262
|
}
|
|
231
263
|
__name(runPlugins, "runPlugins");
|
|
232
264
|
|
|
233
|
-
// src/actions/db.ts
|
|
234
|
-
async function run2(command, options) {
|
|
235
|
-
const schemaFile = getSchemaFile(options.schema);
|
|
236
|
-
await run({
|
|
237
|
-
schema: schemaFile,
|
|
238
|
-
silent: true
|
|
239
|
-
});
|
|
240
|
-
const prismaSchemaFile = import_node_path2.default.join(import_node_path2.default.dirname(schemaFile), "schema.prisma");
|
|
241
|
-
switch (command) {
|
|
242
|
-
case "push":
|
|
243
|
-
await runPush(prismaSchemaFile, options);
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
__name(run2, "run");
|
|
248
|
-
async function runPush(prismaSchemaFile, options) {
|
|
249
|
-
const cmd = `prisma db push --schema "${prismaSchemaFile}"${options.acceptDataLoss ? " --accept-data-loss" : ""}${options.forceReset ? " --force-reset" : ""} --skip-generate`;
|
|
250
|
-
try {
|
|
251
|
-
await execPackage(cmd, {
|
|
252
|
-
stdio: "inherit"
|
|
253
|
-
});
|
|
254
|
-
} catch (err) {
|
|
255
|
-
handleSubProcessError(err);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
__name(runPush, "runPush");
|
|
259
|
-
|
|
260
265
|
// src/actions/info.ts
|
|
261
266
|
var import_colors3 = __toESM(require("colors"), 1);
|
|
262
267
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
@@ -288,7 +293,7 @@ async function getZenStackPackages(projectPath) {
|
|
|
288
293
|
type: "json"
|
|
289
294
|
}
|
|
290
295
|
})).default;
|
|
291
|
-
} catch
|
|
296
|
+
} catch {
|
|
292
297
|
return [];
|
|
293
298
|
}
|
|
294
299
|
const packages = Array.from(new Set([
|
|
@@ -319,7 +324,7 @@ __name(getZenStackPackages, "getZenStackPackages");
|
|
|
319
324
|
|
|
320
325
|
// src/actions/init.ts
|
|
321
326
|
var import_colors4 = __toESM(require("colors"), 1);
|
|
322
|
-
var
|
|
327
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
323
328
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
324
329
|
var import_ora = __toESM(require("ora"), 1);
|
|
325
330
|
var import_package_manager_detector = require("package-manager-detector");
|
|
@@ -357,11 +362,11 @@ model Post {
|
|
|
357
362
|
async function run4(projectPath) {
|
|
358
363
|
const packages = [
|
|
359
364
|
{
|
|
360
|
-
name: "@zenstackhq/cli",
|
|
365
|
+
name: "@zenstackhq/cli@next",
|
|
361
366
|
dev: true
|
|
362
367
|
},
|
|
363
368
|
{
|
|
364
|
-
name: "@zenstackhq/runtime",
|
|
369
|
+
name: "@zenstackhq/runtime@next",
|
|
365
370
|
dev: false
|
|
366
371
|
}
|
|
367
372
|
];
|
|
@@ -395,11 +400,11 @@ async function run4(projectPath) {
|
|
|
395
400
|
}
|
|
396
401
|
}
|
|
397
402
|
const generationFolder = "zenstack";
|
|
398
|
-
if (!
|
|
399
|
-
|
|
403
|
+
if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder))) {
|
|
404
|
+
import_node_fs4.default.mkdirSync(import_node_path4.default.join(projectPath, generationFolder));
|
|
400
405
|
}
|
|
401
|
-
if (!
|
|
402
|
-
|
|
406
|
+
if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
407
|
+
import_node_fs4.default.writeFileSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
403
408
|
} else {
|
|
404
409
|
console.log(import_colors4.default.yellow("Schema file already exists. Skipping generation of sample."));
|
|
405
410
|
}
|
|
@@ -410,35 +415,42 @@ async function run4(projectPath) {
|
|
|
410
415
|
__name(run4, "run");
|
|
411
416
|
|
|
412
417
|
// src/actions/migrate.ts
|
|
413
|
-
var
|
|
418
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
414
419
|
async function run5(command, options) {
|
|
415
420
|
const schemaFile = getSchemaFile(options.schema);
|
|
416
|
-
await
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
421
|
+
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
422
|
+
try {
|
|
423
|
+
switch (command) {
|
|
424
|
+
case "dev":
|
|
425
|
+
await runDev(prismaSchemaFile, options);
|
|
426
|
+
break;
|
|
427
|
+
case "reset":
|
|
428
|
+
await runReset(prismaSchemaFile, options);
|
|
429
|
+
break;
|
|
430
|
+
case "deploy":
|
|
431
|
+
await runDeploy(prismaSchemaFile, options);
|
|
432
|
+
break;
|
|
433
|
+
case "status":
|
|
434
|
+
await runStatus(prismaSchemaFile, options);
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
} finally {
|
|
438
|
+
if (import_node_fs5.default.existsSync(prismaSchemaFile)) {
|
|
439
|
+
import_node_fs5.default.unlinkSync(prismaSchemaFile);
|
|
440
|
+
}
|
|
434
441
|
}
|
|
435
442
|
}
|
|
436
443
|
__name(run5, "run");
|
|
437
|
-
async function runDev(prismaSchemaFile,
|
|
444
|
+
async function runDev(prismaSchemaFile, options) {
|
|
438
445
|
try {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
446
|
+
const cmd = [
|
|
447
|
+
"prisma migrate dev",
|
|
448
|
+
` --schema "${prismaSchemaFile}"`,
|
|
449
|
+
" --skip-generate",
|
|
450
|
+
options.name ? ` --name ${options.name}` : "",
|
|
451
|
+
options.createOnly ? " --create-only" : ""
|
|
452
|
+
].join("");
|
|
453
|
+
await execPackage(cmd);
|
|
442
454
|
} catch (err) {
|
|
443
455
|
handleSubProcessError2(err);
|
|
444
456
|
}
|
|
@@ -446,9 +458,12 @@ async function runDev(prismaSchemaFile, _options) {
|
|
|
446
458
|
__name(runDev, "runDev");
|
|
447
459
|
async function runReset(prismaSchemaFile, options) {
|
|
448
460
|
try {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
461
|
+
const cmd = [
|
|
462
|
+
"prisma migrate reset",
|
|
463
|
+
` --schema "${prismaSchemaFile}"`,
|
|
464
|
+
options.force ? " --force" : ""
|
|
465
|
+
].join("");
|
|
466
|
+
await execPackage(cmd);
|
|
452
467
|
} catch (err) {
|
|
453
468
|
handleSubProcessError2(err);
|
|
454
469
|
}
|
|
@@ -456,9 +471,11 @@ async function runReset(prismaSchemaFile, options) {
|
|
|
456
471
|
__name(runReset, "runReset");
|
|
457
472
|
async function runDeploy(prismaSchemaFile, _options) {
|
|
458
473
|
try {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
474
|
+
const cmd = [
|
|
475
|
+
"prisma migrate deploy",
|
|
476
|
+
` --schema "${prismaSchemaFile}"`
|
|
477
|
+
].join("");
|
|
478
|
+
await execPackage(cmd);
|
|
462
479
|
} catch (err) {
|
|
463
480
|
handleSubProcessError2(err);
|
|
464
481
|
}
|
|
@@ -466,9 +483,7 @@ async function runDeploy(prismaSchemaFile, _options) {
|
|
|
466
483
|
__name(runDeploy, "runDeploy");
|
|
467
484
|
async function runStatus(prismaSchemaFile, _options) {
|
|
468
485
|
try {
|
|
469
|
-
await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"
|
|
470
|
-
stdio: "inherit"
|
|
471
|
-
});
|
|
486
|
+
await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`);
|
|
472
487
|
} catch (err) {
|
|
473
488
|
handleSubProcessError2(err);
|
|
474
489
|
}
|
|
@@ -484,28 +499,29 @@ function handleSubProcessError2(err) {
|
|
|
484
499
|
__name(handleSubProcessError2, "handleSubProcessError");
|
|
485
500
|
|
|
486
501
|
// src/utils/version-utils.ts
|
|
502
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
503
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
504
|
+
var import_node_url = require("url");
|
|
505
|
+
var import_meta = {};
|
|
487
506
|
function getVersion() {
|
|
488
507
|
try {
|
|
489
|
-
|
|
508
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path5.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
509
|
+
return JSON.parse(import_node_fs6.default.readFileSync(import_node_path5.default.join(_dirname, "../package.json"), "utf8")).version;
|
|
490
510
|
} catch {
|
|
491
|
-
|
|
492
|
-
return require_package().version;
|
|
493
|
-
} catch {
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
511
|
+
return void 0;
|
|
496
512
|
}
|
|
497
513
|
}
|
|
498
514
|
__name(getVersion, "getVersion");
|
|
499
515
|
|
|
500
516
|
// src/index.ts
|
|
501
517
|
var generateAction = /* @__PURE__ */ __name(async (options) => {
|
|
502
|
-
await
|
|
518
|
+
await run2(options);
|
|
503
519
|
}, "generateAction");
|
|
504
520
|
var migrateAction = /* @__PURE__ */ __name(async (command, options) => {
|
|
505
521
|
await run5(command, options);
|
|
506
522
|
}, "migrateAction");
|
|
507
523
|
var dbAction = /* @__PURE__ */ __name(async (command, options) => {
|
|
508
|
-
await
|
|
524
|
+
await run(command, options);
|
|
509
525
|
}, "dbAction");
|
|
510
526
|
var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
511
527
|
await run3(projectPath);
|
|
@@ -521,7 +537,7 @@ function createProgram() {
|
|
|
521
537
|
|
|
522
538
|
Documentation: https://zenstack.dev.`).showHelpAfterError().showSuggestionAfterError();
|
|
523
539
|
const schemaOption = new import_commander.Option("--schema <file>", `schema file (with extension ${schemaExtensions}). Defaults to "schema.zmodel" unless specified in package.json.`);
|
|
524
|
-
program2.command("generate").description("Run code generation.").addOption(schemaOption).addOption(new import_commander.Option("-o, --output <path>", "default output directory for core plugins")).action(generateAction);
|
|
540
|
+
program2.command("generate").description("Run code generation.").addOption(schemaOption).addOption(new import_commander.Option("--silent", "do not print any output")).addOption(new import_commander.Option("--save-prisma-schema [path]", "save a Prisma schema file, by default into the output directory")).addOption(new import_commander.Option("-o, --output <path>", "default output directory for core plugins")).action(generateAction);
|
|
525
541
|
const migrateCommand = program2.command("migrate").description("Update the database schema with migrations.");
|
|
526
542
|
migrateCommand.command("dev").addOption(schemaOption).addOption(new import_commander.Option("-n, --name <name>", "migration name")).addOption(new import_commander.Option("--create-only", "only create migration, do not apply")).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
|
|
527
543
|
migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
|