@brickkit/cli 0.12.0 → 0.13.0
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/dashboard-dist/{api-reference-B-bZRtNV.js → api-reference-mT9VNcPb.js} +69 -69
- package/dashboard-dist/app.js +12 -13
- package/dashboard-dist/{client-BJJtVSVr.js → client-CwATkLJa.js} +1 -1
- package/dashboard-dist/{core-Z7NJFk0K.js → core-BEUWp6B5.js} +1 -1
- package/dashboard-dist/docs-BRrtyxDB.js +4 -0
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/popover-Bj9x-88h.js +1 -0
- package/dist/bin.js +154 -217
- package/dist/bin.js.map +1 -1
- package/dist/build.js +463 -0
- package/dist/build.js.map +1 -0
- package/dist/client-contract-file.js +356 -1
- package/dist/client-contract-file.js.map +1 -0
- package/dist/compiler.d.ts +12 -2
- package/dist/compiler2.js +12 -5
- package/dist/compiler2.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +1 -250
- package/dist/config2.d.ts +122 -0
- package/dist/config2.js +207 -0
- package/dist/config2.js.map +1 -0
- package/dist/dashboard-extension.d.ts +3 -0
- package/dist/{dev-telemetry-store.js → dashboard-host.js} +1533 -1574
- package/dist/dashboard-host.js.map +1 -0
- package/dist/dashboard-protocol.js +189 -0
- package/dist/dashboard-protocol.js.map +1 -0
- package/dist/dashboard.d.ts +4 -1
- package/dist/definitions.js +33 -0
- package/dist/definitions.js.map +1 -0
- package/dist/dev-application.js +34 -0
- package/dist/dev-application.js.map +1 -0
- package/dist/dev-protocol.js +21 -0
- package/dist/dev-protocol.js.map +1 -0
- package/dist/dev-reporter.js +2 -1
- package/dist/dev-reporter.js.map +1 -1
- package/dist/dev-telemetry.js +5 -20
- package/dist/dev-telemetry.js.map +1 -1
- package/dist/dev-worker.js +79 -19
- package/dist/dev-worker.js.map +1 -1
- package/dist/index.d.ts +15 -74
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -0
- package/dist/lint/oxlint.js +5 -3
- package/dist/lint/oxlint.js.map +1 -1
- package/dist/own-module.js +7 -0
- package/dist/own-module.js.map +1 -0
- package/dist/plugin.d.ts +6 -5
- package/dist/plugin.js +5 -39
- package/dist/plugin.js.map +1 -1
- package/dist/production-dashboard.d.ts +2 -0
- package/dist/production-dashboard.js +51 -0
- package/dist/production-dashboard.js.map +1 -0
- package/dist/production-dashboard2.d.ts +34 -0
- package/dist/{presets.js → project.js} +104 -106
- package/dist/project.js.map +1 -0
- package/dist/serve.d.ts +24 -0
- package/dist/serve.js +1 -0
- package/dist/serve2.js +49 -0
- package/dist/serve2.js.map +1 -0
- package/dist/vite.js +26 -47
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +2 -2
- package/dist/workflows2.js +59 -37
- package/dist/workflows2.js.map +1 -1
- package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
- package/inspector-dist/client/assets/{highlighted-body-B3W2YXNL-DYVdwGy2.js → highlighted-body-B3W2YXNL-CfRnuITN.js} +1 -1
- package/inspector-dist/client/assets/{home-CyjkvtII.js → home-hwPlkNhv.js} +1529 -378
- package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
- package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
- package/inspector-dist/client/assets/{root-DX9wtogx.js → root-SLeEf-sT.js} +17 -29
- package/inspector-dist/client/assets/{run-detail-C69EJGql.js → run-detail-DYbVkIFH.js} +398 -76
- package/inspector-dist/client/assets/{tabs-B6B88IjT.js → tabs-CaJisoyb.js} +189 -2130
- package/inspector-dist/client/assets/{zstd-browser-decoder-ByUgcY9H.js → zstd-browser-decoder-D94wmfAU.js} +1 -1
- package/inspector-dist/server/assets/{app-WoDoT62X.js → app-DGlfWVUI.js} +69783 -70608
- package/inspector-dist/server/assets/{chunk-RLXIAIE6-CbvDIAEa.js → chunk-RLXIAIE6-F0SJZlei.js} +4 -6
- package/inspector-dist/server/assets/{dist-qR-969AD.js → dist-BCbwm6jl.js} +2 -4
- package/inspector-dist/server/assets/{dist-CQnQcIJg.js → dist-CG2aVufI.js} +0 -2
- package/inspector-dist/server/assets/{dist-BRxZSWUN.js → dist-Ce0I2PUv.js} +2 -5
- package/inspector-dist/server/assets/{dist-DqRd9pyS.js → dist-DY0UlahA.js} +0 -2
- package/inspector-dist/server/assets/{encryption-_PuklZNX.js → encryption-DdQgC8Rk.js} +2 -4
- package/inspector-dist/server/assets/{event-metadata-BVakQJ_y.js → event-metadata-n7E4zEmT.js} +0 -2
- package/inspector-dist/server/assets/{functions-CImcpqNl.js → functions-CNVQtbgg.js} +2 -4
- package/inspector-dist/server/assets/{global-singleton-CPirHxFh.js → global-singleton-D8sIN5du.js} +0 -2
- package/inspector-dist/server/assets/{highlighted-body-B3W2YXNL-fPMB_t7F.js → highlighted-body-B3W2YXNL-CWRzMxYD.js} +2 -4
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
- package/inspector-dist/server/assets/{parse-D9Vvgzt9.js → parse-Begau9cA.js} +0 -2
- package/inspector-dist/server/assets/{rolldown-runtime-CLg409Sh.js → rolldown-runtime-C1I3wEg2.js} +1 -2
- package/inspector-dist/server/assets/{serialization-format-DDtsVTU1.js → serialization-format-BbuGfHog.js} +6 -8
- package/inspector-dist/server/assets/{token-BW4GdQZh.js → token-BgMmJNP5.js} +2 -4
- package/inspector-dist/server/assets/{token-D6FXdkJT.js → token-BrUX0bxz.js} +2 -4
- package/inspector-dist/server/assets/{token-util-BoNmi-wE.js → token-util-DZN32qmT.js} +1 -3
- package/inspector-dist/server/assets/{wrapper-wiqsGXcE.js → wrapper-CIC3w0oC.js} +1 -3
- package/inspector-dist/server/assets/{ws-transport-DV7oG4mL.js → ws-transport-CxTYB11n.js} +24094 -24096
- package/inspector-dist/server/assets/{zstd-browser-decoder-Cswf0KO6.js → zstd-browser-decoder-D7bCXbGg.js} +2 -4
- package/inspector-dist/server/index.js +1 -3
- package/package.json +12 -2
- package/dashboard-dist/docs-Dpfc0wJb.js +0 -4
- package/dashboard-dist/popover-BzejBolB.js +0 -1
- package/dist/app-entry.js +0 -1
- package/dist/app-entry2.js +0 -18
- package/dist/app-entry2.js.map +0 -1
- package/dist/client-contract-file2.js +0 -33
- package/dist/client-contract-file2.js.map +0 -1
- package/dist/client-contract.js +0 -1
- package/dist/client-contract2.js +0 -296
- package/dist/client-contract2.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/dev-telemetry-store.js.map +0 -1
- package/dist/emit.d.ts +0 -5
- package/dist/presets.js.map +0 -1
- package/dist/runner.js +0 -519
- package/dist/runner.js.map +0 -1
- package/inspector-dist/client/assets/app-CCzpuUz_.css +0 -2
- package/inspector-dist/client/assets/manifest-ba30b52d.js +0 -1
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +0 -1
- package/inspector-dist/client/assets/root-8BMab1lL.css +0 -2
- package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +0 -30
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +0 -3
package/dist/bin.js
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
7
|
-
import { i as resolveRules, r as fileRules } from "./presets.js";
|
|
2
|
+
import { a as writeServiceManifest, i as startWorker, n as startDevServer, r as startProdServer, t as buildApplication } from "./build.js";
|
|
3
|
+
import { r as writeClientContract, s as loadBrickApp } from "./client-contract-file.js";
|
|
4
|
+
import { d as resolveDevDashboard, f as resolvePort, n as ConfigError, o as DEFAULT_PORT, p as resolveProject, r as DEFAULT_DASHBOARD_PORT } from "./config2.js";
|
|
5
|
+
import { o as version, s as serviceFolders, t as projectRules } from "./project.js";
|
|
6
|
+
import { a as TEST_FILE, n as DEFINITION_FILE, t as DEFINITION_EXTENSIONS } from "./definitions.js";
|
|
8
7
|
import { createRequire } from "node:module";
|
|
9
|
-
import {
|
|
10
|
-
import { drizzleSchema, generateOpenApiSpec, getGlobalRegistry, getPluginActionRoute, getTableName, kebabCase, migrateDatabase, sql } from "@brickkit/core";
|
|
8
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
11
9
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
12
|
-
import {
|
|
10
|
+
import { drizzleSchema, getGlobalRegistry, getTableName, isCrudEvent, migrateDatabase, sql } from "@brickkit/core";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
13
12
|
import { Command, InvalidArgumentError } from "commander";
|
|
14
13
|
import { spawnSync } from "node:child_process";
|
|
15
14
|
import { tmpdir } from "node:os";
|
|
16
15
|
// src/lint/run.ts
|
|
17
|
-
|
|
16
|
+
let fromSource;
|
|
17
|
+
/** The lint/oxlint entry oxlint loads under Node: the bundle beside this code, or, run from source, a fresh bundle of it. */
|
|
18
18
|
function pluginPath() {
|
|
19
19
|
const here = fileURLToPath(import.meta.url);
|
|
20
|
-
|
|
20
|
+
if (!here.endsWith(".ts")) return resolve(dirname(here), "lint/oxlint.js");
|
|
21
|
+
if (fromSource) return fromSource;
|
|
22
|
+
const file = resolve(here, "../../../node_modules/.cache/brick-lint.js");
|
|
23
|
+
const building = `${file}.${process.pid}`;
|
|
24
|
+
const result = spawnSync(process.execPath, [
|
|
25
|
+
"build",
|
|
26
|
+
resolve(dirname(here), "oxlint.ts"),
|
|
27
|
+
"--target",
|
|
28
|
+
"node"
|
|
29
|
+
].concat([
|
|
30
|
+
"--packages",
|
|
31
|
+
"external",
|
|
32
|
+
"--outfile",
|
|
33
|
+
building
|
|
34
|
+
]), { encoding: "utf8" });
|
|
35
|
+
if (result.status !== 0) throw new Error(`Brick: building the lint plugin failed:\n${result.stderr}`);
|
|
36
|
+
renameSync(building, file);
|
|
37
|
+
return fromSource = file;
|
|
21
38
|
}
|
|
22
39
|
function oxlintBin(root) {
|
|
23
40
|
for (const base of [join(root, "package.json"), fileURLToPath(import.meta.url)]) try {
|
|
@@ -55,7 +72,7 @@ function runFileRules(options) {
|
|
|
55
72
|
"--no-error-on-unmatched-pattern",
|
|
56
73
|
...options.fix ? ["--fix"] : [],
|
|
57
74
|
...(options.ignore ?? []).flatMap((pattern) => ["--ignore-pattern", pattern]),
|
|
58
|
-
|
|
75
|
+
"."
|
|
59
76
|
], {
|
|
60
77
|
cwd: options.root,
|
|
61
78
|
encoding: "utf8",
|
|
@@ -85,50 +102,37 @@ function runFileRules(options) {
|
|
|
85
102
|
}
|
|
86
103
|
// src/lint.ts
|
|
87
104
|
const posix$1 = (path) => path.split(sep).join("/");
|
|
88
|
-
const SOURCE = new Bun.Glob(
|
|
105
|
+
const SOURCE = new Bun.Glob(`**/*.{${[...DEFINITION_EXTENSIONS, "cts"].join(",")}}`);
|
|
89
106
|
/**
|
|
90
107
|
* `brick lint`: the file rules through oxlint, then the app
|
|
91
108
|
* rules against the loaded app. Prints `file:line:col` lines and returns the
|
|
92
109
|
* exit code: 1 when anything is an error.
|
|
93
110
|
*/
|
|
94
111
|
async function runLint(options) {
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
throw new ConfigError(`brick.config.ts: lint.rules: ${error.message}`);
|
|
103
|
-
}
|
|
104
|
-
const fromRoot = (path) => posix$1(relative(root, path)) || ".";
|
|
105
|
-
const services = project?.services ?? resolve(root, "src/services");
|
|
106
|
-
const generated = project?.generated ?? resolve(root, "_brick");
|
|
107
|
-
const entry = options.entry ? resolve(options.entry) : project?.entry ?? resolve(root, "src/app.ts");
|
|
108
|
-
const ignore = [...config.ignore ?? [], `${fromRoot(generated)}/**`];
|
|
112
|
+
const entry = options.entry ? resolve(options.entry) : options.project.entry;
|
|
113
|
+
const project = {
|
|
114
|
+
...options.project,
|
|
115
|
+
entry
|
|
116
|
+
};
|
|
117
|
+
const { root, services } = project;
|
|
118
|
+
const { resolved, rules, settings, ignore } = projectRules(project);
|
|
109
119
|
const messages = runFileRules({
|
|
110
120
|
root,
|
|
111
|
-
rules
|
|
112
|
-
settings
|
|
113
|
-
root,
|
|
114
|
-
services: fromRoot(services),
|
|
115
|
-
entry: fromRoot(entry),
|
|
116
|
-
generated: fromRoot(generated),
|
|
117
|
-
web: "web"
|
|
118
|
-
},
|
|
121
|
+
rules,
|
|
122
|
+
settings,
|
|
119
123
|
ignore
|
|
120
124
|
});
|
|
121
125
|
const globs = ignore.map((pattern) => new Bun.Glob(pattern));
|
|
122
126
|
if (existsSync(entry)) {
|
|
123
|
-
if (project) await writeServiceManifest(project);
|
|
127
|
+
if (project.file) await writeServiceManifest(project);
|
|
124
128
|
messages.push(...await checkApp({
|
|
125
129
|
root,
|
|
126
130
|
entry,
|
|
127
131
|
services,
|
|
128
|
-
severity: (rule) =>
|
|
132
|
+
severity: (rule) => resolved[`brick/${rule}`] ?? "off",
|
|
129
133
|
ignored: (rel) => rel.split("/").includes("node_modules") || globs.some((glob) => glob.match(rel))
|
|
130
134
|
}));
|
|
131
|
-
} else if (options.entry || project) throw new Error(`Brick: entry not found: ${entry}`);
|
|
135
|
+
} else if (options.entry || project.file) throw new Error(`Brick: entry not found: ${entry}`);
|
|
132
136
|
return report(messages);
|
|
133
137
|
}
|
|
134
138
|
function report(messages) {
|
|
@@ -147,93 +151,73 @@ function sourceFiles(check, under = check.root) {
|
|
|
147
151
|
onlyFiles: true
|
|
148
152
|
})].map((file) => resolve(under, file)).filter((file) => {
|
|
149
153
|
const rel = posix$1(relative(check.root, file));
|
|
150
|
-
return !check.ignored(rel) &&
|
|
154
|
+
return !check.ignored(rel) && !TEST_FILE.test(rel) && !rel.startsWith("dist/");
|
|
151
155
|
});
|
|
152
156
|
}
|
|
153
157
|
function lineOf(source, index) {
|
|
154
158
|
return source.slice(0, index).split("\n").length;
|
|
155
159
|
}
|
|
156
|
-
/**
|
|
160
|
+
/** Each app rule's check; a rule in APP_RULES without one fails to compile. */
|
|
161
|
+
const APP_CHECKS = {
|
|
162
|
+
"single-app-entry": singleAppEntry,
|
|
163
|
+
"no-cross-service-tables": noCrossServiceTables,
|
|
164
|
+
"unique-names": () => {},
|
|
165
|
+
"declared-events": declaredEvents,
|
|
166
|
+
"test-colocated": testColocated
|
|
167
|
+
};
|
|
157
168
|
async function checkApp(check) {
|
|
158
169
|
const messages = [];
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
severity,
|
|
168
|
-
message
|
|
169
|
-
});
|
|
170
|
-
};
|
|
170
|
+
const message = (rule, severity, file, text, line = 1) => ({
|
|
171
|
+
file: posix$1(relative(check.root, file)),
|
|
172
|
+
line,
|
|
173
|
+
column: 1,
|
|
174
|
+
rule: `brick/${rule}`,
|
|
175
|
+
severity,
|
|
176
|
+
message: text
|
|
177
|
+
});
|
|
171
178
|
let app;
|
|
172
179
|
try {
|
|
173
180
|
app = await loadBrickApp(check.entry);
|
|
174
181
|
} catch (error) {
|
|
175
|
-
|
|
176
|
-
if (/duplicate/i.test(message)) {
|
|
177
|
-
add("unique-names", check.entry, message);
|
|
178
|
-
return messages;
|
|
179
|
-
}
|
|
182
|
+
if (error.name === "DuplicateNameError") return [message("unique-names", "error", check.entry, error.message)];
|
|
180
183
|
throw error;
|
|
181
184
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
for (const [rule, run] of Object.entries(APP_CHECKS)) {
|
|
186
|
+
const severity = check.severity(rule);
|
|
187
|
+
if (severity === "off") continue;
|
|
188
|
+
await run(check, app, (file, text, line) => messages.push(message(rule, severity, file, text, line)));
|
|
189
|
+
}
|
|
187
190
|
return messages;
|
|
188
191
|
}
|
|
189
|
-
function singleAppEntry(check,
|
|
190
|
-
if (check.severity("single-app-entry") === "off") return;
|
|
192
|
+
function singleAppEntry(check, _app, add) {
|
|
191
193
|
let calls = 0;
|
|
192
|
-
for (const file of
|
|
194
|
+
for (const file of sourceFiles(check)) {
|
|
193
195
|
const source = readFileSync(file, "utf8");
|
|
194
196
|
if (!/import\s*\{[^}]*\bbrick\b[^}]*\}\s*from\s*["']@brickkit\/core["']/.test(source)) continue;
|
|
195
197
|
for (const match of source.matchAll(/(?<![.\w])brick\s*\(/g)) {
|
|
196
198
|
if (file === check.entry && ++calls === 1) continue;
|
|
197
|
-
add(
|
|
199
|
+
add(file, file === check.entry ? "The entry calls brick() more than once; keep one app." : `brick() is called outside the entry (${posix$1(relative(check.root, check.entry))}); keep one app.`, lineOf(source, match.index));
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
|
-
function uniqueNames(check, app, add) {
|
|
202
|
-
const services = [...app.definition.services];
|
|
203
|
-
const seen = /* @__PURE__ */ new Set();
|
|
204
|
-
for (const service of services) {
|
|
205
|
-
if (seen.has(service.name)) add("unique-names", check.entry, `Two services are named "${service.name}".`);
|
|
206
|
-
seen.add(service.name);
|
|
207
|
-
const owners = /* @__PURE__ */ new Map();
|
|
208
|
-
const claim = (name, what) => {
|
|
209
|
-
const segment = kebabCase(name);
|
|
210
|
-
const other = owners.get(segment);
|
|
211
|
-
if (other) add("unique-names", check.entry, `In service "${service.name}", ${what} and ${other} share the name "${segment}".`);
|
|
212
|
-
else owners.set(segment, what);
|
|
213
|
-
};
|
|
214
|
-
for (const action of service.listActions()) if (action.config.path === void 0 && !action.resourceAction && getPluginActionRoute(action) === void 0) claim(action.name, `action "${action.name}"`);
|
|
215
|
-
for (const socket of service.listSockets()) if (socket.schema.path === void 0) claim(socket.schema.name, `socket "${socket.schema.name}"`);
|
|
216
|
-
for (const resource of service.listResources()) claim(resource.name, `resource "${resource.name}"`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
203
|
/** Which service owns each table: its resources' and registered tables, or a database it alone uses. */
|
|
220
204
|
function tableOwners(app) {
|
|
221
205
|
const owners = /* @__PURE__ */ new Map();
|
|
222
206
|
const users = /* @__PURE__ */ new Map();
|
|
223
207
|
for (const service of app.definition.services) {
|
|
224
|
-
for (const table of service.tables
|
|
225
|
-
const database = service.options
|
|
208
|
+
for (const table of service.tables.values()) owners.set(table, service.name);
|
|
209
|
+
const { database } = service.options;
|
|
226
210
|
if (database) users.set(database, [...users.get(database) ?? [], service.name]);
|
|
227
211
|
}
|
|
228
212
|
for (const [database, names] of users) if (names.length === 1) {
|
|
229
|
-
for (const table of Object.values(database.tables
|
|
213
|
+
for (const table of Object.values(database.tables)) if (!owners.has(table)) owners.set(table, names[0]);
|
|
230
214
|
}
|
|
231
215
|
return owners;
|
|
232
216
|
}
|
|
233
217
|
function serviceOfFolder(app, folder) {
|
|
234
|
-
return app.definition.services.find((service) =>
|
|
218
|
+
return app.definition.services.find((service) => serviceFolders(service.name).includes(folder))?.name;
|
|
235
219
|
}
|
|
236
|
-
const IMPORT = /import\s+(type\s+)?([\w$]+\s*,?\s*)?(
|
|
220
|
+
const IMPORT = /(?:import|export)\s+(type\s+)?([\w$]+\s*,?\s*)?(\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})?\s*from\s*["']([^"']+)["']/g;
|
|
237
221
|
async function noCrossServiceTables(check, app, add) {
|
|
238
222
|
const owners = tableOwners(app);
|
|
239
223
|
for (const file of sourceFiles(check, check.services)) {
|
|
@@ -253,8 +237,8 @@ async function noCrossServiceTables(check, app, add) {
|
|
|
253
237
|
const line = lineOf(source, match.index);
|
|
254
238
|
const where = posix$1(relative(check.services, target)).split("/");
|
|
255
239
|
const otherFolder = !where[0].startsWith("..") && where.length > 1 ? where[0] : void 0;
|
|
256
|
-
if (otherFolder && otherFolder !== folder &&
|
|
257
|
-
add(
|
|
240
|
+
if (otherFolder && otherFolder !== folder && DEFINITION_FILE.exec(basename(target))?.[2] === "table") {
|
|
241
|
+
add(file, `Service "${service}" imports ${basename(target)} from ${otherFolder}/; call that service's actions or listen to its events instead.`, line);
|
|
258
242
|
continue;
|
|
259
243
|
}
|
|
260
244
|
const module = await import(target).catch(() => ({}));
|
|
@@ -267,36 +251,30 @@ async function noCrossServiceTables(check, app, add) {
|
|
|
267
251
|
}
|
|
268
252
|
for (const name of names) {
|
|
269
253
|
const owner = owners.get(module[name]);
|
|
270
|
-
if (owner && owner !== service) add(
|
|
254
|
+
if (owner && owner !== service) add(file, `Service "${service}" imports table ${name === "default" ? basename(target) : `"${name}"`} owned by "${owner}"; call ${owner}'s actions or listen to its events instead.`, line);
|
|
271
255
|
}
|
|
272
256
|
}
|
|
273
257
|
}
|
|
274
258
|
}
|
|
275
259
|
function declaredEvents(check, app, add) {
|
|
276
|
-
if (check.severity("declared-events") === "off") return;
|
|
277
260
|
for (const service of app.definition.services) {
|
|
278
261
|
if (!service.options.events) continue;
|
|
279
262
|
const names = new Set(Object.values(service.events).map((e) => e.name));
|
|
280
263
|
const resources = service.listResources().map((r) => r.name);
|
|
281
|
-
const declared = (name) =>
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
};
|
|
285
|
-
for (const action of service.listActions()) for (const name of action.config.emits ?? []) if (!declared(name)) add("declared-events", check.entry, `Action "${service.name}.${action.name}" emits "${name}", which is not in ${service.name}'s event catalog.`);
|
|
286
|
-
const folder = [kebabCase(service.name), service.name].map((name) => resolve(check.services, name)).find(existsSync);
|
|
264
|
+
const declared = (name) => names.has(name) || isCrudEvent(name, resources);
|
|
265
|
+
for (const action of service.listActions()) for (const name of action.config.emits ?? []) if (!declared(name)) add(check.entry, `Action "${service.name}.${action.name}" emits "${name}", which is not in ${service.name}'s event catalog.`);
|
|
266
|
+
const folder = serviceFolders(service.name).map((name) => resolve(check.services, name)).find(existsSync);
|
|
287
267
|
for (const file of folder ? sourceFiles(check, folder) : []) {
|
|
288
268
|
const source = readFileSync(file, "utf8");
|
|
289
|
-
for (const match of source.matchAll(/emitEvent\s*\([^,]+,\s*["'`]([^"'`]+)["'`]/g)) if (!declared(match[1])) add(
|
|
269
|
+
for (const match of source.matchAll(/emitEvent\s*\([^,]+,\s*["'`]([^"'`]+)["'`]/g)) if (!declared(match[1])) add(file, `"${match[1]}" is not in ${service.name}'s event catalog.`, lineOf(source, match.index));
|
|
290
270
|
}
|
|
291
271
|
}
|
|
292
272
|
}
|
|
293
|
-
function testColocated(check, add) {
|
|
294
|
-
if (check.severity("test-colocated") === "off") return;
|
|
273
|
+
function testColocated(check, _app, add) {
|
|
295
274
|
for (const file of sourceFiles(check, check.services)) {
|
|
296
|
-
const match =
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
if (!existsSync(test) && !existsSync(`${test}x`)) add("test-colocated", file, `${basename(file)} has no ${match[1]}.test.ts beside it.`);
|
|
275
|
+
const match = DEFINITION_FILE.exec(basename(file));
|
|
276
|
+
if (match?.[2] !== "action" && match?.[2] !== "command") continue;
|
|
277
|
+
if (!readdirSync(dirname(file)).some((sibling) => TEST_FILE.test(sibling) && sibling.replace(TEST_FILE, "") === match[1])) add(file, `${basename(file)} has no ${match[1]}.test.ts beside it.`);
|
|
300
278
|
}
|
|
301
279
|
}
|
|
302
280
|
// src/db.ts
|
|
@@ -337,7 +315,6 @@ function appDatabases(app) {
|
|
|
337
315
|
}
|
|
338
316
|
/** Run `brick db generate|migrate|push` against every database of the app. */
|
|
339
317
|
async function runDbCommand(command, app, options) {
|
|
340
|
-
const log = options.log ?? console.log;
|
|
341
318
|
const databases = appDatabases(app);
|
|
342
319
|
if (!databases.length) throw new Error("Brick: the app has no database with tables.");
|
|
343
320
|
try {
|
|
@@ -350,13 +327,13 @@ async function runDbCommand(command, app, options) {
|
|
|
350
327
|
const label = `${entry.name} (${entry.database.engine})`;
|
|
351
328
|
if (command === "generate") {
|
|
352
329
|
const file = await generate(entry, folder, options.name);
|
|
353
|
-
log(file ? `${label}: wrote ${file}` : `${label}: no schema changes`);
|
|
330
|
+
console.log(file ? `${label}: wrote ${file}` : `${label}: no schema changes`);
|
|
354
331
|
} else if (command === "migrate") {
|
|
355
332
|
await migrateDatabase(entry.database, folder);
|
|
356
|
-
log(`${label}: migrations in ${folder} applied`);
|
|
333
|
+
console.log(`${label}: migrations in ${folder} applied`);
|
|
357
334
|
} else {
|
|
358
|
-
const applied = await push(entry, options.force ?? false
|
|
359
|
-
log(applied ? `${label}: applied ${applied} change${applied === 1 ? "" : "s"}` : `${label}: no schema changes`);
|
|
335
|
+
const applied = await push(entry, options.force ?? false);
|
|
336
|
+
console.log(applied ? `${label}: applied ${applied} change${applied === 1 ? "" : "s"}` : `${label}: no schema changes`);
|
|
360
337
|
}
|
|
361
338
|
}
|
|
362
339
|
} finally {
|
|
@@ -415,7 +392,7 @@ async function generate(entry, folder, name = "migration") {
|
|
|
415
392
|
* Make the database match the tables with drizzle-kit's push, touching only
|
|
416
393
|
* the tables Brick knows. Returns how many statements ran.
|
|
417
394
|
*/
|
|
418
|
-
async function push(entry, force
|
|
395
|
+
async function push(entry, force) {
|
|
419
396
|
const { pushSchema, pushSQLiteSchema } = await kit();
|
|
420
397
|
const db = entry.database.getDb();
|
|
421
398
|
const names = new Set(entry.tables.map((table) => getTableName(table)));
|
|
@@ -424,7 +401,7 @@ async function push(entry, force, log) {
|
|
|
424
401
|
const result = postgres ? await pushSchema(schema, { execute: async (query) => ({ rows: await db.execute(query) }) }, [...new Set(entry.tables.map((table) => table[Symbol.for("drizzle:Schema")] ?? "public"))], [...names]) : await pushSQLiteSchema(schema, onlyTables(db, names));
|
|
425
402
|
const statements = result.statementsToExecute;
|
|
426
403
|
if (!statements.length) return 0;
|
|
427
|
-
for (const warning of result.warnings) log(warning);
|
|
404
|
+
for (const warning of result.warnings) console.log(warning);
|
|
428
405
|
if (result.hasDataLoss && !force) throw new Error(`Brick: pushing ${entry.name} would lose data (see above). Rerun with --force to apply it, or use \`brick db generate\` and edit the migration.`);
|
|
429
406
|
if (postgres) await db.transaction(async (tx) => {
|
|
430
407
|
for (const statement of statements) await tx.execute(sql.raw(statement));
|
|
@@ -447,15 +424,15 @@ function onlyTables(db, names) {
|
|
|
447
424
|
};
|
|
448
425
|
}
|
|
449
426
|
// src/bin.ts
|
|
450
|
-
const CLI_VERSION =
|
|
451
|
-
const PORT_HELP =
|
|
427
|
+
const CLI_VERSION = version;
|
|
428
|
+
const PORT_HELP = `Port to listen on (CLI --port overrides PORT env, default ${DEFAULT_PORT})`;
|
|
452
429
|
const EXTENSION_HELP = "Dashboard extension module (default export defineDashboard(...)), or the dashboard folder brick build wrote";
|
|
453
430
|
const PORT_RESOLUTION_HELP = `
|
|
454
431
|
Port Resolution (dev/start commands):
|
|
455
432
|
- CLI --port flag takes precedence
|
|
456
433
|
- Falls back to PORT environment variable
|
|
457
434
|
- Then dev.port in brick.config.ts (brick dev only)
|
|
458
|
-
- Defaults to
|
|
435
|
+
- Defaults to ${DEFAULT_PORT} if none is set
|
|
459
436
|
- Valid range: 1-65535
|
|
460
437
|
|
|
461
438
|
Examples:
|
|
@@ -467,7 +444,7 @@ Examples:
|
|
|
467
444
|
const CONFIG_HELP = "Path to brick.config.ts (default: the nearest one in this folder or its parents)";
|
|
468
445
|
function parsePortOption(value) {
|
|
469
446
|
try {
|
|
470
|
-
return
|
|
447
|
+
return resolvePort(value);
|
|
471
448
|
} catch (err) {
|
|
472
449
|
throw new InvalidArgumentError(err.message);
|
|
473
450
|
}
|
|
@@ -481,13 +458,16 @@ function parseFileOption(value, usage) {
|
|
|
481
458
|
if (value.startsWith("-")) throw new InvalidArgumentError(`${usage} (got flag-like value '${value}')`);
|
|
482
459
|
return value;
|
|
483
460
|
}
|
|
484
|
-
/**
|
|
485
|
-
function
|
|
486
|
-
return command.optsWithGlobals().config;
|
|
461
|
+
/** The project of the program-level `--config`, else the nearest config file. */
|
|
462
|
+
function projectOf(command) {
|
|
463
|
+
return resolveProject(command.optsWithGlobals().config);
|
|
464
|
+
}
|
|
465
|
+
function entryOf(entry, project) {
|
|
466
|
+
return entry ?? (project.file ? project.entry : void 0);
|
|
487
467
|
}
|
|
488
|
-
/**
|
|
468
|
+
/** Without an entry argument or config entry, commander's usual error. */
|
|
489
469
|
function requireEntry(command, entry, project) {
|
|
490
|
-
const resolved = entry
|
|
470
|
+
const resolved = entryOf(entry, project);
|
|
491
471
|
if (!resolved) command.error("error: missing required argument 'entry'", {
|
|
492
472
|
exitCode: 1,
|
|
493
473
|
code: "commander.missingArgument"
|
|
@@ -496,16 +476,15 @@ function requireEntry(command, entry, project) {
|
|
|
496
476
|
}
|
|
497
477
|
/** Load the app after refreshing the services manifest it imports. */
|
|
498
478
|
async function loadProjectApp(entry, project) {
|
|
499
|
-
if (project) await writeServiceManifest(project);
|
|
479
|
+
if (project.file) await writeServiceManifest(project);
|
|
500
480
|
return loadBrickApp(entry);
|
|
501
481
|
}
|
|
502
|
-
/** A config path, made absolute from the config file's folder. */
|
|
503
482
|
function fromRoot(project, path) {
|
|
504
|
-
return path &&
|
|
483
|
+
return path && resolve(project.root, path);
|
|
505
484
|
}
|
|
506
485
|
/** The config's dashboard settings; a `--dashboard-extension` flag replaces its extension. */
|
|
507
486
|
function configDashboard(project, extensionFlag) {
|
|
508
|
-
const dashboard = project
|
|
487
|
+
const dashboard = project.config.dashboard;
|
|
509
488
|
if (!dashboard && !extensionFlag) return void 0;
|
|
510
489
|
return {
|
|
511
490
|
extension: extensionFlag ?? fromRoot(project, dashboard?.extension),
|
|
@@ -514,81 +493,55 @@ function configDashboard(project, extensionFlag) {
|
|
|
514
493
|
}
|
|
515
494
|
async function writeOpenApi(entry, output, project) {
|
|
516
495
|
const app = await loadProjectApp(entry, project);
|
|
517
|
-
const
|
|
518
|
-
services: [...app.definition.services],
|
|
519
|
-
prefix: app.definition.prefix
|
|
520
|
-
});
|
|
521
|
-
const json = JSON.stringify(spec, null, 2);
|
|
496
|
+
const json = JSON.stringify(app.openApiDocument(), null, 2);
|
|
522
497
|
if (output) await Bun.write(output, json);
|
|
523
498
|
return json;
|
|
524
499
|
}
|
|
525
500
|
function createProgram() {
|
|
526
501
|
const program = new Command();
|
|
527
|
-
program.name("brick").description("🧱 Brick-TS CLI").version(CLI_VERSION).showHelpAfterError().addHelpText("after", `
|
|
528
|
-
|
|
529
|
-
brick dev [entry] [--port <number>] [--dashboard-port <number>] [--history-days <number>] [--no-dashboard] Start development server with live reload and dashboard
|
|
530
|
-
brick start [entry] [--port <number>] Start production server
|
|
531
|
-
brick worker <entry> Deliver events without serving HTTP
|
|
532
|
-
brick build <app.ts> [--outdir <dir>] [--port <number>] [--no-aot] Compile a default-exported BrickApp into a Bun server
|
|
533
|
-
brick gen openapi <entry> [--output <file>] Generate OpenAPI 3.1 JSON specification
|
|
534
|
-
brick gen client <entry> [--output <file>] Generate a typed browser client contract
|
|
535
|
-
brick gen manifest Write <generated>/services.gen.ts
|
|
536
|
-
brick db generate [entry] [--out <dir>] [--name <name>] Write a SQL migration for the schema changes
|
|
537
|
-
brick db migrate [entry] [--out <dir>] Apply the migrations that have not run yet
|
|
538
|
-
brick db push [entry] [--force] Change the database to match the schema (development)
|
|
539
|
-
brick lint [entry] Check the project against the Brick lint rules
|
|
540
|
-
brick info <entry> Export architecture JSON schema
|
|
541
|
-
|
|
542
|
-
With a brick.config.ts, the entry and most flags come from the config file,
|
|
543
|
-
and every command takes --config <path>.
|
|
502
|
+
program.name("brick").description("🧱 Brick-TS CLI").version(CLI_VERSION).showHelpAfterError().configureHelp({ showGlobalOptions: true }).option("--config <path>", CONFIG_HELP).addHelpText("after", `
|
|
503
|
+
With a brick.config.ts, the entry and most flags come from the config file.
|
|
544
504
|
${PORT_RESOLUTION_HELP}`);
|
|
545
|
-
program.command("dev").description("Start development server with live reload").option("--client <file>", "Generate and watch a browser contract before startup").option("--frontend <command>", "Start frontend after contract generation; requires --client").option("--dashboard-port <number>", `Port for the local dashboard (default ${DEFAULT_DASHBOARD_PORT})`, parsePortOption).option("--history-days <number>", `Days of requests the dashboard keeps on disk, 0 for none (default 90)`, parseHistoryDays).option("--no-dashboard", "Do not start the local dashboard").option("--dashboard-extension <file>", EXTENSION_HELP).argument("[entry]", "Application entry file").option("--port <number>", PORT_HELP, parsePortOption).
|
|
546
|
-
const project = await
|
|
547
|
-
const config = project
|
|
548
|
-
const entry = entryArg
|
|
549
|
-
const port =
|
|
550
|
-
|
|
551
|
-
if (opts.dashboard === false && opts.historyDays !== void 0) throw new Error("Brick: --history-days cannot be combined with --no-dashboard.");
|
|
552
|
-
const configured = config?.dev?.dashboard;
|
|
553
|
-
const dashboardOff = opts.dashboard === false || configured === false && opts.dashboardPort === void 0 && opts.historyDays === void 0;
|
|
554
|
-
const dashboardConfig = configured || void 0;
|
|
555
|
-
if (dashboardOff && opts.dashboardExtension) throw new Error("Brick: --dashboard-extension cannot be combined with --no-dashboard.");
|
|
505
|
+
program.command("dev").description("Start development server with live reload").option("--client <file>", "Generate and watch a browser contract before startup").option("--frontend <command>", "Start frontend after contract generation; requires --client").option("--dashboard-port <number>", `Port for the local dashboard (default ${DEFAULT_DASHBOARD_PORT})`, parsePortOption).option("--history-days <number>", `Days of requests the dashboard keeps on disk, 0 for none (default 90)`, parseHistoryDays).option("--no-dashboard", "Do not start the local dashboard").option("--dashboard-extension <file>", EXTENSION_HELP).argument("[entry]", "Application entry file").option("--port <number>", PORT_HELP, parsePortOption).addHelpText("after", PORT_RESOLUTION_HELP).action(async (entryArg, opts, command) => {
|
|
506
|
+
const project = await projectOf(command);
|
|
507
|
+
const { config } = project;
|
|
508
|
+
const entry = entryOf(entryArg, project);
|
|
509
|
+
const port = resolvePort(opts.port, config.dev?.port);
|
|
510
|
+
const dashboard = resolveDevDashboard(config.dev?.dashboard, opts);
|
|
556
511
|
await startDevServer({
|
|
557
512
|
entry,
|
|
558
513
|
port,
|
|
559
|
-
clientOutput: opts.client ?? fromRoot(project, config
|
|
560
|
-
frontend: opts.frontend ?? config
|
|
561
|
-
dashboard: entry &&
|
|
562
|
-
|
|
563
|
-
historyDays: opts.historyDays ?? dashboardConfig?.historyDays,
|
|
514
|
+
clientOutput: opts.client ?? fromRoot(project, config.client?.output),
|
|
515
|
+
frontend: opts.frontend ?? config.dev?.frontend,
|
|
516
|
+
dashboard: entry && dashboard ? {
|
|
517
|
+
...dashboard,
|
|
564
518
|
...configDashboard(project, opts.dashboardExtension)
|
|
565
519
|
} : false,
|
|
566
|
-
manifest: project
|
|
520
|
+
manifest: project.file ? project : void 0
|
|
567
521
|
});
|
|
568
522
|
});
|
|
569
|
-
program.command("start").description("Start production server").argument("[entry]", "Application entry file").option("--port <number>", PORT_HELP, parsePortOption).option("--dashboard-extension <file>", EXTENSION_HELP).
|
|
570
|
-
const project = await
|
|
571
|
-
const port = resolveDevPort(opts.port);
|
|
523
|
+
program.command("start").description("Start production server").argument("[entry]", "Application entry file").option("--port <number>", PORT_HELP, parsePortOption).option("--dashboard-extension <file>", EXTENSION_HELP).addHelpText("after", PORT_RESOLUTION_HELP).action(async (entry, opts, command) => {
|
|
524
|
+
const project = await projectOf(command);
|
|
572
525
|
await startProdServer({
|
|
573
|
-
entry: entry
|
|
574
|
-
port,
|
|
526
|
+
entry: entryOf(entry, project),
|
|
527
|
+
port: resolvePort(opts.port),
|
|
575
528
|
dashboard: configDashboard(project, opts.dashboardExtension)
|
|
576
529
|
});
|
|
577
530
|
});
|
|
578
|
-
program.command("worker").description("Deliver the app's events without serving HTTP").argument("[entry]", "Application entry file (must default-export a BrickApp)").
|
|
579
|
-
const project = await
|
|
531
|
+
program.command("worker").description("Deliver the app's events without serving HTTP").argument("[entry]", "Application entry file (must default-export a BrickApp)").action(async (entry, _opts, command) => {
|
|
532
|
+
const project = await projectOf(command);
|
|
580
533
|
await startWorker({ entry: requireEntry(command, entry, project) });
|
|
581
534
|
});
|
|
582
|
-
program.command("build").description("Compile a default-exported BrickApp into a Bun server").argument("[entry]", "Application entry file (must default-export a BrickApp)").option("--
|
|
583
|
-
if (opts.prefix !== void 0 || opts.requestLogging === false) throw new
|
|
584
|
-
const project = await
|
|
585
|
-
const build = project
|
|
586
|
-
if (build?.requestLogging === false) throw new
|
|
535
|
+
program.command("build").description("Compile a default-exported BrickApp into a Bun server").argument("[entry]", "Application entry file (must default-export a BrickApp)").option("--outdir <dir>", "Output directory", (v) => parseFileOption(v, "Usage: brick build <app.ts> [--outdir <directory>]")).option("--port <number>", "Default listening port", parsePortOption).option("--no-aot", "Disable ahead-of-time compilation").option("--dashboard-extension <file>", "Dashboard extension module to build into <outdir>/dashboard").option("--prefix <path>", "DEPRECATED: configure prefix in brick() app instead").option("--no-request-logging", "DEPRECATED: configure requestLogging in brick() app instead").action(async (entryArg, opts, command) => {
|
|
536
|
+
if (opts.prefix !== void 0 || opts.requestLogging === false) throw new ConfigError("Brick: configure prefix and requestLogging in your default-exported brick() app instead of build flags.");
|
|
537
|
+
const project = await projectOf(command);
|
|
538
|
+
const build = project.config.build;
|
|
539
|
+
if (build?.requestLogging === false) throw new ConfigError("Brick: configure requestLogging in your default-exported brick() app instead of build.requestLogging.");
|
|
587
540
|
const entry = requireEntry(command, entryArg, project);
|
|
588
|
-
if (project) await writeServiceManifest(project);
|
|
541
|
+
if (project.file) await writeServiceManifest(project);
|
|
589
542
|
const result = await buildApplication({
|
|
590
543
|
entry,
|
|
591
|
-
outdir: opts.outdir ??
|
|
544
|
+
outdir: opts.outdir ?? project.outdir,
|
|
592
545
|
port: opts.port,
|
|
593
546
|
aot: opts.aot === false ? false : build?.aot,
|
|
594
547
|
dashboard: configDashboard(project, opts.dashboardExtension)
|
|
@@ -599,18 +552,17 @@ ${PORT_RESOLUTION_HELP}`);
|
|
|
599
552
|
if (result.dashboard) console.log(`Dashboard extension: ${result.dashboard}`);
|
|
600
553
|
console.log(`Run: bun ${result.entry}`);
|
|
601
554
|
});
|
|
602
|
-
const gen = program.command("gen").description("Generate artifacts from a BrickApp entry").argument("[subcommand]", "Generator to run (openapi, client, manifest)").
|
|
603
|
-
const project =
|
|
604
|
-
if (!project) {
|
|
555
|
+
const gen = program.command("gen").description("Generate artifacts from a BrickApp entry").argument("[subcommand]", "Generator to run (openapi, client, manifest)").action(async (subcommand, _opts, command) => {
|
|
556
|
+
const project = await projectOf(command);
|
|
557
|
+
if (subcommand !== void 0 || !project.file) {
|
|
605
558
|
console.error(`Unknown generator: ${subcommand ?? "(none)"}. Available: openapi, client, manifest`);
|
|
606
559
|
process.exit(1);
|
|
607
560
|
}
|
|
608
561
|
const manifest = await writeServiceManifest(project);
|
|
609
562
|
console.log(`Services manifest written to ${manifest}`);
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
console.log(`Client contract written to ${client}`);
|
|
563
|
+
if (project.config.client?.output) {
|
|
564
|
+
await writeClientContract(project.entry, project.contract);
|
|
565
|
+
console.log(`Client contract written to ${project.contract}`);
|
|
614
566
|
}
|
|
615
567
|
const openapi = fromRoot(project, project.config.openapi?.output);
|
|
616
568
|
if (openapi) {
|
|
@@ -618,33 +570,29 @@ ${PORT_RESOLUTION_HELP}`);
|
|
|
618
570
|
console.log(`✅ OpenAPI 3.1 specification written to ${openapi}`);
|
|
619
571
|
}
|
|
620
572
|
});
|
|
621
|
-
gen.command("openapi").description("Generate OpenAPI 3.1 JSON specification").argument("[entry]", "Application entry file").option("--
|
|
622
|
-
const project = await
|
|
623
|
-
const output = opts.output ?? fromRoot(project, project
|
|
573
|
+
gen.command("openapi").description("Generate OpenAPI 3.1 JSON specification").argument("[entry]", "Application entry file").option("--output <file>", "Write specification to file instead of stdout", (v) => parseFileOption(v, "Usage: brick gen openapi <entry> [--output <file>]")).action(async (entry, opts, command) => {
|
|
574
|
+
const project = await projectOf(command);
|
|
575
|
+
const output = opts.output ?? fromRoot(project, project.config.openapi?.output);
|
|
624
576
|
const json = await writeOpenApi(requireEntry(command, entry, project), output, project);
|
|
625
577
|
if (output) console.log(`✅ OpenAPI 3.1 specification written to ${output}`);
|
|
626
578
|
else console.log(json);
|
|
627
579
|
});
|
|
628
|
-
gen.command("client").description("Generate a typed browser client contract").argument("[entry]", "Application entry file").option("--
|
|
629
|
-
const project = await
|
|
580
|
+
gen.command("client").description("Generate a typed browser client contract").argument("[entry]", "Application entry file").option("--output <file>", "Write contract to file (default _brick/contract.ts)", (v) => parseFileOption(v, "Usage: brick gen client <entry> [--output <file>]")).action(async (entry, opts, command) => {
|
|
581
|
+
const project = await projectOf(command);
|
|
630
582
|
const target = requireEntry(command, entry, project);
|
|
631
|
-
if (project) await writeServiceManifest(project);
|
|
632
|
-
const output = await writeClientContract(target, opts.output ??
|
|
583
|
+
if (project.file) await writeServiceManifest(project);
|
|
584
|
+
const output = await writeClientContract(target, opts.output ?? project.contract);
|
|
633
585
|
console.log(`Client contract written to ${output}`);
|
|
634
586
|
});
|
|
635
|
-
gen.command("manifest").description("Write <generated>/services.gen.ts, which imports every definition file").
|
|
636
|
-
const
|
|
637
|
-
const output = await writeServiceManifest(project ?? {
|
|
638
|
-
services: resolve("src/services"),
|
|
639
|
-
generated: resolve("_brick")
|
|
640
|
-
});
|
|
587
|
+
gen.command("manifest").description("Write <generated>/services.gen.ts, which imports every definition file").action(async (_opts, command) => {
|
|
588
|
+
const output = await writeServiceManifest(await projectOf(command));
|
|
641
589
|
console.log(`Services manifest written to ${output}`);
|
|
642
590
|
});
|
|
643
591
|
const db = program.command("db").description("Manage the app's database schema with drizzle-kit: generate, migrate, push");
|
|
644
|
-
const dbCommand = (name, description) => db.command(name).description(description).argument("[entry]", "Application entry file")
|
|
592
|
+
const dbCommand = (name, description) => db.command(name).description(description).argument("[entry]", "Application entry file");
|
|
645
593
|
const OUT_HELP = "Migrations folder (default drizzle, beside brick.config.ts); each database gets a subfolder named after it";
|
|
646
594
|
const dbAction = (name) => async (entry, opts, command) => {
|
|
647
|
-
const project = await
|
|
595
|
+
const project = await projectOf(command);
|
|
648
596
|
await runDbCommand(name, await loadProjectApp(requireEntry(command, entry, project), project), {
|
|
649
597
|
out: opts.out ?? fromRoot(project, "drizzle"),
|
|
650
598
|
name: opts.name,
|
|
@@ -654,15 +602,15 @@ ${PORT_RESOLUTION_HELP}`);
|
|
|
654
602
|
dbCommand("generate", "Write a SQL migration for the schema changes since the last one").option("--out <dir>", OUT_HELP).option("--name <name>", "Migration name (default migration)").action(dbAction("generate"));
|
|
655
603
|
dbCommand("migrate", "Apply the migrations that have not run yet").option("--out <dir>", OUT_HELP).action(dbAction("migrate"));
|
|
656
604
|
dbCommand("push", "Change the database to match the schema directly, without migration files (development)").option("--force", "Apply changes that drop data").action(dbAction("push"));
|
|
657
|
-
program.command("lint").description("Check the project against the Brick lint rules").argument("[entry]", "Application entry file").
|
|
605
|
+
program.command("lint").description("Check the project against the Brick lint rules").argument("[entry]", "Application entry file").action(async (entry, _opts, command) => {
|
|
658
606
|
const code = await runLint({
|
|
659
607
|
entry,
|
|
660
|
-
project: await
|
|
608
|
+
project: await projectOf(command)
|
|
661
609
|
});
|
|
662
610
|
if (code !== 0) process.exit(code);
|
|
663
611
|
});
|
|
664
|
-
program.command("info").alias("services").description("Export architecture JSON schema").argument("[entry]", "Application entry file").
|
|
665
|
-
const project = await
|
|
612
|
+
program.command("info").alias("services").description("Export architecture JSON schema").argument("[entry]", "Application entry file").action(async (entry, _opts, command) => {
|
|
613
|
+
const project = await projectOf(command);
|
|
666
614
|
const app = await loadProjectApp(requireEntry(command, entry, project), project);
|
|
667
615
|
const architecture = getGlobalRegistry().exportArchitecture(app.definition);
|
|
668
616
|
console.log(JSON.stringify(architecture, null, 2));
|
|
@@ -670,18 +618,7 @@ ${PORT_RESOLUTION_HELP}`);
|
|
|
670
618
|
return program;
|
|
671
619
|
}
|
|
672
620
|
async function main() {
|
|
673
|
-
|
|
674
|
-
const userArgs = process.argv.slice(2);
|
|
675
|
-
if (userArgs.length === 0 && await loadConfig()) {
|
|
676
|
-
await program.parseAsync([...process.argv, "dev"]);
|
|
677
|
-
return;
|
|
678
|
-
}
|
|
679
|
-
if (userArgs.length === 0) {
|
|
680
|
-
const port = parsePort(void 0, process.env.PORT);
|
|
681
|
-
await startDevServer({ port });
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
await program.parseAsync(process.argv);
|
|
621
|
+
await createProgram().parseAsync(process.argv.length > 2 ? process.argv : [...process.argv, "dev"]);
|
|
685
622
|
}
|
|
686
623
|
main().catch((err) => {
|
|
687
624
|
if (err?.exitCode !== void 0) process.exit(err.exitCode);
|