@zenstackhq/cli 3.0.0-beta.33 → 3.0.0-beta.34
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 +85 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -28
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/src/actions/generate.ts +72 -11
package/dist/index.js
CHANGED
|
@@ -275,7 +275,10 @@ import { invariant } from "@zenstackhq/common-helpers";
|
|
|
275
275
|
import { isPlugin } from "@zenstackhq/language/ast";
|
|
276
276
|
import { getLiteral, getLiteralArray } from "@zenstackhq/language/utils";
|
|
277
277
|
import colors4 from "colors";
|
|
278
|
+
import { createJiti } from "jiti";
|
|
279
|
+
import fs6 from "fs";
|
|
278
280
|
import path4 from "path";
|
|
281
|
+
import { pathToFileURL } from "url";
|
|
279
282
|
import ora from "ora";
|
|
280
283
|
|
|
281
284
|
// src/plugins/index.ts
|
|
@@ -390,14 +393,7 @@ async function runPlugins(schemaFile, model, outputPath, options) {
|
|
|
390
393
|
throw new CliError(`Unknown core plugin: ${provider}`);
|
|
391
394
|
}
|
|
392
395
|
} else {
|
|
393
|
-
|
|
394
|
-
if (moduleSpec.startsWith(".")) {
|
|
395
|
-
moduleSpec = path4.resolve(path4.dirname(schemaFile), moduleSpec);
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
cliPlugin = (await import(moduleSpec)).default;
|
|
399
|
-
} catch {
|
|
400
|
-
}
|
|
396
|
+
cliPlugin = await loadPluginModule(provider, path4.dirname(schemaFile));
|
|
401
397
|
}
|
|
402
398
|
if (cliPlugin) {
|
|
403
399
|
const pluginOptions = getPluginOptions(plugin3);
|
|
@@ -426,7 +422,7 @@ async function runPlugins(schemaFile, model, outputPath, options) {
|
|
|
426
422
|
];
|
|
427
423
|
defaultPlugins.forEach(({ plugin: plugin3, options: options2 }) => {
|
|
428
424
|
if (!processedPlugins.some((p) => p.cliPlugin === plugin3)) {
|
|
429
|
-
processedPlugins.
|
|
425
|
+
processedPlugins.unshift({
|
|
430
426
|
cliPlugin: plugin3,
|
|
431
427
|
pluginOptions: options2
|
|
432
428
|
});
|
|
@@ -476,6 +472,65 @@ function getPluginOptions(plugin3) {
|
|
|
476
472
|
return result;
|
|
477
473
|
}
|
|
478
474
|
__name(getPluginOptions, "getPluginOptions");
|
|
475
|
+
async function loadPluginModule(provider, basePath) {
|
|
476
|
+
let moduleSpec = provider;
|
|
477
|
+
if (moduleSpec.startsWith(".")) {
|
|
478
|
+
moduleSpec = path4.resolve(basePath, moduleSpec);
|
|
479
|
+
}
|
|
480
|
+
const importAsEsm = /* @__PURE__ */ __name(async (spec) => {
|
|
481
|
+
try {
|
|
482
|
+
const result = (await import(spec)).default;
|
|
483
|
+
return result;
|
|
484
|
+
} catch (err) {
|
|
485
|
+
throw new CliError(`Failed to load plugin module from ${spec}: ${err.message}`);
|
|
486
|
+
}
|
|
487
|
+
}, "importAsEsm");
|
|
488
|
+
const jiti = createJiti(pathToFileURL(basePath).toString());
|
|
489
|
+
const importAsTs = /* @__PURE__ */ __name(async (spec) => {
|
|
490
|
+
try {
|
|
491
|
+
const result = await jiti.import(spec, {
|
|
492
|
+
default: true
|
|
493
|
+
});
|
|
494
|
+
return result;
|
|
495
|
+
} catch (err) {
|
|
496
|
+
throw new CliError(`Failed to load plugin module from ${spec}: ${err.message}`);
|
|
497
|
+
}
|
|
498
|
+
}, "importAsTs");
|
|
499
|
+
const esmSuffixes = [
|
|
500
|
+
".js",
|
|
501
|
+
".mjs"
|
|
502
|
+
];
|
|
503
|
+
const tsSuffixes = [
|
|
504
|
+
".ts",
|
|
505
|
+
".mts"
|
|
506
|
+
];
|
|
507
|
+
if (fs6.existsSync(moduleSpec) && fs6.statSync(moduleSpec).isFile()) {
|
|
508
|
+
if (esmSuffixes.some((suffix) => moduleSpec.endsWith(suffix))) {
|
|
509
|
+
return await importAsEsm(pathToFileURL(moduleSpec).toString());
|
|
510
|
+
}
|
|
511
|
+
if (tsSuffixes.some((suffix) => moduleSpec.endsWith(suffix))) {
|
|
512
|
+
return await importAsTs(moduleSpec);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
for (const suffix of esmSuffixes) {
|
|
516
|
+
const indexPath = path4.join(moduleSpec, `index${suffix}`);
|
|
517
|
+
if (fs6.existsSync(indexPath)) {
|
|
518
|
+
return await importAsEsm(pathToFileURL(indexPath).toString());
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
for (const suffix of tsSuffixes) {
|
|
522
|
+
const indexPath = path4.join(moduleSpec, `index${suffix}`);
|
|
523
|
+
if (fs6.existsSync(indexPath)) {
|
|
524
|
+
return await importAsTs(indexPath);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
return (await import(moduleSpec)).default;
|
|
529
|
+
} catch {
|
|
530
|
+
return void 0;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
__name(loadPluginModule, "loadPluginModule");
|
|
479
534
|
|
|
480
535
|
// src/actions/info.ts
|
|
481
536
|
import colors5 from "colors";
|
|
@@ -542,7 +597,7 @@ __name(getZenStackPackages, "getZenStackPackages");
|
|
|
542
597
|
|
|
543
598
|
// src/actions/init.ts
|
|
544
599
|
import colors6 from "colors";
|
|
545
|
-
import
|
|
600
|
+
import fs7 from "fs";
|
|
546
601
|
import path6 from "path";
|
|
547
602
|
import ora2 from "ora";
|
|
548
603
|
import { detect, resolveCommand } from "package-manager-detector";
|
|
@@ -618,11 +673,11 @@ async function run6(projectPath) {
|
|
|
618
673
|
}
|
|
619
674
|
}
|
|
620
675
|
const generationFolder = "zenstack";
|
|
621
|
-
if (!
|
|
622
|
-
|
|
676
|
+
if (!fs7.existsSync(path6.join(projectPath, generationFolder))) {
|
|
677
|
+
fs7.mkdirSync(path6.join(projectPath, generationFolder));
|
|
623
678
|
}
|
|
624
|
-
if (!
|
|
625
|
-
|
|
679
|
+
if (!fs7.existsSync(path6.join(projectPath, generationFolder, "schema.zmodel"))) {
|
|
680
|
+
fs7.writeFileSync(path6.join(projectPath, generationFolder, "schema.zmodel"), STARTER_ZMODEL);
|
|
626
681
|
} else {
|
|
627
682
|
console.log(colors6.yellow("Schema file already exists. Skipping generation of sample."));
|
|
628
683
|
}
|
|
@@ -633,7 +688,7 @@ async function run6(projectPath) {
|
|
|
633
688
|
__name(run6, "run");
|
|
634
689
|
|
|
635
690
|
// src/actions/migrate.ts
|
|
636
|
-
import
|
|
691
|
+
import fs8 from "fs";
|
|
637
692
|
import path7 from "path";
|
|
638
693
|
|
|
639
694
|
// src/actions/seed.ts
|
|
@@ -688,8 +743,8 @@ async function run8(command, options) {
|
|
|
688
743
|
break;
|
|
689
744
|
}
|
|
690
745
|
} finally {
|
|
691
|
-
if (
|
|
692
|
-
|
|
746
|
+
if (fs8.existsSync(prismaSchemaFile)) {
|
|
747
|
+
fs8.unlinkSync(prismaSchemaFile);
|
|
693
748
|
}
|
|
694
749
|
}
|
|
695
750
|
}
|
|
@@ -780,7 +835,7 @@ __name(handleSubProcessError2, "handleSubProcessError");
|
|
|
780
835
|
// src/telemetry.ts
|
|
781
836
|
import { init } from "mixpanel";
|
|
782
837
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
783
|
-
import
|
|
838
|
+
import fs13 from "fs";
|
|
784
839
|
import * as os2 from "os";
|
|
785
840
|
|
|
786
841
|
// src/constants.ts
|
|
@@ -791,14 +846,14 @@ import { env } from "process";
|
|
|
791
846
|
var isInCi = env["CI"] !== "0" && env["CI"] !== "false" && ("CI" in env || "CONTINUOUS_INTEGRATION" in env || Object.keys(env).some((key) => key.startsWith("CI_")));
|
|
792
847
|
|
|
793
848
|
// src/utils/is-container.ts
|
|
794
|
-
import
|
|
849
|
+
import fs10 from "fs";
|
|
795
850
|
|
|
796
851
|
// src/utils/is-docker.ts
|
|
797
|
-
import
|
|
852
|
+
import fs9 from "fs";
|
|
798
853
|
var isDockerCached;
|
|
799
854
|
function hasDockerEnv() {
|
|
800
855
|
try {
|
|
801
|
-
|
|
856
|
+
fs9.statSync("/.dockerenv");
|
|
802
857
|
return true;
|
|
803
858
|
} catch {
|
|
804
859
|
return false;
|
|
@@ -807,7 +862,7 @@ function hasDockerEnv() {
|
|
|
807
862
|
__name(hasDockerEnv, "hasDockerEnv");
|
|
808
863
|
function hasDockerCGroup() {
|
|
809
864
|
try {
|
|
810
|
-
return
|
|
865
|
+
return fs9.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
811
866
|
} catch {
|
|
812
867
|
return false;
|
|
813
868
|
}
|
|
@@ -825,7 +880,7 @@ __name(isDocker, "isDocker");
|
|
|
825
880
|
var cachedResult;
|
|
826
881
|
var hasContainerEnv = /* @__PURE__ */ __name(() => {
|
|
827
882
|
try {
|
|
828
|
-
|
|
883
|
+
fs10.statSync("/run/.containerenv");
|
|
829
884
|
return true;
|
|
830
885
|
} catch {
|
|
831
886
|
return false;
|
|
@@ -842,7 +897,7 @@ __name(isInContainer, "isInContainer");
|
|
|
842
897
|
// src/utils/is-wsl.ts
|
|
843
898
|
import process2 from "process";
|
|
844
899
|
import os from "os";
|
|
845
|
-
import
|
|
900
|
+
import fs11 from "fs";
|
|
846
901
|
var isWsl = /* @__PURE__ */ __name(() => {
|
|
847
902
|
if (process2.platform !== "linux") {
|
|
848
903
|
return false;
|
|
@@ -851,7 +906,7 @@ var isWsl = /* @__PURE__ */ __name(() => {
|
|
|
851
906
|
return true;
|
|
852
907
|
}
|
|
853
908
|
try {
|
|
854
|
-
return
|
|
909
|
+
return fs11.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
|
|
855
910
|
} catch {
|
|
856
911
|
return false;
|
|
857
912
|
}
|
|
@@ -916,7 +971,7 @@ __name(getMachineId, "getMachineId");
|
|
|
916
971
|
|
|
917
972
|
// src/utils/version-utils.ts
|
|
918
973
|
import colors8 from "colors";
|
|
919
|
-
import
|
|
974
|
+
import fs12 from "fs";
|
|
920
975
|
import path8 from "path";
|
|
921
976
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
922
977
|
import semver from "semver";
|
|
@@ -925,7 +980,7 @@ var VERSION_CHECK_TAG = "next";
|
|
|
925
980
|
function getVersion() {
|
|
926
981
|
try {
|
|
927
982
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : path8.dirname(fileURLToPath2(import.meta.url));
|
|
928
|
-
return JSON.parse(
|
|
983
|
+
return JSON.parse(fs12.readFileSync(path8.join(_dirname, "../package.json"), "utf8")).version;
|
|
929
984
|
} catch {
|
|
930
985
|
return void 0;
|
|
931
986
|
}
|
|
@@ -1055,7 +1110,7 @@ var Telemetry = class {
|
|
|
1055
1110
|
try {
|
|
1056
1111
|
const packageJsonPath = import.meta.resolve("prisma/package.json");
|
|
1057
1112
|
const packageJsonUrl = new URL(packageJsonPath);
|
|
1058
|
-
const packageJson = JSON.parse(
|
|
1113
|
+
const packageJson = JSON.parse(fs13.readFileSync(packageJsonUrl, "utf8"));
|
|
1059
1114
|
return packageJson.version;
|
|
1060
1115
|
} catch {
|
|
1061
1116
|
return void 0;
|