create-better-schemic 0.1.0-alpha.15 → 0.1.0-alpha.16
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/README.md +8 -7
- package/lib/index.js +31 -49
- package/package.json +2 -1
- package/src/index.ts +53 -76
package/README.md
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# create-better-schemic
|
|
2
2
|
|
|
3
|
-
Scaffold a new [Better-schemic](https://github.com/NONSTANDARDCODE/better-schemic) project — `package.json`, `tsconfig.json`,
|
|
4
|
-
|
|
3
|
+
Scaffold a new [Better-schemic](https://github.com/NONSTANDARDCODE/better-schemic) project — `package.json`, `tsconfig.json`, and
|
|
4
|
+
the `database/` schema — in one command.
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
7
|
npm create better-schemic@latest # or: bun create better-schemic, pnpm create better-schemic
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Interactive by default (project directory
|
|
10
|
+
Interactive by default (project directory and whether/how to install). Flags:
|
|
11
11
|
|
|
12
12
|
```
|
|
13
|
-
create-better-schemic [directory] [--
|
|
13
|
+
create-better-schemic [directory] [--pm bun|npm|pnpm|yarn]
|
|
14
14
|
[--no-install] [--no-git] [-y]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
It writes the TS project envelope,
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
It writes the TS project envelope, installs `better-schemic` (the ONE package: the authoring
|
|
18
|
+
surface, the engine and the CLI — Zod and the SurrealDB SDK ship inside it), then runs
|
|
19
|
+
`better-schemic init` to scaffold the config + `database/` schema. To add Better-schemic to an
|
|
20
|
+
EXISTING project, use `better-schemic init` directly.
|
package/lib/index.js
CHANGED
|
@@ -100,7 +100,8 @@ import {
|
|
|
100
100
|
readFileSync,
|
|
101
101
|
writeFileSync
|
|
102
102
|
} from "node:fs";
|
|
103
|
-
import {
|
|
103
|
+
import { createRequire } from "node:module";
|
|
104
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
104
105
|
|
|
105
106
|
// ../../node_modules/.bun/@clack+core@1.5.1/node_modules/@clack/core/dist/index.mjs
|
|
106
107
|
import { styleText } from "node:util";
|
|
@@ -1256,20 +1257,12 @@ ${i}
|
|
|
1256
1257
|
}
|
|
1257
1258
|
}).prompt();
|
|
1258
1259
|
// package.json
|
|
1259
|
-
var version = "0.1.0-alpha.
|
|
1260
|
+
var version = "0.1.0-alpha.16";
|
|
1260
1261
|
|
|
1261
1262
|
// src/index.ts
|
|
1262
1263
|
var RANGE = `^${version}`;
|
|
1263
1264
|
var bold = (s) => `\x1B[1m${s}\x1B[0m`;
|
|
1264
1265
|
var dim = (s) => `\x1B[2m${s}\x1B[0m`;
|
|
1265
|
-
var DRIVERS = {
|
|
1266
|
-
surrealdb: {
|
|
1267
|
-
label: "SurrealDB",
|
|
1268
|
-
pkg: "@better-schemic/surrealdb",
|
|
1269
|
-
deps: { surrealdb: "^2.0.3", zod: "^4.3.5" }
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
var DRIVER_NAMES = Object.keys(DRIVERS);
|
|
1273
1266
|
var PMS = ["bun", "npm", "pnpm", "yarn"];
|
|
1274
1267
|
function parseArgs(argv) {
|
|
1275
1268
|
const o = { git: true, yes: false };
|
|
@@ -1281,25 +1274,30 @@ function parseArgs(argv) {
|
|
|
1281
1274
|
o.install = false;
|
|
1282
1275
|
else if (a === "--no-git")
|
|
1283
1276
|
o.git = false;
|
|
1284
|
-
else if (a === "--driver")
|
|
1285
|
-
o.driver = argv[++i];
|
|
1286
1277
|
else if (a === "--pm")
|
|
1287
1278
|
o.pm = argv[++i];
|
|
1288
1279
|
else if (a === "-h" || a === "--help") {
|
|
1289
1280
|
printHelp();
|
|
1290
1281
|
process.exit(0);
|
|
1291
|
-
} else if (
|
|
1282
|
+
} else if (a.startsWith("-"))
|
|
1283
|
+
unknownOption(a);
|
|
1284
|
+
else if (o.dir === undefined)
|
|
1292
1285
|
o.dir = a;
|
|
1293
1286
|
}
|
|
1294
1287
|
return o;
|
|
1295
1288
|
}
|
|
1289
|
+
function unknownOption(option) {
|
|
1290
|
+
console.error(`Unknown option: ${option}
|
|
1291
|
+
`);
|
|
1292
|
+
printHelp();
|
|
1293
|
+
process.exit(1);
|
|
1294
|
+
}
|
|
1296
1295
|
function printHelp() {
|
|
1297
1296
|
console.log(`create-better-schemic — scaffold a new Better-schemic project
|
|
1298
1297
|
|
|
1299
1298
|
Usage: create-better-schemic [directory] [options]
|
|
1300
1299
|
|
|
1301
1300
|
Options:
|
|
1302
|
-
--driver <name> ${DRIVER_NAMES.join(" | ")}
|
|
1303
1301
|
--pm <name> ${PMS.join(" | ")} (the package manager to install with)
|
|
1304
1302
|
--no-install scaffold only; don't install or run \`better-schemic init\`
|
|
1305
1303
|
--no-git don't run \`git init\`
|
|
@@ -1323,16 +1321,8 @@ function abortIfCancel(value) {
|
|
|
1323
1321
|
var SCRIPTS = {
|
|
1324
1322
|
db: "better-schemic"
|
|
1325
1323
|
};
|
|
1326
|
-
function depMap(
|
|
1327
|
-
|
|
1328
|
-
const deps = {
|
|
1329
|
-
"@better-schemic/cli": RANGE,
|
|
1330
|
-
[d.pkg]: RANGE,
|
|
1331
|
-
...d.deps
|
|
1332
|
-
};
|
|
1333
|
-
if (pm === "pnpm")
|
|
1334
|
-
deps["@better-schemic/core"] = RANGE;
|
|
1335
|
-
return deps;
|
|
1324
|
+
function depMap() {
|
|
1325
|
+
return { "better-schemic": RANGE };
|
|
1336
1326
|
}
|
|
1337
1327
|
var TSCONFIG = `${JSON.stringify({
|
|
1338
1328
|
compilerOptions: {
|
|
@@ -1350,9 +1340,9 @@ var TSCONFIG = `${JSON.stringify({
|
|
|
1350
1340
|
exclude: ["node_modules"]
|
|
1351
1341
|
}, null, 2)}
|
|
1352
1342
|
`;
|
|
1353
|
-
function applyPackageJson(target, name
|
|
1343
|
+
function applyPackageJson(target, name) {
|
|
1354
1344
|
const path = join(target, "package.json");
|
|
1355
|
-
const deps = depMap(
|
|
1345
|
+
const deps = depMap();
|
|
1356
1346
|
if (!existsSync(path)) {
|
|
1357
1347
|
const fresh = {
|
|
1358
1348
|
name,
|
|
@@ -1412,6 +1402,16 @@ function run(cmd, args, cwd, capture = false) {
|
|
|
1412
1402
|
});
|
|
1413
1403
|
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}` };
|
|
1414
1404
|
}
|
|
1405
|
+
function resolveCliEntry(target) {
|
|
1406
|
+
const require2 = createRequire(join(target, "package.json"));
|
|
1407
|
+
const manifestPath = require2.resolve("better-schemic/package.json");
|
|
1408
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
1409
|
+
const bin = manifest.bin;
|
|
1410
|
+
const rel = typeof bin === "string" ? bin : bin?.["better-schemic"];
|
|
1411
|
+
if (!rel)
|
|
1412
|
+
throw new Error("the installed `better-schemic` package exposes no `better-schemic` bin — reinstall it.");
|
|
1413
|
+
return join(dirname(manifestPath), rel);
|
|
1414
|
+
}
|
|
1415
1415
|
async function main() {
|
|
1416
1416
|
const opts = parseArgs(process.argv.slice(2));
|
|
1417
1417
|
const tty = !!process.stdin.isTTY && !opts.yes;
|
|
@@ -1439,22 +1439,6 @@ async function main() {
|
|
|
1439
1439
|
process.exit(1);
|
|
1440
1440
|
}
|
|
1441
1441
|
}
|
|
1442
|
-
let driver = opts.driver;
|
|
1443
|
-
if (!driver && tty) {
|
|
1444
|
-
driver = abortIfCancel(await select({
|
|
1445
|
-
message: "Database driver",
|
|
1446
|
-
options: DRIVER_NAMES.map((n) => ({
|
|
1447
|
-
value: n,
|
|
1448
|
-
label: DRIVERS[n].label
|
|
1449
|
-
})),
|
|
1450
|
-
initialValue: "surrealdb"
|
|
1451
|
-
}));
|
|
1452
|
-
}
|
|
1453
|
-
driver ||= "surrealdb";
|
|
1454
|
-
if (!DRIVERS[driver]) {
|
|
1455
|
-
cancel(`Unknown driver "${driver}". Known: ${DRIVER_NAMES.join(", ")}.`);
|
|
1456
|
-
process.exit(1);
|
|
1457
|
-
}
|
|
1458
1442
|
const detected = detectPm();
|
|
1459
1443
|
let install = opts.install;
|
|
1460
1444
|
if (install === undefined)
|
|
@@ -1478,12 +1462,12 @@ async function main() {
|
|
|
1478
1462
|
}));
|
|
1479
1463
|
}
|
|
1480
1464
|
const written = [
|
|
1481
|
-
applyPackageJson(target, name
|
|
1465
|
+
applyPackageJson(target, name),
|
|
1482
1466
|
applyTsconfig(target),
|
|
1483
1467
|
writeIfAbsent(target, ".gitignore", GITIGNORE)
|
|
1484
1468
|
];
|
|
1485
1469
|
const header = isExisting ? `Adding Better-schemic to ${name}` : name;
|
|
1486
|
-
log.step(`${bold(header)} ${dim(
|
|
1470
|
+
log.step(`${bold(header)} ${dim("(SurrealDB)")}
|
|
1487
1471
|
${written.join(`
|
|
1488
1472
|
`)}`);
|
|
1489
1473
|
if (opts.git && !existsSync(join(target, ".git")))
|
|
@@ -1503,10 +1487,8 @@ ${written.join(`
|
|
|
1503
1487
|
s.stop("Dependencies installed");
|
|
1504
1488
|
log.step("Scaffolding the schema");
|
|
1505
1489
|
const runtime = pm === "bun" ? "bun" : "node";
|
|
1506
|
-
const cliJs =
|
|
1507
|
-
|
|
1508
|
-
process.env.SCHEMIC_NO_BOOTSTRAP = "1";
|
|
1509
|
-
run(runtime, [cliJs, "init", "--driver", driver], target);
|
|
1490
|
+
const cliJs = resolveCliEntry(target);
|
|
1491
|
+
run(runtime, [cliJs, "init"], target);
|
|
1510
1492
|
}
|
|
1511
1493
|
const cd = dir === "." ? "" : `cd ${dir}
|
|
1512
1494
|
`;
|
|
@@ -1514,7 +1496,7 @@ ${written.join(`
|
|
|
1514
1496
|
const steps = install ? `${cd}cp .env.example .env ${dim("# set your connection")}
|
|
1515
1497
|
${dbCmd("gen")}
|
|
1516
1498
|
${dbCmd("migrate")}` : `${cd}${pm} install
|
|
1517
|
-
${pm} exec better-schemic init
|
|
1499
|
+
${pm} exec better-schemic init
|
|
1518
1500
|
cp .env.example .env
|
|
1519
1501
|
${dbCmd("gen")}`;
|
|
1520
1502
|
note(steps, "Next steps");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-better-schemic",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.16",
|
|
4
4
|
"description": "Scaffold a new Better-schemic project — package.json, tsconfig, a driver, and the database/ schema, in one command.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "NONSTANDARDCODE",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "bun run ../../scripts/build.ts",
|
|
28
28
|
"prepack": "bun run build",
|
|
29
|
+
"test": "bun test",
|
|
29
30
|
"typecheck": "bun check",
|
|
30
31
|
"lint": "biome check ."
|
|
31
32
|
},
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
readFileSync,
|
|
7
7
|
writeFileSync,
|
|
8
8
|
} from "node:fs";
|
|
9
|
-
import {
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
10
11
|
import * as p from "@clack/prompts";
|
|
11
|
-
// The
|
|
12
|
+
// The better-schemic version this scaffolder pins is its OWN version (the packages release lockstep), so a
|
|
12
13
|
// fresh project always gets a matching set. Inlined at build by the Bun bundler.
|
|
13
14
|
import { version as BETTER_SCHEMIC_VERSION } from "../package.json";
|
|
14
15
|
|
|
@@ -16,24 +17,11 @@ const RANGE = `^${BETTER_SCHEMIC_VERSION}`;
|
|
|
16
17
|
const bold = (s: string) => `\x1b[1m${s}\x1b[0m`;
|
|
17
18
|
const dim = (s: string) => `\x1b[2m${s}\x1b[0m`;
|
|
18
19
|
|
|
19
|
-
/** Supported drivers: the package + the runtime deps a project authoring/connecting with it needs. */
|
|
20
|
-
const DRIVERS: Record<
|
|
21
|
-
string,
|
|
22
|
-
{ label: string; pkg: string; deps: Record<string, string> }
|
|
23
|
-
> = {
|
|
24
|
-
surrealdb: {
|
|
25
|
-
label: "SurrealDB",
|
|
26
|
-
pkg: "@better-schemic/surrealdb",
|
|
27
|
-
deps: { surrealdb: "^2.0.3", zod: "^4.3.5" },
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
const DRIVER_NAMES = Object.keys(DRIVERS);
|
|
31
20
|
const PMS = ["bun", "npm", "pnpm", "yarn"] as const;
|
|
32
21
|
type Pm = (typeof PMS)[number];
|
|
33
22
|
|
|
34
23
|
interface Options {
|
|
35
24
|
dir?: string;
|
|
36
|
-
driver?: string;
|
|
37
25
|
pm?: string;
|
|
38
26
|
install?: boolean; // undefined = ask
|
|
39
27
|
git: boolean;
|
|
@@ -47,23 +35,32 @@ function parseArgs(argv: string[]): Options {
|
|
|
47
35
|
if (a === "-y" || a === "--yes") o.yes = true;
|
|
48
36
|
else if (a === "--no-install") o.install = false;
|
|
49
37
|
else if (a === "--no-git") o.git = false;
|
|
50
|
-
else if (a === "--driver") o.driver = argv[++i];
|
|
51
38
|
else if (a === "--pm") o.pm = argv[++i];
|
|
52
39
|
else if (a === "-h" || a === "--help") {
|
|
53
40
|
printHelp();
|
|
54
41
|
process.exit(0);
|
|
55
|
-
} else if (
|
|
42
|
+
} else if (a.startsWith("-"))
|
|
43
|
+
// An unknown OPTION is an error, never a directory name — a typo must not scaffold a folder
|
|
44
|
+
// named after the flag's value.
|
|
45
|
+
unknownOption(a);
|
|
46
|
+
else if (o.dir === undefined) o.dir = a;
|
|
56
47
|
}
|
|
57
48
|
return o;
|
|
58
49
|
}
|
|
59
50
|
|
|
51
|
+
/** Refuse an unknown option with the usage (an exit, so the caller never continues). */
|
|
52
|
+
function unknownOption(option: string): never {
|
|
53
|
+
console.error(`Unknown option: ${option}\n`);
|
|
54
|
+
printHelp();
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
60
58
|
function printHelp(): void {
|
|
61
59
|
console.log(`create-better-schemic — scaffold a new Better-schemic project
|
|
62
60
|
|
|
63
61
|
Usage: create-better-schemic [directory] [options]
|
|
64
62
|
|
|
65
63
|
Options:
|
|
66
|
-
--driver <name> ${DRIVER_NAMES.join(" | ")}
|
|
67
64
|
--pm <name> ${PMS.join(" | ")} (the package manager to install with)
|
|
68
65
|
--no-install scaffold only; don't install or run \`better-schemic init\`
|
|
69
66
|
--no-git don't run \`git init\`
|
|
@@ -95,16 +92,13 @@ const SCRIPTS: Record<string, string> = {
|
|
|
95
92
|
db: "better-schemic",
|
|
96
93
|
};
|
|
97
94
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
if (pm === "pnpm") deps["@better-schemic/core"] = RANGE;
|
|
107
|
-
return deps;
|
|
95
|
+
/**
|
|
96
|
+
* The runtime deps a scaffolded project needs. `better-schemic` is ONE package: the authoring
|
|
97
|
+
* surface, the engine and the CLI. Zod and the SurrealDB SDK ship INSIDE it (they are its
|
|
98
|
+
* dependencies, not peers), so the project never installs them itself.
|
|
99
|
+
*/
|
|
100
|
+
function depMap(): Record<string, string> {
|
|
101
|
+
return { "better-schemic": RANGE };
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
// Kept conservative so it works across TypeScript 5, 6, and 7: `module: "ESNext"` (5.0+) rather than
|
|
@@ -131,14 +125,9 @@ const TSCONFIG = `${JSON.stringify(
|
|
|
131
125
|
)}\n`;
|
|
132
126
|
|
|
133
127
|
/** NEW project → write a fresh package.json. EXISTING → MERGE deps + scripts (never clobber). */
|
|
134
|
-
function applyPackageJson(
|
|
135
|
-
target: string,
|
|
136
|
-
name: string,
|
|
137
|
-
driver: string,
|
|
138
|
-
pm: Pm,
|
|
139
|
-
): string {
|
|
128
|
+
function applyPackageJson(target: string, name: string): string {
|
|
140
129
|
const path = join(target, "package.json");
|
|
141
|
-
const deps = depMap(
|
|
130
|
+
const deps = depMap();
|
|
142
131
|
if (!existsSync(path)) {
|
|
143
132
|
const fresh = {
|
|
144
133
|
name,
|
|
@@ -216,6 +205,26 @@ function run(
|
|
|
216
205
|
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}` };
|
|
217
206
|
}
|
|
218
207
|
|
|
208
|
+
/**
|
|
209
|
+
* The CLI entry of the INSTALLED `better-schemic` package, resolved from its own manifest (the
|
|
210
|
+
* `bin` field) — never a hardcoded path, so a change in the package layout can't break the
|
|
211
|
+
* scaffolder.
|
|
212
|
+
*/
|
|
213
|
+
function resolveCliEntry(target: string): string {
|
|
214
|
+
const require = createRequire(join(target, "package.json"));
|
|
215
|
+
const manifestPath = require.resolve("better-schemic/package.json");
|
|
216
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {
|
|
217
|
+
bin?: string | Record<string, string>;
|
|
218
|
+
};
|
|
219
|
+
const bin = manifest.bin;
|
|
220
|
+
const rel = typeof bin === "string" ? bin : bin?.["better-schemic"];
|
|
221
|
+
if (!rel)
|
|
222
|
+
throw new Error(
|
|
223
|
+
"the installed `better-schemic` package exposes no `better-schemic` bin — reinstall it.",
|
|
224
|
+
);
|
|
225
|
+
return join(dirname(manifestPath), rel);
|
|
226
|
+
}
|
|
227
|
+
|
|
219
228
|
async function main(): Promise<void> {
|
|
220
229
|
const opts = parseArgs(process.argv.slice(2));
|
|
221
230
|
const tty = !!process.stdin.isTTY && !opts.yes;
|
|
@@ -252,27 +261,7 @@ async function main(): Promise<void> {
|
|
|
252
261
|
}
|
|
253
262
|
}
|
|
254
263
|
|
|
255
|
-
// 2.
|
|
256
|
-
let driver = opts.driver;
|
|
257
|
-
if (!driver && tty) {
|
|
258
|
-
driver = abortIfCancel(
|
|
259
|
-
await p.select({
|
|
260
|
-
message: "Database driver",
|
|
261
|
-
options: DRIVER_NAMES.map((n) => ({
|
|
262
|
-
value: n,
|
|
263
|
-
label: DRIVERS[n].label,
|
|
264
|
-
})),
|
|
265
|
-
initialValue: "surrealdb",
|
|
266
|
-
}),
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
driver ||= "surrealdb";
|
|
270
|
-
if (!DRIVERS[driver]) {
|
|
271
|
-
p.cancel(`Unknown driver "${driver}". Known: ${DRIVER_NAMES.join(", ")}.`);
|
|
272
|
-
process.exit(1);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// 3. install? + which package manager (ask, default = detected)
|
|
264
|
+
// 2. install? + which package manager (ask, default = detected)
|
|
276
265
|
const detected = detectPm();
|
|
277
266
|
let install = opts.install;
|
|
278
267
|
if (install === undefined)
|
|
@@ -302,20 +291,18 @@ async function main(): Promise<void> {
|
|
|
302
291
|
) as Pm;
|
|
303
292
|
}
|
|
304
293
|
|
|
305
|
-
//
|
|
294
|
+
// 3. write/merge the project envelope (fresh for a new project, merge into an existing one)
|
|
306
295
|
const written = [
|
|
307
|
-
applyPackageJson(target, name
|
|
296
|
+
applyPackageJson(target, name),
|
|
308
297
|
applyTsconfig(target),
|
|
309
298
|
writeIfAbsent(target, ".gitignore", GITIGNORE),
|
|
310
299
|
];
|
|
311
300
|
const header = isExisting ? `Adding Better-schemic to ${name}` : name;
|
|
312
|
-
p.log.step(
|
|
313
|
-
`${bold(header)} ${dim(`(${DRIVERS[driver].label})`)}\n${written.join("\n")}`,
|
|
314
|
-
);
|
|
301
|
+
p.log.step(`${bold(header)} ${dim("(SurrealDB)")}\n${written.join("\n")}`);
|
|
315
302
|
if (opts.git && !existsSync(join(target, ".git")))
|
|
316
303
|
run("git", ["init", "-q"], target);
|
|
317
304
|
|
|
318
|
-
//
|
|
305
|
+
// 4. install + compose on `better-schemic init` (which scaffolds the config + database/)
|
|
319
306
|
if (install) {
|
|
320
307
|
const s = p.spinner();
|
|
321
308
|
s.start(`Installing dependencies with ${pm}`);
|
|
@@ -329,28 +316,18 @@ async function main(): Promise<void> {
|
|
|
329
316
|
s.stop("Dependencies installed");
|
|
330
317
|
p.log.step("Scaffolding the schema");
|
|
331
318
|
const runtime = pm === "bun" ? "bun" : "node";
|
|
332
|
-
const cliJs =
|
|
333
|
-
|
|
334
|
-
"node_modules",
|
|
335
|
-
"@better-schemic",
|
|
336
|
-
"cli",
|
|
337
|
-
"lib",
|
|
338
|
-
"cli.js",
|
|
339
|
-
);
|
|
340
|
-
// Mark the inner init as already-bootstrapped so it scaffolds directly (never forwards back here).
|
|
341
|
-
process.env.BETTER_SCHEMIC_NO_BOOTSTRAP = "1";
|
|
342
|
-
process.env.SCHEMIC_NO_BOOTSTRAP = "1"; // legacy alias
|
|
343
|
-
run(runtime, [cliJs, "init", "--driver", driver], target);
|
|
319
|
+
const cliJs = resolveCliEntry(target);
|
|
320
|
+
run(runtime, [cliJs, "init"], target);
|
|
344
321
|
}
|
|
345
322
|
|
|
346
|
-
//
|
|
323
|
+
// 5. next steps
|
|
347
324
|
const cd = dir === "." ? "" : `cd ${dir}\n`;
|
|
348
325
|
// npm needs `npm run db -- <sub>` to forward args; bun/pnpm/yarn forward `<pm> run db <sub>` directly.
|
|
349
326
|
const dbCmd = (sub: string) =>
|
|
350
327
|
pm === "npm" ? `npm run db -- ${sub}` : `${pm} run db ${sub}`;
|
|
351
328
|
const steps = install
|
|
352
329
|
? `${cd}cp .env.example .env ${dim("# set your connection")}\n${dbCmd("gen")}\n${dbCmd("migrate")}`
|
|
353
|
-
: `${cd}${pm} install\n${pm} exec better-schemic init
|
|
330
|
+
: `${cd}${pm} install\n${pm} exec better-schemic init\ncp .env.example .env\n${dbCmd("gen")}`;
|
|
354
331
|
p.note(steps, "Next steps");
|
|
355
332
|
p.outro(`${bold(name)} is ready.`);
|
|
356
333
|
}
|