@junejs/cli 0.0.15 → 0.0.17
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/package.json +3 -3
- package/src/cli.ts +45 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junejs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "The `june` CLI — dev / build / deploy / gen / info. A thin bin over @junejs/server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"typecheck": "tsc --noEmit"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@junejs/core": "0.0.
|
|
24
|
-
"@junejs/server": "0.0.
|
|
23
|
+
"@junejs/core": "0.0.17",
|
|
24
|
+
"@junejs/server": "0.0.17"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
package/src/cli.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// process; the bin (june.ts) just forwards process.argv. See docs/cli.md.
|
|
4
4
|
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
|
+
import { writeFile } from "node:fs/promises";
|
|
6
7
|
import { join, resolve } from "node:path";
|
|
7
8
|
|
|
8
9
|
export type Parsed = {
|
|
@@ -43,7 +44,7 @@ Commands:
|
|
|
43
44
|
build Build a workerd-ready bundle --out <dir>
|
|
44
45
|
deploy Build + deploy (workers/vercel) --dry-run --prod --skip-migrate --allow-destructive
|
|
45
46
|
gen Freeze content/schema --check
|
|
46
|
-
db Database tasks (db migrate)
|
|
47
|
+
db Database tasks (db migrate, db types) --allow-destructive
|
|
47
48
|
info Show routes + the agent surface
|
|
48
49
|
help Show this help
|
|
49
50
|
|
|
@@ -140,28 +141,53 @@ export async function run(argv: string[]): Promise<number | undefined> {
|
|
|
140
141
|
return 0;
|
|
141
142
|
}
|
|
142
143
|
case "db": {
|
|
143
|
-
// `june db migrate [dir]
|
|
144
|
-
//
|
|
144
|
+
// `june db <migrate|types> [dir]`. The subcommand is positional[0], so the app
|
|
145
|
+
// dir (if any) is positional[1] — not `root`.
|
|
145
146
|
const sub = positional[0];
|
|
146
|
-
if (sub !== "migrate") {
|
|
147
|
-
console.error(`june db: unknown subcommand "${sub ?? ""}" (try: june db migrate)`);
|
|
148
|
-
return 1;
|
|
149
|
-
}
|
|
150
147
|
const dbRoot = positional[1] ? resolve(positional[1]) : process.cwd();
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
148
|
+
if (sub === "migrate") {
|
|
149
|
+
const { loadJuneConfig, migrateApp, blockedMessage } = await import("@junejs/server");
|
|
150
|
+
const config = await loadJuneConfig(dbRoot);
|
|
151
|
+
if (!config.resources?.db) {
|
|
152
|
+
console.error("june db migrate: no `db` resource declared in june.config.ts.");
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
const r = await migrateApp(dbRoot, config, { allowDestructive: !!flags["allow-destructive"] });
|
|
156
|
+
if (r?.applied.length) console.log(`migrated: ${r.applied.join(", ")}`);
|
|
157
|
+
else if (r && !r.blocked) console.log("migrations up to date");
|
|
158
|
+
if (r?.blocked) {
|
|
159
|
+
console.error(blockedMessage(r.blocked));
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
return 0;
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
if (sub === "types") {
|
|
165
|
+
// Generate db/schema.d.ts from the migrated schema (Stage 3 inference).
|
|
166
|
+
const { loadJuneConfig, typesApp } = await import("@junejs/server");
|
|
167
|
+
const config = await loadJuneConfig(dbRoot);
|
|
168
|
+
if (!config.resources?.db) {
|
|
169
|
+
console.error("june db types: no `db` resource declared in june.config.ts.");
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
if (!config.dataLayer?.emitTypes) {
|
|
173
|
+
console.error(
|
|
174
|
+
"june db types: the configured dataLayer doesn't generate types " +
|
|
175
|
+
"(declare `dataLayer: junoDataLayer()` in june.config.ts).",
|
|
176
|
+
);
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
const text = await typesApp(dbRoot, config);
|
|
180
|
+
if (text == null) {
|
|
181
|
+
console.log("nothing to generate");
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
const out = join(dbRoot, "db", "schema.d.ts");
|
|
185
|
+
await writeFile(out, text);
|
|
186
|
+
console.log("wrote db/schema.d.ts");
|
|
187
|
+
return 0;
|
|
163
188
|
}
|
|
164
|
-
|
|
189
|
+
console.error(`june db: unknown subcommand "${sub ?? ""}" (try: june db migrate | june db types)`);
|
|
190
|
+
return 1;
|
|
165
191
|
}
|
|
166
192
|
case "info":
|
|
167
193
|
return info(root);
|