@zenstackhq/cli 3.0.0-alpha.1 → 3.0.0-alpha.11
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 +200 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +202 -171
- package/dist/index.js.map +1 -1
- package/eslint.config.js +4 -0
- package/package.json +13 -15
- package/src/actions/action-utils.ts +73 -8
- package/src/actions/db.ts +30 -29
- package/src/actions/generate.ts +33 -19
- package/src/actions/info.ts +9 -18
- package/src/actions/init.ts +7 -28
- package/src/actions/migrate.ts +61 -63
- package/src/actions/templates.ts +6 -1
- package/src/index.ts +23 -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
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[32mESM[39m
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
DTS dist/index.d.cts 108.00 B
|
|
1
|
+
|
|
2
|
+
> @zenstackhq/cli@3.0.0-alpha.11 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
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m21.61 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m38.40 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 127ms
|
|
16
|
+
[32mESM[39m [1mdist/index.js [22m[32m18.25 KB[39m
|
|
17
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m38.16 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 127ms
|
|
19
|
+
[34mDTS[39m Build start
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 3734ms
|
|
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.1",
|
|
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,11 @@ function execPackage(cmd, options) {
|
|
|
130
64
|
__name(execPackage, "execPackage");
|
|
131
65
|
|
|
132
66
|
// src/actions/action-utils.ts
|
|
67
|
+
var import_language = require("@zenstackhq/language");
|
|
68
|
+
var import_sdk = require("@zenstackhq/sdk");
|
|
69
|
+
var import_colors = __toESM(require("colors"), 1);
|
|
133
70
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
71
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
134
72
|
|
|
135
73
|
// src/cli-error.ts
|
|
136
74
|
var CliError = class extends Error {
|
|
@@ -140,8 +78,6 @@ var CliError = class extends Error {
|
|
|
140
78
|
};
|
|
141
79
|
|
|
142
80
|
// src/actions/action-utils.ts
|
|
143
|
-
var import_language = require("@zenstackhq/language");
|
|
144
|
-
var import_colors = __toESM(require("colors"), 1);
|
|
145
81
|
function getSchemaFile(file) {
|
|
146
82
|
if (file) {
|
|
147
83
|
if (!import_node_fs.default.existsSync(file)) {
|
|
@@ -149,6 +85,13 @@ function getSchemaFile(file) {
|
|
|
149
85
|
}
|
|
150
86
|
return file;
|
|
151
87
|
}
|
|
88
|
+
const pkgJsonConfig = getPkgJsonConfig(process.cwd());
|
|
89
|
+
if (pkgJsonConfig.schema) {
|
|
90
|
+
if (!import_node_fs.default.existsSync(pkgJsonConfig.schema)) {
|
|
91
|
+
throw new CliError(`Schema file not found: ${pkgJsonConfig.schema}`);
|
|
92
|
+
}
|
|
93
|
+
return pkgJsonConfig.schema;
|
|
94
|
+
}
|
|
152
95
|
if (import_node_fs.default.existsSync("./zenstack/schema.zmodel")) {
|
|
153
96
|
return "./zenstack/schema.zmodel";
|
|
154
97
|
} else if (import_node_fs.default.existsSync("./schema.zmodel")) {
|
|
@@ -178,42 +121,151 @@ function handleSubProcessError(err) {
|
|
|
178
121
|
}
|
|
179
122
|
}
|
|
180
123
|
__name(handleSubProcessError, "handleSubProcessError");
|
|
124
|
+
async function generateTempPrismaSchema(zmodelPath, folder) {
|
|
125
|
+
const model = await loadSchemaDocument(zmodelPath);
|
|
126
|
+
const prismaSchema = await new import_sdk.PrismaSchemaGenerator(model).generate();
|
|
127
|
+
if (!folder) {
|
|
128
|
+
folder = import_node_path.default.dirname(zmodelPath);
|
|
129
|
+
}
|
|
130
|
+
const prismaSchemaFile = import_node_path.default.resolve(folder, "~schema.prisma");
|
|
131
|
+
import_node_fs.default.writeFileSync(prismaSchemaFile, prismaSchema);
|
|
132
|
+
return prismaSchemaFile;
|
|
133
|
+
}
|
|
134
|
+
__name(generateTempPrismaSchema, "generateTempPrismaSchema");
|
|
135
|
+
function getPkgJsonConfig(startPath) {
|
|
136
|
+
const result = {
|
|
137
|
+
schema: void 0,
|
|
138
|
+
output: void 0
|
|
139
|
+
};
|
|
140
|
+
const pkgJsonFile = findUp([
|
|
141
|
+
"package.json"
|
|
142
|
+
], startPath, false);
|
|
143
|
+
if (!pkgJsonFile) {
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
let pkgJson = void 0;
|
|
147
|
+
try {
|
|
148
|
+
pkgJson = JSON.parse(import_node_fs.default.readFileSync(pkgJsonFile, "utf8"));
|
|
149
|
+
} catch {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
if (pkgJson.zenstack && typeof pkgJson.zenstack === "object") {
|
|
153
|
+
result.schema = pkgJson.zenstack.schema && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.schema);
|
|
154
|
+
result.output = pkgJson.zenstack.output && import_node_path.default.resolve(import_node_path.default.dirname(pkgJsonFile), pkgJson.zenstack.output);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
__name(getPkgJsonConfig, "getPkgJsonConfig");
|
|
159
|
+
function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
160
|
+
if (!names.some((name) => !!name)) {
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
|
|
164
|
+
if (multiple === false && target) {
|
|
165
|
+
return import_node_path.default.join(cwd, target);
|
|
166
|
+
}
|
|
167
|
+
if (target) {
|
|
168
|
+
result.push(import_node_path.default.join(cwd, target));
|
|
169
|
+
}
|
|
170
|
+
const up = import_node_path.default.resolve(cwd, "..");
|
|
171
|
+
if (up === cwd) {
|
|
172
|
+
return multiple && result.length > 0 ? result : void 0;
|
|
173
|
+
}
|
|
174
|
+
return findUp(names, up, multiple, result);
|
|
175
|
+
}
|
|
176
|
+
__name(findUp, "findUp");
|
|
177
|
+
|
|
178
|
+
// src/actions/db.ts
|
|
179
|
+
async function run(command, options) {
|
|
180
|
+
switch (command) {
|
|
181
|
+
case "push":
|
|
182
|
+
await runPush(options);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
__name(run, "run");
|
|
187
|
+
async function runPush(options) {
|
|
188
|
+
const schemaFile = getSchemaFile(options.schema);
|
|
189
|
+
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile);
|
|
190
|
+
try {
|
|
191
|
+
const cmd = [
|
|
192
|
+
"prisma db push",
|
|
193
|
+
` --schema "${prismaSchemaFile}"`,
|
|
194
|
+
options.acceptDataLoss ? " --accept-data-loss" : "",
|
|
195
|
+
options.forceReset ? " --force-reset" : "",
|
|
196
|
+
" --skip-generate"
|
|
197
|
+
].join("");
|
|
198
|
+
try {
|
|
199
|
+
await execPackage(cmd);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
handleSubProcessError(err);
|
|
202
|
+
}
|
|
203
|
+
} finally {
|
|
204
|
+
if (import_node_fs2.default.existsSync(prismaSchemaFile)) {
|
|
205
|
+
import_node_fs2.default.unlinkSync(prismaSchemaFile);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
__name(runPush, "runPush");
|
|
181
210
|
|
|
182
211
|
// src/actions/generate.ts
|
|
212
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
183
213
|
var import_ast = require("@zenstackhq/language/ast");
|
|
184
|
-
var
|
|
214
|
+
var import_sdk2 = require("@zenstackhq/sdk");
|
|
185
215
|
var import_colors2 = __toESM(require("colors"), 1);
|
|
186
|
-
var
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
async function run(options) {
|
|
216
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
217
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
218
|
+
async function run2(options) {
|
|
190
219
|
const schemaFile = getSchemaFile(options.schema);
|
|
191
220
|
const model = await loadSchemaDocument(schemaFile);
|
|
192
|
-
const outputPath = options
|
|
193
|
-
const tsSchemaFile =
|
|
194
|
-
await new
|
|
221
|
+
const outputPath = getOutputPath(options, schemaFile);
|
|
222
|
+
const tsSchemaFile = import_node_path2.default.join(outputPath, "schema.ts");
|
|
223
|
+
await new import_sdk2.TsSchemaGenerator().generate(schemaFile, [], outputPath);
|
|
195
224
|
await runPlugins(model, outputPath, tsSchemaFile);
|
|
196
|
-
|
|
197
|
-
|
|
225
|
+
if (options.savePrismaSchema) {
|
|
226
|
+
const prismaSchema = await new import_sdk2.PrismaSchemaGenerator(model).generate();
|
|
227
|
+
let prismaSchemaFile = import_node_path2.default.join(outputPath, "schema.prisma");
|
|
228
|
+
if (typeof options.savePrismaSchema === "string") {
|
|
229
|
+
prismaSchemaFile = import_node_path2.default.resolve(outputPath, options.savePrismaSchema);
|
|
230
|
+
import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(prismaSchemaFile), {
|
|
231
|
+
recursive: true
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
import_node_fs3.default.writeFileSync(prismaSchemaFile, prismaSchema);
|
|
235
|
+
}
|
|
198
236
|
if (!options.silent) {
|
|
199
237
|
console.log(import_colors2.default.green("Generation completed successfully."));
|
|
200
238
|
console.log(`You can now create a ZenStack client with it.
|
|
201
239
|
|
|
202
|
-
\`\`\`
|
|
240
|
+
\`\`\`ts
|
|
203
241
|
import { ZenStackClient } from '@zenstackhq/runtime';
|
|
204
242
|
import { schema } from '${outputPath}/schema';
|
|
205
243
|
|
|
206
|
-
const client = new ZenStackClient(schema
|
|
244
|
+
const client = new ZenStackClient(schema, {
|
|
245
|
+
dialectConfig: { ... }
|
|
246
|
+
});
|
|
207
247
|
\`\`\`
|
|
208
248
|
`);
|
|
209
249
|
}
|
|
210
250
|
}
|
|
211
|
-
__name(
|
|
251
|
+
__name(run2, "run");
|
|
252
|
+
function getOutputPath(options, schemaFile) {
|
|
253
|
+
if (options.output) {
|
|
254
|
+
return options.output;
|
|
255
|
+
}
|
|
256
|
+
const pkgJsonConfig = getPkgJsonConfig(process.cwd());
|
|
257
|
+
if (pkgJsonConfig.output) {
|
|
258
|
+
return pkgJsonConfig.output;
|
|
259
|
+
} else {
|
|
260
|
+
return import_node_path2.default.dirname(schemaFile);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
__name(getOutputPath, "getOutputPath");
|
|
212
264
|
async function runPlugins(model, outputPath, tsSchemaFile) {
|
|
213
265
|
const plugins = model.declarations.filter(import_ast.isPlugin);
|
|
214
266
|
for (const plugin of plugins) {
|
|
215
267
|
const providerField = plugin.fields.find((f) => f.name === "provider");
|
|
216
|
-
(0,
|
|
268
|
+
(0, import_common_helpers.invariant)(providerField, `Plugin ${plugin.name} does not have a provider field`);
|
|
217
269
|
const provider = providerField.value.value;
|
|
218
270
|
let useProvider = provider;
|
|
219
271
|
if (useProvider.startsWith("@core/")) {
|
|
@@ -230,33 +282,6 @@ async function runPlugins(model, outputPath, tsSchemaFile) {
|
|
|
230
282
|
}
|
|
231
283
|
__name(runPlugins, "runPlugins");
|
|
232
284
|
|
|
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
285
|
// src/actions/info.ts
|
|
261
286
|
var import_colors3 = __toESM(require("colors"), 1);
|
|
262
287
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
@@ -288,7 +313,7 @@ async function getZenStackPackages(projectPath) {
|
|
|
288
313
|
type: "json"
|
|
289
314
|
}
|
|
290
315
|
})).default;
|
|
291
|
-
} catch
|
|
316
|
+
} catch {
|
|
292
317
|
return [];
|
|
293
318
|
}
|
|
294
319
|
const packages = Array.from(new Set([
|
|
@@ -319,7 +344,7 @@ __name(getZenStackPackages, "getZenStackPackages");
|
|
|
319
344
|
|
|
320
345
|
// src/actions/init.ts
|
|
321
346
|
var import_colors4 = __toESM(require("colors"), 1);
|
|
322
|
-
var
|
|
347
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
323
348
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
324
349
|
var import_ora = __toESM(require("ora"), 1);
|
|
325
350
|
var import_package_manager_detector = require("package-manager-detector");
|
|
@@ -357,7 +382,7 @@ model Post {
|
|
|
357
382
|
async function run4(projectPath) {
|
|
358
383
|
const packages = [
|
|
359
384
|
{
|
|
360
|
-
name: "@zenstackhq
|
|
385
|
+
name: "@zenstackhq/cli@next",
|
|
361
386
|
dev: true
|
|
362
387
|
},
|
|
363
388
|
{
|
|
@@ -395,11 +420,11 @@ async function run4(projectPath) {
|
|
|
395
420
|
}
|
|
396
421
|
}
|
|
397
422
|
const generationFolder = "zenstack";
|
|
398
|
-
if (!
|
|
399
|
-
|
|
423
|
+
if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder))) {
|
|
424
|
+
import_node_fs4.default.mkdirSync(import_node_path4.default.join(projectPath, generationFolder));
|
|
400
425
|
}
|
|
401
|
-
if (!
|
|
402
|
-
|
|
426
|
+
if (!import_node_fs4.default.existsSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
427
|
+
import_node_fs4.default.writeFileSync(import_node_path4.default.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
403
428
|
} else {
|
|
404
429
|
console.log(import_colors4.default.yellow("Schema file already exists. Skipping generation of sample."));
|
|
405
430
|
}
|
|
@@ -410,35 +435,44 @@ async function run4(projectPath) {
|
|
|
410
435
|
__name(run4, "run");
|
|
411
436
|
|
|
412
437
|
// src/actions/migrate.ts
|
|
438
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
413
439
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
414
440
|
async function run5(command, options) {
|
|
415
441
|
const schemaFile = getSchemaFile(options.schema);
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
442
|
+
const prismaSchemaDir = options.migrations ? import_node_path5.default.dirname(options.migrations) : void 0;
|
|
443
|
+
const prismaSchemaFile = await generateTempPrismaSchema(schemaFile, prismaSchemaDir);
|
|
444
|
+
try {
|
|
445
|
+
switch (command) {
|
|
446
|
+
case "dev":
|
|
447
|
+
await runDev(prismaSchemaFile, options);
|
|
448
|
+
break;
|
|
449
|
+
case "reset":
|
|
450
|
+
await runReset(prismaSchemaFile, options);
|
|
451
|
+
break;
|
|
452
|
+
case "deploy":
|
|
453
|
+
await runDeploy(prismaSchemaFile, options);
|
|
454
|
+
break;
|
|
455
|
+
case "status":
|
|
456
|
+
await runStatus(prismaSchemaFile, options);
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
} finally {
|
|
460
|
+
if (import_node_fs5.default.existsSync(prismaSchemaFile)) {
|
|
461
|
+
import_node_fs5.default.unlinkSync(prismaSchemaFile);
|
|
462
|
+
}
|
|
434
463
|
}
|
|
435
464
|
}
|
|
436
465
|
__name(run5, "run");
|
|
437
|
-
async function runDev(prismaSchemaFile,
|
|
466
|
+
async function runDev(prismaSchemaFile, options) {
|
|
438
467
|
try {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
468
|
+
const cmd = [
|
|
469
|
+
"prisma migrate dev",
|
|
470
|
+
` --schema "${prismaSchemaFile}"`,
|
|
471
|
+
" --skip-generate",
|
|
472
|
+
options.name ? ` --name ${options.name}` : "",
|
|
473
|
+
options.createOnly ? " --create-only" : ""
|
|
474
|
+
].join("");
|
|
475
|
+
await execPackage(cmd);
|
|
442
476
|
} catch (err) {
|
|
443
477
|
handleSubProcessError2(err);
|
|
444
478
|
}
|
|
@@ -446,9 +480,12 @@ async function runDev(prismaSchemaFile, _options) {
|
|
|
446
480
|
__name(runDev, "runDev");
|
|
447
481
|
async function runReset(prismaSchemaFile, options) {
|
|
448
482
|
try {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
483
|
+
const cmd = [
|
|
484
|
+
"prisma migrate reset",
|
|
485
|
+
` --schema "${prismaSchemaFile}"`,
|
|
486
|
+
options.force ? " --force" : ""
|
|
487
|
+
].join("");
|
|
488
|
+
await execPackage(cmd);
|
|
452
489
|
} catch (err) {
|
|
453
490
|
handleSubProcessError2(err);
|
|
454
491
|
}
|
|
@@ -456,9 +493,11 @@ async function runReset(prismaSchemaFile, options) {
|
|
|
456
493
|
__name(runReset, "runReset");
|
|
457
494
|
async function runDeploy(prismaSchemaFile, _options) {
|
|
458
495
|
try {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
496
|
+
const cmd = [
|
|
497
|
+
"prisma migrate deploy",
|
|
498
|
+
` --schema "${prismaSchemaFile}"`
|
|
499
|
+
].join("");
|
|
500
|
+
await execPackage(cmd);
|
|
462
501
|
} catch (err) {
|
|
463
502
|
handleSubProcessError2(err);
|
|
464
503
|
}
|
|
@@ -466,9 +505,7 @@ async function runDeploy(prismaSchemaFile, _options) {
|
|
|
466
505
|
__name(runDeploy, "runDeploy");
|
|
467
506
|
async function runStatus(prismaSchemaFile, _options) {
|
|
468
507
|
try {
|
|
469
|
-
await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"
|
|
470
|
-
stdio: "inherit"
|
|
471
|
-
});
|
|
508
|
+
await execPackage(`prisma migrate status --schema "${prismaSchemaFile}"`);
|
|
472
509
|
} catch (err) {
|
|
473
510
|
handleSubProcessError2(err);
|
|
474
511
|
}
|
|
@@ -484,28 +521,29 @@ function handleSubProcessError2(err) {
|
|
|
484
521
|
__name(handleSubProcessError2, "handleSubProcessError");
|
|
485
522
|
|
|
486
523
|
// src/utils/version-utils.ts
|
|
524
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
525
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
526
|
+
var import_node_url = require("url");
|
|
527
|
+
var import_meta = {};
|
|
487
528
|
function getVersion() {
|
|
488
529
|
try {
|
|
489
|
-
|
|
530
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path6.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
531
|
+
return JSON.parse(import_node_fs6.default.readFileSync(import_node_path6.default.join(_dirname, "../package.json"), "utf8")).version;
|
|
490
532
|
} catch {
|
|
491
|
-
|
|
492
|
-
return require_package().version;
|
|
493
|
-
} catch {
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
533
|
+
return void 0;
|
|
496
534
|
}
|
|
497
535
|
}
|
|
498
536
|
__name(getVersion, "getVersion");
|
|
499
537
|
|
|
500
538
|
// src/index.ts
|
|
501
539
|
var generateAction = /* @__PURE__ */ __name(async (options) => {
|
|
502
|
-
await
|
|
540
|
+
await run2(options);
|
|
503
541
|
}, "generateAction");
|
|
504
542
|
var migrateAction = /* @__PURE__ */ __name(async (command, options) => {
|
|
505
543
|
await run5(command, options);
|
|
506
544
|
}, "migrateAction");
|
|
507
545
|
var dbAction = /* @__PURE__ */ __name(async (command, options) => {
|
|
508
|
-
await
|
|
546
|
+
await run(command, options);
|
|
509
547
|
}, "dbAction");
|
|
510
548
|
var infoAction = /* @__PURE__ */ __name(async (projectPath) => {
|
|
511
549
|
await run3(projectPath);
|
|
@@ -521,12 +559,13 @@ function createProgram() {
|
|
|
521
559
|
|
|
522
560
|
Documentation: https://zenstack.dev.`).showHelpAfterError().showSuggestionAfterError();
|
|
523
561
|
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);
|
|
562
|
+
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
563
|
const migrateCommand = program2.command("migrate").description("Update the database schema with migrations.");
|
|
526
|
-
|
|
527
|
-
migrateCommand.command("
|
|
528
|
-
migrateCommand.command("
|
|
529
|
-
migrateCommand.command("
|
|
564
|
+
const migrationsOption = new import_commander.Option("--migrations <path>", "path for migrations");
|
|
565
|
+
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")).addOption(migrationsOption).description("Create a migration from changes in schema and apply it to the database.").action((options) => migrateAction("dev", options));
|
|
566
|
+
migrateCommand.command("reset").addOption(schemaOption).addOption(new import_commander.Option("--force", "skip the confirmation prompt")).addOption(migrationsOption).description("Reset your database and apply all migrations, all data will be lost.").action((options) => migrateAction("reset", options));
|
|
567
|
+
migrateCommand.command("deploy").addOption(schemaOption).addOption(migrationsOption).description("Deploy your pending migrations to your production/staging database.").action((options) => migrateAction("deploy", options));
|
|
568
|
+
migrateCommand.command("status").addOption(schemaOption).addOption(migrationsOption).description("check the status of your database migrations.").action((options) => migrateAction("status", options));
|
|
530
569
|
const dbCommand = program2.command("db").description("Manage your database schema during development.");
|
|
531
570
|
dbCommand.command("push").description("Push the state from your schema to your database").addOption(schemaOption).addOption(new import_commander.Option("--accept-data-loss", "ignore data loss warnings")).addOption(new import_commander.Option("--force-reset", "force a reset of the database before push")).action((options) => dbAction("push", options));
|
|
532
571
|
program2.command("info").description("Get information of installed ZenStack and related packages.").argument("[path]", "project path", ".").action(infoAction);
|