@brickkit/cli 0.2.1 ā 0.2.2
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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/bin.js +39 -1
- package/dist/bin.js.map +1 -1
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chandraprakash-Darji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ The `brick` binary ships in this package for local dev and inspection:
|
|
|
32
32
|
```sh
|
|
33
33
|
brick dev --port 4000
|
|
34
34
|
brick gen openapi --output openapi.json
|
|
35
|
+
brick gen client src/app.ts
|
|
35
36
|
brick info
|
|
36
37
|
```
|
|
37
38
|
|
|
@@ -130,3 +131,32 @@ schema references and non-JSON transport types fail generation explicitly.
|
|
|
130
131
|
This integration requires Vite 8; the normal server entry point has no Vite
|
|
131
132
|
runtime dependency. `generateClientContract(app)` exposes the source generator
|
|
132
133
|
for non-Vite tooling.
|
|
134
|
+
|
|
135
|
+
## Generate a typed client without Vite
|
|
136
|
+
|
|
137
|
+
Use the standalone Bun CLI with any module whose default export is a `BrickApp`:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
brick gen client src/app.ts
|
|
141
|
+
brick gen client src/app.ts --output frontend/src/contract.ts
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The default output is `_brick/contract.ts`, relative to the working directory.
|
|
145
|
+
The app's selected services and prefix determine its contents, just as with the
|
|
146
|
+
Vite plugin. The command evaluates the entry without calling `.listen()`; keep
|
|
147
|
+
the listener in a separate server bootstrap. Vite is not required or loaded.
|
|
148
|
+
|
|
149
|
+
Run generation before your frontend's development server, build, and type check,
|
|
150
|
+
and rerun after changing backend definitions. You can add a package script:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"scripts": {
|
|
155
|
+
"gen:client": "brick gen client src/app.ts"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Import the generated `contract` with `createBrickClient({ baseUrl, contract })`
|
|
161
|
+
as shown above. The command creates parent directories and leaves an unchanged
|
|
162
|
+
contract file untouched. Add the generated output to `.gitignore`.
|
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { n as startDevServer, t as buildApplication } from "./build.js";
|
|
3
|
+
import { t as generateClientContract } from "./client-contract.js";
|
|
3
4
|
import { generateOpenApiSpec, getGlobalRegistry } from "@brickkit/core";
|
|
5
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
//#region src/client-contract-file.ts
|
|
10
|
+
/** Generate a client contract without loading Vite or starting a server. */
|
|
11
|
+
async function writeClientContract(entryPath, outputPath) {
|
|
12
|
+
const entry = resolve(entryPath);
|
|
13
|
+
const output = resolve(outputPath ?? "_brick/contract.ts");
|
|
14
|
+
if (entry === output) throw new Error("Brick: contract output must not overwrite the app entry.");
|
|
15
|
+
const { default: app } = await import(pathToFileURL(entry).href);
|
|
16
|
+
if (!app || typeof app.endpoint !== "function" || !app.definition) throw new Error("Brick: the entry module must default-export a BrickApp created by brick().");
|
|
17
|
+
const source = generateClientContract(app);
|
|
18
|
+
if (await readFile(output, "utf8").catch((error) => {
|
|
19
|
+
if (error.code !== "ENOENT") throw error;
|
|
20
|
+
}) !== source) {
|
|
21
|
+
await mkdir(dirname(output), { recursive: true });
|
|
22
|
+
const temporary = join(dirname(output), `.brick-contract-${randomUUID()}.tmp`);
|
|
23
|
+
try {
|
|
24
|
+
await writeFile(temporary, source, { flag: "wx" });
|
|
25
|
+
await rename(temporary, output);
|
|
26
|
+
} finally {
|
|
27
|
+
await rm(temporary, { force: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
4
33
|
//#region src/bin.ts
|
|
5
34
|
const args = process.argv.slice(2);
|
|
6
35
|
const command = args[0] || "dev";
|
|
@@ -42,6 +71,14 @@ async function main() {
|
|
|
42
71
|
}
|
|
43
72
|
case "gen": {
|
|
44
73
|
const subCommand = args[1];
|
|
74
|
+
if (subCommand === "client") {
|
|
75
|
+
const entry = args[2];
|
|
76
|
+
if (!entry || entry.startsWith("-")) throw new Error("Usage: brick gen client <entry> [--output <file>]");
|
|
77
|
+
if (args.length > 3 && (args[3] !== "--output" || !args[4] || args[4].startsWith("-") || args.length > 5)) throw new Error("Usage: brick gen client <entry> [--output <file>]");
|
|
78
|
+
const output = await writeClientContract(entry, args[4]);
|
|
79
|
+
console.log(`Client contract written to ${output}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
45
82
|
if (subCommand === "openapi") {
|
|
46
83
|
const outIdx = args.indexOf("--output");
|
|
47
84
|
const outputFile = outIdx !== -1 ? args[outIdx + 1] : void 0;
|
|
@@ -53,7 +90,7 @@ async function main() {
|
|
|
53
90
|
} else console.log(jsonOutput);
|
|
54
91
|
break;
|
|
55
92
|
}
|
|
56
|
-
console.error(`Unknown generator: ${subCommand}. Available: openapi`);
|
|
93
|
+
console.error(`Unknown generator: ${subCommand}. Available: openapi, client`);
|
|
57
94
|
process.exit(1);
|
|
58
95
|
break;
|
|
59
96
|
}
|
|
@@ -72,6 +109,7 @@ Usage:
|
|
|
72
109
|
brick start [entry] Start production server
|
|
73
110
|
brick build <entry> [--outdir <dir>] Compile definitions into a Bun server
|
|
74
111
|
brick gen openapi [--output <file>] Generate OpenAPI 3.1 JSON specification
|
|
112
|
+
brick gen client <entry> [--output <file>] Generate a typed browser client contract
|
|
75
113
|
brick info Export architecture JSON schema
|
|
76
114
|
`);
|
|
77
115
|
process.exit(0);
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env bun\nimport { startDevServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { getGlobalRegistry, generateOpenApiSpec } from \"@brickkit/core\";\n\nconst args = process.argv.slice(2);\nconst command = args[0] || \"dev\";\n\nasync function main() {\n switch (command) {\n case \"dev\":\n case \"start\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n const portArgIdx = args.indexOf(\"--port\");\n const port = portArgIdx !== -1 ? Number(args[portArgIdx + 1]) : 4000;\n\n await startDevServer({ entry, port });\n break;\n }\n\n case \"build\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n if (!entry)\n throw new Error(\n \"Usage: brick build <definitions.ts> [--outdir <directory>] [--prefix <path>] [--port <number>]\",\n );\n const value = (flag: string) => {\n const index = args.indexOf(flag);\n if (index === -1) return undefined;\n if (!args[index + 1] || args[index + 1]!.startsWith(\"--\"))\n throw new Error(`Missing value for ${flag}`);\n return args[index + 1];\n };\n const port = value(\"--port\");\n const result = await buildApplication({\n entry,\n outdir: value(\"--outdir\"),\n prefix: value(\"--prefix\"),\n port: port === undefined ? undefined : Number(port),\n requestLogging: !args.includes(\"--no-request-logging\"),\n });\n for (const warning of result.ir.diagnostics)\n console.warn(`[Brick compiler] ${warning}`);\n console.log(\n `Compiled ${result.ir.services.length} services / ${result.ir.routes.length} routes`,\n );\n console.log(`IR: ${result.outdir}/brick-ir.json`);\n console.log(`Run: bun ${result.entry}`);\n break;\n }\n\n case \"gen\": {\n const subCommand = args[1];\n if (subCommand === \"openapi\") {\n const outIdx = args.indexOf(\"--output\");\n const outputFile = outIdx !== -1 ? args[outIdx + 1] : undefined;\n\n const spec = generateOpenApiSpec();\n const jsonOutput = JSON.stringify(spec, null, 2);\n\n if (outputFile) {\n await Bun.write(outputFile, jsonOutput);\n console.log(`ā
OpenAPI 3.1 specification written to ${outputFile}`);\n } else {\n console.log(jsonOutput);\n }\n break;\n }\n console.error(`Unknown generator: ${subCommand}. Available: openapi
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/client-contract-file.ts","../src/bin.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { generateClientContract } from \"./client-contract\";\nimport type { BrickApp } from \"./endpoints\";\n\n/** Generate a client contract without loading Vite or starting a server. */\nexport async function writeClientContract(\n entryPath: string,\n outputPath?: string,\n) {\n const entry = resolve(entryPath);\n const output = resolve(outputPath ?? \"_brick/contract.ts\");\n if (entry === output)\n throw new Error(\"Brick: contract output must not overwrite the app entry.\");\n const { default: app } = await import(pathToFileURL(entry).href);\n if (!app || typeof app.endpoint !== \"function\" || !app.definition)\n throw new Error(\n \"Brick: the entry module must default-export a BrickApp created by brick().\",\n );\n const source = generateClientContract(app as BrickApp);\n const previous = await readFile(output, \"utf8\").catch((error) => {\n if (error.code !== \"ENOENT\") throw error;\n return undefined;\n });\n if (previous !== source) {\n await mkdir(dirname(output), { recursive: true });\n const temporary = join(\n dirname(output),\n `.brick-contract-${randomUUID()}.tmp`,\n );\n try {\n await writeFile(temporary, source, { flag: \"wx\" });\n await rename(temporary, output);\n } finally {\n await rm(temporary, { force: true });\n }\n }\n return output;\n}\n","#!/usr/bin/env bun\nimport { startDevServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { writeClientContract } from \"./client-contract-file\";\nimport { getGlobalRegistry, generateOpenApiSpec } from \"@brickkit/core\";\n\nconst args = process.argv.slice(2);\nconst command = args[0] || \"dev\";\n\nasync function main() {\n switch (command) {\n case \"dev\":\n case \"start\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n const portArgIdx = args.indexOf(\"--port\");\n const port = portArgIdx !== -1 ? Number(args[portArgIdx + 1]) : 4000;\n\n await startDevServer({ entry, port });\n break;\n }\n\n case \"build\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n if (!entry)\n throw new Error(\n \"Usage: brick build <definitions.ts> [--outdir <directory>] [--prefix <path>] [--port <number>]\",\n );\n const value = (flag: string) => {\n const index = args.indexOf(flag);\n if (index === -1) return undefined;\n if (!args[index + 1] || args[index + 1]!.startsWith(\"--\"))\n throw new Error(`Missing value for ${flag}`);\n return args[index + 1];\n };\n const port = value(\"--port\");\n const result = await buildApplication({\n entry,\n outdir: value(\"--outdir\"),\n prefix: value(\"--prefix\"),\n port: port === undefined ? undefined : Number(port),\n requestLogging: !args.includes(\"--no-request-logging\"),\n });\n for (const warning of result.ir.diagnostics)\n console.warn(`[Brick compiler] ${warning}`);\n console.log(\n `Compiled ${result.ir.services.length} services / ${result.ir.routes.length} routes`,\n );\n console.log(`IR: ${result.outdir}/brick-ir.json`);\n console.log(`Run: bun ${result.entry}`);\n break;\n }\n\n case \"gen\": {\n const subCommand = args[1];\n if (subCommand === \"client\") {\n const entry = args[2];\n if (!entry || entry.startsWith(\"-\"))\n throw new Error(\"Usage: brick gen client <entry> [--output <file>]\");\n if (\n args.length > 3 &&\n (args[3] !== \"--output\" ||\n !args[4] ||\n args[4].startsWith(\"-\") ||\n args.length > 5)\n )\n throw new Error(\"Usage: brick gen client <entry> [--output <file>]\");\n const output = await writeClientContract(entry, args[4]);\n console.log(`Client contract written to ${output}`);\n break;\n }\n if (subCommand === \"openapi\") {\n const outIdx = args.indexOf(\"--output\");\n const outputFile = outIdx !== -1 ? args[outIdx + 1] : undefined;\n\n const spec = generateOpenApiSpec();\n const jsonOutput = JSON.stringify(spec, null, 2);\n\n if (outputFile) {\n await Bun.write(outputFile, jsonOutput);\n console.log(`ā
OpenAPI 3.1 specification written to ${outputFile}`);\n } else {\n console.log(jsonOutput);\n }\n break;\n }\n console.error(\n `Unknown generator: ${subCommand}. Available: openapi, client`,\n );\n process.exit(1);\n break;\n }\n\n case \"info\":\n case \"services\": {\n const registry = getGlobalRegistry();\n console.log(JSON.stringify(registry.exportArchitecture(), null, 2));\n break;\n }\n\n default:\n console.log(`\nš§± Brick-TS CLI\n\nUsage:\n brick dev [entry] [--port <number>] Start development server with live reload\n brick start [entry] Start production server\n brick build <entry> [--outdir <dir>] Compile definitions into a Bun server\n brick gen openapi [--output <file>] Generate OpenAPI 3.1 JSON specification\n brick gen client <entry> [--output <file>] Generate a typed browser client contract\n brick info Export architecture JSON schema\n`);\n process.exit(0);\n }\n}\n\nmain().catch((err) => {\n console.error(\"Fatal error:\", err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;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e,WAAW;IAC5B,MAAM,SAAS,KAAK,QAAQ,UAAU;IACtC,MAAM,aAAa,WAAW,KAAK,KAAK,SAAS,KAAK,KAAA;IAEtD,MAAM,OAAO,oBAAoB;IACjC,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,CAAC;IAE/C,IAAI,YAAY;KACd,MAAM,IAAI,MAAM,YAAY,UAAU;KACtC,QAAQ,IAAI,0CAA0C,YAAY;IACpE,OACE,QAAQ,IAAI,UAAU;IAExB;GACF;GACA,QAAQ,MACN,sBAAsB,WAAW,6BACnC;GACA,QAAQ,KAAK,CAAC;GACd;EACF;EAEA,KAAK;EACL,KAAK,YAAY;GACf,MAAM,WAAW,kBAAkB;GACnC,QAAQ,IAAI,KAAK,UAAU,SAAS,mBAAmB,GAAG,MAAM,CAAC,CAAC;GAClE;EACF;EAEA;GACE,QAAQ,IAAI;;;;;;;;;;CAUjB;GACK,QAAQ,KAAK,CAAC;CAClB;AACF;AAEA,KAAK,CAAC,CAAC,OAAO,QAAQ;CACpB,QAAQ,MAAM,gBAAgB,GAAG;CACjC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brickkit/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "CLI and server engine for Brick-TS",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
8
|
"module": "./dist/index.js",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"format:check": "oxfmt --check ."
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@brickkit/core": "^0.2.
|
|
52
|
+
"@brickkit/core": "^0.2.2",
|
|
52
53
|
"@sinclair/typebox": "^0.34.0",
|
|
53
54
|
"elysia": "^1.2.0"
|
|
54
55
|
},
|