@ghentcdh/create-crouton 0.0.1-alpha.26 → 0.0.1-alpha.27
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/dist/index.js +68 -25
- package/dist/index.js.map +1 -1
- package/dist/lib/index.js +20 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/templates/nx/root/nx.json.tmpl +2 -1
- package/dist/templates/nx/root/package.json.tmpl +7 -1
- package/dist/templates/nx/root/pnpm-workspace.yaml.tmpl +16 -2
- package/dist/templates/nx/root/tsconfig.base.json.tmpl +2 -1
- package/dist/templates/nx/workspace/apps/backend/package.json.tmpl +1 -0
- package/dist/templates/nx/workspace/apps/backend/project.json.tmpl +1 -1
- package/dist/templates/nx/workspace/apps/backend/src/app/app.module.ts.tmpl +1 -0
- package/dist/templates/nx/workspace/apps/backend/tsconfig.json.tmpl +1 -2
- package/dist/templates/nx/workspace/apps/frontend/project.json.tmpl +1 -1
- package/dist/templates/nx/workspace/apps/frontend/src/App.vue.tmpl +1 -4
- package/dist/templates/nx/workspace/apps/frontend/src/main.ts.tmpl +22 -1
- package/dist/templates/nx/workspace/apps/frontend/tsconfig.json.tmpl +1 -1
- package/dist/templates/nx/workspace/generated/{types → default/client}/package.json.tmpl +1 -1
- package/dist/templates/nx/workspace/generated/default/types/package.json.tmpl +9 -0
- package/dist/templates/regular/.npmrc.tmpl +4 -0
- package/dist/templates/regular/package.json.tmpl +1 -0
- package/dist/templates/regular/src/app.module.ts.tmpl +1 -0
- package/dist/templates/regular/tsconfig.json.tmpl +2 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -19243,7 +19243,9 @@ var RulesetSchema = external_exports.object({
|
|
|
19243
19243
|
showRelationsInForm: external_exports.boolean().default(true),
|
|
19244
19244
|
enumValueLabel: external_exports.boolean().default(true),
|
|
19245
19245
|
sharedEnums: external_exports.boolean().default(true),
|
|
19246
|
-
defaultOperations: JsonOperationsSchema.default(
|
|
19246
|
+
defaultOperations: JsonOperationsSchema.default(
|
|
19247
|
+
JsonOperationsSchema.parse({})
|
|
19248
|
+
)
|
|
19247
19249
|
});
|
|
19248
19250
|
var CroutonConfigSchema = external_exports.object({
|
|
19249
19251
|
/**
|
|
@@ -19262,7 +19264,7 @@ var CroutonConfigSchema = external_exports.object({
|
|
|
19262
19264
|
*/
|
|
19263
19265
|
schemaExportName: external_exports.string().default("{Model}WithRelationsSchema"),
|
|
19264
19266
|
/** Path to the shared enum registry, relative to project root. Default `crouton.enums.json`. */
|
|
19265
|
-
enumsFile: external_exports.string().default("
|
|
19267
|
+
enumsFile: external_exports.string().default("crouton.enums.json"),
|
|
19266
19268
|
/** Optional overrides of the default visibility ruleset. */
|
|
19267
19269
|
rules: RulesetSchema.default(RulesetSchema.parse({})),
|
|
19268
19270
|
/**
|
|
@@ -19336,7 +19338,7 @@ var buildDatasourceFiles = (opts) => {
|
|
|
19336
19338
|
zodOutput,
|
|
19337
19339
|
prismaConfig
|
|
19338
19340
|
};
|
|
19339
|
-
const clientImport = relImport(dsDir, clientOutput);
|
|
19341
|
+
const clientImport = opts.generatedClientImport ?? relImport(dsDir, clientOutput);
|
|
19340
19342
|
const indexTs = `import { PrismaClient } from '${clientImport}';
|
|
19341
19343
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
19342
19344
|
|
|
@@ -19372,14 +19374,17 @@ datasource db {
|
|
|
19372
19374
|
// url is provided by ${prismaConfig} (Prisma 7 forbids \`url\` here)
|
|
19373
19375
|
}
|
|
19374
19376
|
`;
|
|
19377
|
+
const configDir = dirname4(prismaConfig);
|
|
19378
|
+
const relSchema = relImport(configDir, prismaSchema);
|
|
19379
|
+
const relMigrations = relImport(configDir, migrationsDir);
|
|
19375
19380
|
const prismaConfigTs = `// Generated by \`crouton create-datasource\`.
|
|
19376
19381
|
import 'dotenv/config';
|
|
19377
19382
|
import { defineConfig, env } from 'prisma/config';
|
|
19378
19383
|
|
|
19379
19384
|
export default defineConfig({
|
|
19380
|
-
schema: '${
|
|
19385
|
+
schema: '${relSchema}',
|
|
19381
19386
|
migrations: {
|
|
19382
|
-
path: '${
|
|
19387
|
+
path: '${relMigrations}',
|
|
19383
19388
|
},
|
|
19384
19389
|
datasource: {
|
|
19385
19390
|
url: env('${opts.urlEnv}'),
|
|
@@ -19433,7 +19438,24 @@ var writeFiles = async (files, opts = {}) => {
|
|
|
19433
19438
|
var loadTemplate = async (templateDir, relativePath) => readFile4(`${templateDir}/${relativePath}`, "utf-8");
|
|
19434
19439
|
|
|
19435
19440
|
// src/lib/pm.ts
|
|
19436
|
-
import { spawn } from "child_process";
|
|
19441
|
+
import { execSync, spawn } from "child_process";
|
|
19442
|
+
var MIN_PNPM_MAJOR = 11;
|
|
19443
|
+
var checkPnpmVersion = () => {
|
|
19444
|
+
let raw;
|
|
19445
|
+
try {
|
|
19446
|
+
raw = execSync("pnpm --version", { stdio: "pipe" }).toString().trim();
|
|
19447
|
+
} catch {
|
|
19448
|
+
throw new Error("pnpm is not installed. Install it with: npm i -g pnpm@latest");
|
|
19449
|
+
}
|
|
19450
|
+
const major = parseInt(raw.split(".")[0], 10);
|
|
19451
|
+
if (isNaN(major) || major < MIN_PNPM_MAJOR) {
|
|
19452
|
+
throw new Error(
|
|
19453
|
+
`pnpm ${raw} detected, but version ${MIN_PNPM_MAJOR}+ is required.
|
|
19454
|
+
Upgrade with: npm i -g pnpm@latest`
|
|
19455
|
+
);
|
|
19456
|
+
}
|
|
19457
|
+
return raw;
|
|
19458
|
+
};
|
|
19437
19459
|
var installDeps = (pm, cwd) => new Promise((resolve3, reject) => {
|
|
19438
19460
|
const child = spawn(pm, ["install"], { cwd, stdio: "inherit" });
|
|
19439
19461
|
child.on(
|
|
@@ -19469,7 +19491,7 @@ var render = (template, tokens) => {
|
|
|
19469
19491
|
};
|
|
19470
19492
|
|
|
19471
19493
|
// src/runner.ts
|
|
19472
|
-
import { execSync } from "child_process";
|
|
19494
|
+
import { execSync as execSync2 } from "child_process";
|
|
19473
19495
|
import { existsSync } from "fs";
|
|
19474
19496
|
import { readdir as readdir4 } from "fs/promises";
|
|
19475
19497
|
import { resolve as resolve2 } from "path";
|
|
@@ -19497,6 +19519,10 @@ var runCreate = async (name, opts) => {
|
|
|
19497
19519
|
const frontend = await resolveFrontend(opts, layout);
|
|
19498
19520
|
const prefix = layout === "nx" ? await resolvePrefix(opts) : void 0;
|
|
19499
19521
|
const pm = await resolvePm(opts);
|
|
19522
|
+
if (pm === "pnpm") {
|
|
19523
|
+
const pnpmVersion = checkPnpmVersion();
|
|
19524
|
+
M2.info(`Using pnpm ${pnpmVersion}`);
|
|
19525
|
+
}
|
|
19500
19526
|
const dbUrl = await resolveDbUrl(opts);
|
|
19501
19527
|
const dbName = name.replace(/[^a-zA-Z0-9]/g, "_");
|
|
19502
19528
|
const tokens = {
|
|
@@ -19516,12 +19542,16 @@ var runCreate = async (name, opts) => {
|
|
|
19516
19542
|
tokens["prefix"] = prefix;
|
|
19517
19543
|
tokens["appsRoot"] = `${prefix}/apps`;
|
|
19518
19544
|
tokens["schemaPath"] = "../../../node_modules/nx/schemas/project-schema.json";
|
|
19519
|
-
tokens["
|
|
19545
|
+
tokens["tsconfigBase"] = "../../../tsconfig.base.json";
|
|
19546
|
+
tokens["generatedTypesPath"] = `${prefix}/generated/default/types/src`;
|
|
19547
|
+
tokens["generatedClientPath"] = `${prefix}/generated/default/client/src`;
|
|
19520
19548
|
} else {
|
|
19521
19549
|
tokens["noPrefix"] = "true";
|
|
19522
19550
|
tokens["appsRoot"] = "apps";
|
|
19523
19551
|
tokens["schemaPath"] = "../../node_modules/nx/schemas/project-schema.json";
|
|
19524
|
-
tokens["
|
|
19552
|
+
tokens["tsconfigBase"] = "../../tsconfig.base.json";
|
|
19553
|
+
tokens["generatedTypesPath"] = "generated/default/types/src";
|
|
19554
|
+
tokens["generatedClientPath"] = "generated/default/client/src";
|
|
19525
19555
|
}
|
|
19526
19556
|
}
|
|
19527
19557
|
if (frontend) {
|
|
@@ -19543,14 +19573,18 @@ var runCreate = async (name, opts) => {
|
|
|
19543
19573
|
files.push(...dockerFiles);
|
|
19544
19574
|
}
|
|
19545
19575
|
const dataSourcesDir = "apps/backend/src/app/data-sources";
|
|
19546
|
-
const generatedImport = `@${name}/generated/default`;
|
|
19576
|
+
const generatedImport = `@${name}/generated/default/types`;
|
|
19577
|
+
const generatedClientImport = `@${name}/generated/default/client`;
|
|
19547
19578
|
const { files: dsFiles } = buildDatasourceFiles({
|
|
19548
19579
|
name: "default",
|
|
19549
19580
|
dataSourcesDir,
|
|
19550
19581
|
urlEnv: "DATABASE_URL",
|
|
19551
19582
|
generatedTypesImport: generatedImport,
|
|
19583
|
+
generatedClientImport,
|
|
19552
19584
|
type: "postgres",
|
|
19553
|
-
default: true
|
|
19585
|
+
default: true,
|
|
19586
|
+
zodOutput: "generated/default/types/src",
|
|
19587
|
+
clientOutput: "generated/default/client/src"
|
|
19554
19588
|
});
|
|
19555
19589
|
for (const f of dsFiles) {
|
|
19556
19590
|
files.push({ path: resolve2(workspaceTarget, f.path), contents: f.contents });
|
|
@@ -19568,14 +19602,18 @@ var runCreate = async (name, opts) => {
|
|
|
19568
19602
|
files.push(...dockerFiles);
|
|
19569
19603
|
}
|
|
19570
19604
|
const dataSourcesDir = "src/data-sources";
|
|
19571
|
-
const generatedImport = "@app/generated/default";
|
|
19605
|
+
const generatedImport = "@app/generated/default/types";
|
|
19606
|
+
const generatedClientImport = "@app/generated/default/client";
|
|
19572
19607
|
const { files: dsFiles } = buildDatasourceFiles({
|
|
19573
19608
|
name: "default",
|
|
19574
19609
|
dataSourcesDir,
|
|
19575
19610
|
urlEnv: "DATABASE_URL",
|
|
19576
19611
|
generatedTypesImport: generatedImport,
|
|
19612
|
+
generatedClientImport,
|
|
19577
19613
|
type: "postgres",
|
|
19578
|
-
default: true
|
|
19614
|
+
default: true,
|
|
19615
|
+
zodOutput: "generated/default/types/src",
|
|
19616
|
+
clientOutput: "generated/default/client/src"
|
|
19579
19617
|
});
|
|
19580
19618
|
for (const f of dsFiles) {
|
|
19581
19619
|
files.push({ path: resolve2(targetDir, f.path), contents: f.contents });
|
|
@@ -19585,11 +19623,12 @@ var runCreate = async (name, opts) => {
|
|
|
19585
19623
|
await postScaffold(opts, targetDir, pm, dbUrl);
|
|
19586
19624
|
}
|
|
19587
19625
|
const pmRun = pm === "npm" ? "npm run" : pm;
|
|
19626
|
+
const prefixFlag = prefix ? ` --prefix ${prefix}` : "";
|
|
19588
19627
|
Me(
|
|
19589
19628
|
[
|
|
19590
19629
|
opts.docker !== false ? "docker compose up -d # start postgres" : null,
|
|
19591
19630
|
`${pmRun} prisma:migrate # create initial migration`,
|
|
19592
|
-
|
|
19631
|
+
`crouton update resources${prefixFlag} # generate resource CRUD`,
|
|
19593
19632
|
`${pmRun} dev # start dev server`
|
|
19594
19633
|
].filter(Boolean).join("\n"),
|
|
19595
19634
|
"Next steps"
|
|
@@ -19608,7 +19647,7 @@ var postScaffold = async (opts, targetDir, pm, dbUrl, prefix) => {
|
|
|
19608
19647
|
const s = Y2();
|
|
19609
19648
|
s.start("Initializing git repository");
|
|
19610
19649
|
try {
|
|
19611
|
-
|
|
19650
|
+
execSync2('git init && git add -A && git commit -m "Initial commit"', {
|
|
19612
19651
|
cwd: targetDir,
|
|
19613
19652
|
stdio: "pipe"
|
|
19614
19653
|
});
|
|
@@ -19629,22 +19668,26 @@ var postScaffold = async (opts, targetDir, pm, dbUrl, prefix) => {
|
|
|
19629
19668
|
if (dbUrl) {
|
|
19630
19669
|
try {
|
|
19631
19670
|
const s2 = Y2();
|
|
19632
|
-
s2.start("Running
|
|
19633
|
-
const
|
|
19634
|
-
|
|
19635
|
-
cwd:
|
|
19636
|
-
stdio: "pipe"
|
|
19671
|
+
s2.start("Running crouton update resources");
|
|
19672
|
+
const croutonCwd = prefix ? resolve2(targetDir, prefix) : targetDir;
|
|
19673
|
+
execSync2("npx crouton update resources --yes", {
|
|
19674
|
+
cwd: croutonCwd,
|
|
19675
|
+
stdio: "pipe",
|
|
19676
|
+
env: { ...process.env, DATABASE_URL: dbUrl }
|
|
19637
19677
|
});
|
|
19638
|
-
s2.stop("
|
|
19639
|
-
} catch {
|
|
19640
|
-
|
|
19678
|
+
s2.stop("Resources updated");
|
|
19679
|
+
} catch (err) {
|
|
19680
|
+
const stderr = err instanceof Error && "stderr" in err ? String(err.stderr).trim() : "";
|
|
19681
|
+
M2.warn(
|
|
19682
|
+
"crouton update resources failed \u2014 run it manually after setting up your database." + (stderr ? `
|
|
19683
|
+
${import_picocolors3.default.dim(stderr)}` : "")
|
|
19684
|
+
);
|
|
19641
19685
|
}
|
|
19642
|
-
} else {
|
|
19643
|
-
M2.info("Skipping prisma generate \u2014 no database URL provided.");
|
|
19644
19686
|
}
|
|
19645
19687
|
}
|
|
19646
19688
|
};
|
|
19647
19689
|
var resolveLayout = async (opts) => {
|
|
19690
|
+
if (opts.prefix) return "nx";
|
|
19648
19691
|
if (opts.yes) return opts.nx ? "nx" : "regular";
|
|
19649
19692
|
if (opts.nx) return "nx";
|
|
19650
19693
|
const layout = assertNotCancel(
|