@brickkit/cli 0.4.0 → 0.4.1

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/bin.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env bun
2
- import { i as startProdServer, n as loadBrickApp, r as startDevServer, t as buildApplication } from "./build.js";
2
+ import { n as startDevServer, r as startProdServer } from "./runner.js";
3
+ import { n as loadBrickApp, t as buildApplication } from "./build.js";
3
4
  import { t as generateClientContract } from "./client-contract.js";
5
+ import { t as parsePort } from "./port-utils.js";
4
6
  import { generateOpenApiSpec, getGlobalRegistry } from "@brickkit/core";
5
7
  import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
6
8
  import { dirname, join, resolve } from "node:path";
@@ -29,18 +31,8 @@ async function writeClientContract(entryPath, outputPath) {
29
31
  return output;
30
32
  }
31
33
  //#endregion
32
- //#region src/port-utils.ts
33
- function parsePort(portStr, envPort) {
34
- let port;
35
- if (portStr !== void 0) port = Number(portStr);
36
- else if (envPort !== void 0) port = Number(envPort);
37
- else port = 4e3;
38
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
39
- return port;
40
- }
41
- //#endregion
42
34
  //#region src/bin.ts
43
- const CLI_VERSION = "0.4.0";
35
+ const CLI_VERSION = "0.4.1";
44
36
  const PORT_HELP = "Port to listen on (CLI --port overrides PORT env, default 4000)";
45
37
  const PORT_RESOLUTION_HELP = `
46
38
  Port Resolution (dev/start commands):
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","names":["cliPkg.version"],"sources":["../src/client-contract-file.ts","../src/port-utils.ts","../package.json","../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 { generateClientContract } from \"./client-contract\";\nimport { loadBrickApp } from \"./app-entry\";\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 app = await loadBrickApp(entry);\n const source = generateClientContract(app);\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","export function parsePort(\n portStr: string | undefined,\n envPort?: string | undefined,\n): number {\n let port: number | undefined;\n if (portStr !== undefined) {\n port = Number(portStr);\n } else if (envPort !== undefined) {\n port = Number(envPort);\n } else {\n port = 4000;\n }\n\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n return port;\n}\n","","#!/usr/bin/env bun\nimport { Command, InvalidArgumentError } from \"commander\";\nimport { startDevServer, startProdServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { writeClientContract } from \"./client-contract-file\";\nimport { generateOpenApiSpec, getGlobalRegistry } from \"@brickkit/core\";\nimport { parsePort } from \"./port-utils\";\nimport { loadBrickApp } from \"./app-entry\";\nimport cliPkg from \"../package.json\";\n\n// Single source of truth for the CLI version (inlined at build time).\nconst CLI_VERSION: string = cliPkg.version;\n\nconst PORT_HELP =\n \"Port to listen on (CLI --port overrides PORT env, default 4000)\";\n\nconst PORT_RESOLUTION_HELP = `\nPort Resolution (dev/start commands):\n - CLI --port flag takes precedence\n - Falls back to PORT environment variable\n - Defaults to 4000 if neither is set\n - Valid range: 1-65535\n\nExamples:\n brick dev app.ts # port 4000 (default)\n brick dev app.ts --port 5000 # port 5000 (explicit)\n PORT=3000 brick dev app.ts # port 3000 (from env)\n brick dev app.ts --port 6000 # port 6000 (CLI overrides PORT=3000)\n`;\n\nfunction parsePortOption(value: string): number {\n try {\n return parsePort(value, undefined);\n } catch (err) {\n throw new InvalidArgumentError((err as Error).message);\n }\n}\n\nfunction parseFileOption(value: string, usage: string): string {\n if (value.startsWith(\"-\")) {\n throw new InvalidArgumentError(`${usage} (got flag-like value '${value}')`);\n }\n return value;\n}\n\nfunction resolveDevPort(cliPort: number | undefined): number {\n if (cliPort !== undefined) return cliPort;\n return parsePort(undefined, process.env.PORT);\n}\n\nexport function createProgram(): Command {\n const program = new Command();\n program\n .name(\"brick\")\n .description(\"🧱 Brick-TS CLI\")\n .version(CLI_VERSION)\n .showHelpAfterError()\n .addHelpText(\n \"after\",\n `\nUsage:\n brick dev [entry] [--port <number>] Start development server with live reload\n brick start [entry] [--port <number>] Start production server\n brick build <app.ts> [--outdir <dir>] [--port <number>] [--no-aot] Compile a default-exported BrickApp into a Bun server\n brick gen openapi <entry> [--output <file>] Generate OpenAPI 3.1 JSON specification\n brick gen client <entry> [--output <file>] Generate a typed browser client contract\n brick info <entry> Export architecture JSON schema\n${PORT_RESOLUTION_HELP}`,\n );\n\n program\n .command(\"dev\")\n .description(\"Start development server with live reload\")\n .argument(\"[entry]\", \"Application entry file\")\n .option(\"--port <number>\", PORT_HELP, parsePortOption)\n .addHelpText(\"after\", PORT_RESOLUTION_HELP)\n .action(async (entry: string | undefined, opts: { port?: number }) => {\n const port = resolveDevPort(opts.port);\n await startDevServer({ entry, port });\n });\n\n program\n .command(\"start\")\n .description(\"Start production server\")\n .argument(\"[entry]\", \"Application entry file\")\n .option(\"--port <number>\", PORT_HELP, parsePortOption)\n .addHelpText(\"after\", PORT_RESOLUTION_HELP)\n .action(async (entry: string | undefined, opts: { port?: number }) => {\n const port = resolveDevPort(opts.port);\n await startProdServer({ entry, port });\n });\n\n program\n .command(\"build\")\n .description(\"Compile a default-exported BrickApp into a Bun server\")\n .argument(\n \"<entry>\",\n \"Application entry file (must default-export a BrickApp)\",\n )\n .option(\"--outdir <dir>\", \"Output directory\", (v: string) =>\n parseFileOption(v, \"Usage: brick build <app.ts> [--outdir <directory>]\"),\n )\n .option(\"--port <number>\", \"Default listening port\", parsePortOption)\n .option(\"--no-aot\", \"Disable ahead-of-time compilation\")\n .option(\n \"--prefix <path>\",\n \"DEPRECATED: configure prefix in brick() app instead\",\n )\n .option(\n \"--no-request-logging\",\n \"DEPRECATED: configure requestLogging in brick() app instead\",\n )\n .action(\n async (\n entry: string,\n opts: {\n outdir?: string;\n port?: number;\n aot?: boolean;\n prefix?: string;\n requestLogging?: boolean;\n },\n ) => {\n if (opts.prefix !== undefined || opts.requestLogging === false) {\n throw new Error(\n \"Brick: configure prefix and requestLogging in your default-exported brick() app instead of build flags.\",\n );\n }\n const result = await buildApplication({\n entry,\n outdir: opts.outdir,\n port: opts.port,\n aot: opts.aot,\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 },\n );\n\n const gen = program\n .command(\"gen\")\n .description(\"Generate artifacts from a BrickApp entry\")\n .argument(\"[subcommand]\", \"Generator to run (openapi, client)\")\n .action((subcommand: string | undefined) => {\n console.error(\n `Unknown generator: ${subcommand ?? \"(none)\"}. Available: openapi, client`,\n );\n process.exit(1);\n });\n\n gen\n .command(\"openapi\")\n .description(\"Generate OpenAPI 3.1 JSON specification\")\n .argument(\"<entry>\", \"Application entry file\")\n .option(\n \"--output <file>\",\n \"Write specification to file instead of stdout\",\n (v: string) =>\n parseFileOption(\n v,\n \"Usage: brick gen openapi <entry> [--output <file>]\",\n ),\n )\n .action(async (entry: string, opts: { output?: string }) => {\n const app = await loadBrickApp(entry);\n const spec = generateOpenApiSpec({\n services: [...app.definition.services],\n prefix: app.definition.prefix,\n });\n const jsonOutput = JSON.stringify(spec, null, 2);\n if (opts.output) {\n await Bun.write(opts.output, jsonOutput);\n console.log(`✅ OpenAPI 3.1 specification written to ${opts.output}`);\n } else {\n console.log(jsonOutput);\n }\n });\n\n gen\n .command(\"client\")\n .description(\"Generate a typed browser client contract\")\n .argument(\"<entry>\", \"Application entry file\")\n .option(\n \"--output <file>\",\n \"Write contract to file (default _brick/contract.ts)\",\n (v: string) =>\n parseFileOption(v, \"Usage: brick gen client <entry> [--output <file>]\"),\n )\n .action(async (entry: string, opts: { output?: string }) => {\n const output = await writeClientContract(entry, opts.output);\n console.log(`Client contract written to ${output}`);\n });\n\n program\n .command(\"info\")\n .alias(\"services\")\n .description(\"Export architecture JSON schema\")\n .argument(\"<entry>\", \"Application entry file\")\n .action(async (entry: string) => {\n const app = await loadBrickApp(entry);\n const architecture = getGlobalRegistry().exportArchitecture(\n app.definition,\n );\n console.log(JSON.stringify(architecture, null, 2));\n });\n\n return program;\n}\n\nasync function main() {\n const program = createProgram();\n // Preserve legacy behavior: bare `brick` starts the dev server.\n const userArgs = process.argv.slice(2);\n if (userArgs.length === 0) {\n const port = parsePort(undefined, process.env.PORT);\n await startDevServer({ port });\n return;\n }\n await program.parseAsync(process.argv);\n}\n\nmain().catch((err) => {\n // Commander already prints validation errors (missing arg, unknown option,\n // invalid port) and exits. Only print Fatal error for action failures.\n if (err?.exitCode !== undefined) {\n process.exit(err.exitCode);\n }\n if (err?.code?.startsWith?.(\"commander.\")) {\n process.exit(1);\n }\n console.error(\"Fatal error:\", err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;AAOA,eAAsB,oBACpB,WACA,YACA;CACA,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,SAAS,QAAQ,cAAc,oBAAoB;CACzD,IAAI,UAAU,QACZ,MAAM,IAAI,MAAM,0DAA0D;CAC5E,MAAM,MAAM,MAAM,aAAa,KAAK;CACpC,MAAM,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,8BAA8B,QAAQ;CACpD,CAAC;CAEH,QACG,QAAQ,MAAM,CAAC,CACf,MAAM,UAAU,CAAC,CACjB,YAAY,iCAAiC,CAAC,CAC9C,SAAS,WAAW,wBAAwB,CAAC,CAC7C,OAAO,OAAO,UAAkB;EAC/B,MAAM,MAAM,MAAM,aAAa,KAAK;EACpC,MAAM,eAAe,kBAAkB,CAAC,CAAC,mBACvC,IAAI,UACN;EACA,QAAQ,IAAI,KAAK,UAAU,cAAc,MAAM,CAAC,CAAC;CACnD,CAAC;CAEH,OAAO;AACT;AAEA,eAAe,OAAO;CACpB,MAAM,UAAU,cAAc;CAG9B,IADiB,QAAQ,KAAK,MAAM,CACzB,CAAC,CAAC,WAAW,GAAG;EACzB,MAAM,OAAO,UAAU,KAAA,GAAW,QAAQ,IAAI,IAAI;EAClD,MAAM,eAAe,EAAE,KAAK,CAAC;EAC7B;CACF;CACA,MAAM,QAAQ,WAAW,QAAQ,IAAI;AACvC;AAEA,KAAK,CAAC,CAAC,OAAO,QAAQ;CAGpB,IAAI,KAAK,aAAa,KAAA,GACpB,QAAQ,KAAK,IAAI,QAAQ;CAE3B,IAAI,KAAK,MAAM,aAAa,YAAY,GACtC,QAAQ,KAAK,CAAC;CAEhB,QAAQ,MAAM,gBAAgB,GAAG;CACjC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"bin.js","names":["cliPkg.version"],"sources":["../src/client-contract-file.ts","../package.json","../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 { generateClientContract } from \"./client-contract\";\nimport { loadBrickApp } from \"./app-entry\";\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 app = await loadBrickApp(entry);\n const source = generateClientContract(app);\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 { Command, InvalidArgumentError } from \"commander\";\nimport { startDevServer, startProdServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { writeClientContract } from \"./client-contract-file\";\nimport { generateOpenApiSpec, getGlobalRegistry } from \"@brickkit/core\";\nimport { parsePort } from \"./port-utils\";\nimport { loadBrickApp } from \"./app-entry\";\nimport cliPkg from \"../package.json\";\n\n// Single source of truth for the CLI version (inlined at build time).\nconst CLI_VERSION: string = cliPkg.version;\n\nconst PORT_HELP =\n \"Port to listen on (CLI --port overrides PORT env, default 4000)\";\n\nconst PORT_RESOLUTION_HELP = `\nPort Resolution (dev/start commands):\n - CLI --port flag takes precedence\n - Falls back to PORT environment variable\n - Defaults to 4000 if neither is set\n - Valid range: 1-65535\n\nExamples:\n brick dev app.ts # port 4000 (default)\n brick dev app.ts --port 5000 # port 5000 (explicit)\n PORT=3000 brick dev app.ts # port 3000 (from env)\n brick dev app.ts --port 6000 # port 6000 (CLI overrides PORT=3000)\n`;\n\nfunction parsePortOption(value: string): number {\n try {\n return parsePort(value, undefined);\n } catch (err) {\n throw new InvalidArgumentError((err as Error).message);\n }\n}\n\nfunction parseFileOption(value: string, usage: string): string {\n if (value.startsWith(\"-\")) {\n throw new InvalidArgumentError(`${usage} (got flag-like value '${value}')`);\n }\n return value;\n}\n\nfunction resolveDevPort(cliPort: number | undefined): number {\n if (cliPort !== undefined) return cliPort;\n return parsePort(undefined, process.env.PORT);\n}\n\nexport function createProgram(): Command {\n const program = new Command();\n program\n .name(\"brick\")\n .description(\"🧱 Brick-TS CLI\")\n .version(CLI_VERSION)\n .showHelpAfterError()\n .addHelpText(\n \"after\",\n `\nUsage:\n brick dev [entry] [--port <number>] Start development server with live reload\n brick start [entry] [--port <number>] Start production server\n brick build <app.ts> [--outdir <dir>] [--port <number>] [--no-aot] Compile a default-exported BrickApp into a Bun server\n brick gen openapi <entry> [--output <file>] Generate OpenAPI 3.1 JSON specification\n brick gen client <entry> [--output <file>] Generate a typed browser client contract\n brick info <entry> Export architecture JSON schema\n${PORT_RESOLUTION_HELP}`,\n );\n\n program\n .command(\"dev\")\n .description(\"Start development server with live reload\")\n .argument(\"[entry]\", \"Application entry file\")\n .option(\"--port <number>\", PORT_HELP, parsePortOption)\n .addHelpText(\"after\", PORT_RESOLUTION_HELP)\n .action(async (entry: string | undefined, opts: { port?: number }) => {\n const port = resolveDevPort(opts.port);\n await startDevServer({ entry, port });\n });\n\n program\n .command(\"start\")\n .description(\"Start production server\")\n .argument(\"[entry]\", \"Application entry file\")\n .option(\"--port <number>\", PORT_HELP, parsePortOption)\n .addHelpText(\"after\", PORT_RESOLUTION_HELP)\n .action(async (entry: string | undefined, opts: { port?: number }) => {\n const port = resolveDevPort(opts.port);\n await startProdServer({ entry, port });\n });\n\n program\n .command(\"build\")\n .description(\"Compile a default-exported BrickApp into a Bun server\")\n .argument(\n \"<entry>\",\n \"Application entry file (must default-export a BrickApp)\",\n )\n .option(\"--outdir <dir>\", \"Output directory\", (v: string) =>\n parseFileOption(v, \"Usage: brick build <app.ts> [--outdir <directory>]\"),\n )\n .option(\"--port <number>\", \"Default listening port\", parsePortOption)\n .option(\"--no-aot\", \"Disable ahead-of-time compilation\")\n .option(\n \"--prefix <path>\",\n \"DEPRECATED: configure prefix in brick() app instead\",\n )\n .option(\n \"--no-request-logging\",\n \"DEPRECATED: configure requestLogging in brick() app instead\",\n )\n .action(\n async (\n entry: string,\n opts: {\n outdir?: string;\n port?: number;\n aot?: boolean;\n prefix?: string;\n requestLogging?: boolean;\n },\n ) => {\n if (opts.prefix !== undefined || opts.requestLogging === false) {\n throw new Error(\n \"Brick: configure prefix and requestLogging in your default-exported brick() app instead of build flags.\",\n );\n }\n const result = await buildApplication({\n entry,\n outdir: opts.outdir,\n port: opts.port,\n aot: opts.aot,\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 },\n );\n\n const gen = program\n .command(\"gen\")\n .description(\"Generate artifacts from a BrickApp entry\")\n .argument(\"[subcommand]\", \"Generator to run (openapi, client)\")\n .action((subcommand: string | undefined) => {\n console.error(\n `Unknown generator: ${subcommand ?? \"(none)\"}. Available: openapi, client`,\n );\n process.exit(1);\n });\n\n gen\n .command(\"openapi\")\n .description(\"Generate OpenAPI 3.1 JSON specification\")\n .argument(\"<entry>\", \"Application entry file\")\n .option(\n \"--output <file>\",\n \"Write specification to file instead of stdout\",\n (v: string) =>\n parseFileOption(\n v,\n \"Usage: brick gen openapi <entry> [--output <file>]\",\n ),\n )\n .action(async (entry: string, opts: { output?: string }) => {\n const app = await loadBrickApp(entry);\n const spec = generateOpenApiSpec({\n services: [...app.definition.services],\n prefix: app.definition.prefix,\n });\n const jsonOutput = JSON.stringify(spec, null, 2);\n if (opts.output) {\n await Bun.write(opts.output, jsonOutput);\n console.log(`✅ OpenAPI 3.1 specification written to ${opts.output}`);\n } else {\n console.log(jsonOutput);\n }\n });\n\n gen\n .command(\"client\")\n .description(\"Generate a typed browser client contract\")\n .argument(\"<entry>\", \"Application entry file\")\n .option(\n \"--output <file>\",\n \"Write contract to file (default _brick/contract.ts)\",\n (v: string) =>\n parseFileOption(v, \"Usage: brick gen client <entry> [--output <file>]\"),\n )\n .action(async (entry: string, opts: { output?: string }) => {\n const output = await writeClientContract(entry, opts.output);\n console.log(`Client contract written to ${output}`);\n });\n\n program\n .command(\"info\")\n .alias(\"services\")\n .description(\"Export architecture JSON schema\")\n .argument(\"<entry>\", \"Application entry file\")\n .action(async (entry: string) => {\n const app = await loadBrickApp(entry);\n const architecture = getGlobalRegistry().exportArchitecture(\n app.definition,\n );\n console.log(JSON.stringify(architecture, null, 2));\n });\n\n return program;\n}\n\nasync function main() {\n const program = createProgram();\n // Preserve legacy behavior: bare `brick` starts the dev server.\n const userArgs = process.argv.slice(2);\n if (userArgs.length === 0) {\n const port = parsePort(undefined, process.env.PORT);\n await startDevServer({ port });\n return;\n }\n await program.parseAsync(process.argv);\n}\n\nmain().catch((err) => {\n // Commander already prints validation errors (missing arg, unknown option,\n // invalid port) and exits. Only print Fatal error for action failures.\n if (err?.exitCode !== undefined) {\n process.exit(err.exitCode);\n }\n if (err?.code?.startsWith?.(\"commander.\")) {\n process.exit(1);\n }\n console.error(\"Fatal error:\", err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;AAOA,eAAsB,oBACpB,WACA,YACA;CACA,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,SAAS,QAAQ,cAAc,oBAAoB;CACzD,IAAI,UAAU,QACZ,MAAM,IAAI,MAAM,0DAA0D;CAC5E,MAAM,MAAM,MAAM,aAAa,KAAK;CACpC,MAAM,SAAS,uBAAuB,GAAG;CAKzC,IAAI,MAJmB,SAAS,QAAQ,MAAM,CAAC,CAAC,OAAO,UAAU;EAC/D,IAAI,MAAM,SAAS,UAAU,MAAM;CAErC,CAAC,MACgB,QAAQ;EACvB,MAAM,MAAM,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;EAChD,MAAM,YAAY,KAChB,QAAQ,MAAM,GACd,mBAAmB,WAAW,EAAE,KAClC;EACA,IAAI;GACF,MAAM,UAAU,WAAW,QAAQ,EAAE,MAAM,KAAK,CAAC;GACjD,MAAM,OAAO,WAAW,MAAM;EAChC,UAAU;GACR,MAAM,GAAG,WAAW,EAAE,OAAO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I,QAAQ;CAE3B,IAAI,KAAK,MAAM,aAAa,YAAY,GACtC,QAAQ,KAAK,CAAC;CAEhB,QAAQ,MAAM,gBAAgB,GAAG;CACjC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/dist/build.js CHANGED
@@ -1,149 +1,21 @@
1
1
  import { i as emitCompiledApplication, n as compileBrickApplication } from "./compiler2.js";
2
- import { brick, getPluginActionRoute, requireBrickApp, resetGlobalRegistry } from "@brickkit/core";
3
- import { existsSync, watch } from "fs";
4
- import { resolve } from "path";
2
+ import { requireBrickApp } from "@brickkit/core";
3
+ import { pathToFileURL } from "node:url";
5
4
  import { mkdir, mkdtemp, rename, rm } from "node:fs/promises";
6
- import { dirname, join, resolve as resolve$1 } from "node:path";
5
+ import { dirname, join, resolve } from "node:path";
7
6
  import { aot } from "elysia/plugin/aot/bun";
8
- import { pathToFileURL } from "node:url";
9
- //#region src/runner.ts
10
- let currentServer = null;
11
- async function closeServer() {
12
- if (currentServer) try {
13
- await currentServer.stop?.();
14
- currentServer = null;
15
- await new Promise((resolve) => setTimeout(resolve, 100));
16
- } catch (err) {
17
- console.error("Error closing server:", err);
18
- }
19
- }
20
- async function createServer(options, label) {
21
- let port;
22
- if (options.port !== void 0) port = options.port;
23
- else if (process.env.PORT !== void 0 && process.env.PORT !== "") port = Number(process.env.PORT);
24
- else port = 4e3;
25
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
26
- const app = brick({
27
- port,
28
- prefix: options.prefix
29
- });
30
- currentServer = await app.listen({ port });
31
- const prefix = app.definition.prefix;
32
- const services = app.definition.services;
33
- console.log(`\n🧱 Brick-TS ${label} Server`);
34
- console.log(` Registered Services: ${services.length}`);
35
- for (const svc of services) {
36
- const actions = svc.listActions();
37
- console.log(` • ${svc.name} (${actions.length} actions)`);
38
- for (const act of actions) {
39
- const pluginRoute = getPluginActionRoute(act, prefix);
40
- if (pluginRoute === false) continue;
41
- const method = pluginRoute?.method ?? act.config.method ?? "POST";
42
- const path = pluginRoute?.path ?? act.config.path ?? `${prefix}/${svc.name}/${act.name}`;
43
- console.log(` -> ${method.padEnd(6)} ${path}`);
44
- }
45
- }
46
- console.log(`\n⚡ API Gateway running on: http://localhost:${port}`);
47
- console.log(`🩺 Health check: http://localhost:${port}/_health`);
48
- console.log(`🗺️ Architecture graph: http://localhost:${port}/_brick/services\n`);
49
- return app;
50
- }
51
- async function startProdServer(options = {}) {
52
- const entry = options.entry;
53
- if (entry) {
54
- const resolvedEntry = resolve(process.cwd(), entry);
55
- if (!existsSync(resolvedEntry)) {
56
- console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);
57
- process.exit(1);
58
- }
59
- console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);
60
- await import(resolvedEntry);
61
- }
62
- const port = options.port !== void 0 ? options.port : process.env.PORT !== void 0 && process.env.PORT !== "" ? Number(process.env.PORT) : 4e3;
63
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
64
- const app = brick({
65
- port,
66
- prefix: options.prefix
67
- });
68
- const prefix = app.definition.prefix;
69
- const services = app.definition.services;
70
- console.log(`\n🧱 Brick-TS Production Server`);
71
- console.log(` Registered Services: ${services.length}`);
72
- for (const svc of services) {
73
- const actions = svc.listActions();
74
- console.log(` • ${svc.name} (${actions.length} actions)`);
75
- for (const act of actions) {
76
- const pluginRoute = getPluginActionRoute(act, prefix);
77
- if (pluginRoute === false) continue;
78
- const method = pluginRoute?.method ?? act.config.method ?? "POST";
79
- const path = pluginRoute?.path ?? act.config.path ?? `${prefix}/${svc.name}/${act.name}`;
80
- console.log(` -> ${method.padEnd(6)} ${path}`);
81
- }
82
- }
83
- app.listen(port);
84
- console.log(`\n⚡ API Gateway running on: http://localhost:${port}`);
85
- console.log(`🩺 Health check: http://localhost:${port}/_health`);
86
- console.log(`🗺️ Architecture graph: http://localhost:${port}/_brick/services\n`);
87
- return app;
88
- }
89
- async function startDevServer(options = {}) {
90
- const entry = options.entry;
91
- if (entry) {
92
- const resolvedEntry = resolve(process.cwd(), entry);
93
- if (!existsSync(resolvedEntry)) {
94
- console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);
95
- process.exit(1);
96
- }
97
- console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);
98
- await import(resolvedEntry);
99
- }
100
- const app = await createServer(options, "Development");
101
- const cwd = process.cwd();
102
- const watchDirs = [
103
- resolve(cwd, "src"),
104
- resolve(cwd, "app"),
105
- entry ? resolve(cwd, entry).replace(/\/[^/]+$/, "") : null
106
- ].filter(Boolean);
107
- let isRestarting = false;
108
- for (const dir of watchDirs) {
109
- if (!existsSync(dir)) continue;
110
- watch(dir, { recursive: true }, async (eventType, filename) => {
111
- if (!filename || filename.includes("node_modules") || isRestarting) return;
112
- isRestarting = true;
113
- await new Promise((resolve) => setTimeout(resolve, 100));
114
- console.log(`\n📝 Changes detected in ${filename}. Restarting server...`);
115
- try {
116
- await closeServer();
117
- resetGlobalRegistry();
118
- if (entry) {
119
- const resolvedEntry = resolve(process.cwd(), entry);
120
- if (existsSync(resolvedEntry)) await import(resolvedEntry);
121
- }
122
- await createServer(options, "Development");
123
- } catch (err) {
124
- console.error("Error restarting server:", err);
125
- isRestarting = false;
126
- return;
127
- }
128
- isRestarting = false;
129
- });
130
- }
131
- console.log(`\n👀 Watching for changes in: ${watchDirs.join(", ")}`);
132
- return app;
133
- }
134
- //#endregion
135
7
  //#region src/app-entry.ts
136
8
  async function loadBrickApp(entry) {
137
- const module = await import(pathToFileURL(resolve$1(entry)).href);
9
+ const module = await import(pathToFileURL(resolve(entry)).href);
138
10
  return requireBrickApp(module.default);
139
11
  }
140
12
  //#endregion
141
13
  //#region src/build.ts
142
14
  /** Bundle an exported BrickApp with generated handlers and its original configuration. */
143
15
  async function buildApplication(options) {
144
- const entry = resolve$1(options.entry);
16
+ const entry = resolve(options.entry);
145
17
  if (!await Bun.file(entry).exists()) throw new Error(`Brick compiler: entry not found: ${entry}`);
146
- const outdir = resolve$1(options.outdir ?? "dist/brick");
18
+ const outdir = resolve(options.outdir ?? "dist/brick");
147
19
  if (entry === join(outdir, "server.js") || entry === join(outdir, "routes.js")) throw new Error("Brick compiler: output would overwrite the application entry");
148
20
  const port = options.port ?? 4e3;
149
21
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Brick compiler: port must be an integer between 1 and 65535");
@@ -205,6 +77,6 @@ if (import.meta.main) {
205
77
  }
206
78
  }
207
79
  //#endregion
208
- export { startProdServer as i, loadBrickApp as n, startDevServer as r, buildApplication as t };
80
+ export { loadBrickApp as n, buildApplication as t };
209
81
 
210
82
  //# sourceMappingURL=build.js.map
package/dist/build.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","names":["resolve","resolve"],"sources":["../src/runner.ts","../src/app-entry.ts","../src/build.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { watch } from \"fs\";\nimport { resolve } from \"path\";\nimport {\n brick,\n getPluginActionRoute,\n resetGlobalRegistry,\n} from \"@brickkit/core\";\n\nexport interface DevServerOptions {\n port?: number;\n entry?: string;\n prefix?: string;\n}\n\nlet currentServer: any = null;\n\nasync function closeServer() {\n if (currentServer) {\n try {\n await currentServer.stop?.();\n currentServer = null;\n await new Promise((resolve) => setTimeout(resolve, 100));\n } catch (err) {\n console.error(\"Error closing server:\", err);\n }\n }\n}\n\nasync function createServer(options: DevServerOptions, label: string) {\n let port: number;\n if (options.port !== undefined) {\n port = options.port;\n } else if (process.env.PORT !== undefined && process.env.PORT !== \"\") {\n port = Number(process.env.PORT);\n } else {\n port = 4000;\n }\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n\n const app = brick({\n port,\n prefix: options.prefix,\n });\n\n currentServer = await app.listen({ port });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS ${label} Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const pluginRoute = getPluginActionRoute(act, prefix);\n if (pluginRoute === false) continue;\n const method = pluginRoute?.method ?? act.config.method ?? \"POST\";\n const path =\n pluginRoute?.path ??\n act.config.path ??\n `${prefix}/${svc.name}/${act.name}`;\n console.log(` -> ${method.padEnd(6)} ${path}`);\n }\n }\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\nexport async function startProdServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await import(resolvedEntry);\n }\n\n const port =\n options.port !== undefined\n ? options.port\n : process.env.PORT !== undefined && process.env.PORT !== \"\"\n ? Number(process.env.PORT)\n : 4000;\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n\n const app = brick({\n port,\n prefix: options.prefix,\n });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS Production Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const pluginRoute = getPluginActionRoute(act, prefix);\n if (pluginRoute === false) continue;\n const method = pluginRoute?.method ?? act.config.method ?? \"POST\";\n const path =\n pluginRoute?.path ??\n act.config.path ??\n `${prefix}/${svc.name}/${act.name}`;\n console.log(` -> ${method.padEnd(6)} ${path}`);\n }\n }\n\n app.listen(port);\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\nexport async function startDevServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await import(resolvedEntry);\n }\n\n const app = await createServer(options, \"Development\");\n\n const cwd = process.cwd();\n const watchDirs = [\n resolve(cwd, \"src\"),\n resolve(cwd, \"app\"),\n entry ? resolve(cwd, entry).replace(/\\/[^/]+$/, \"\") : null,\n ].filter(Boolean) as string[];\n\n let isRestarting = false;\n\n for (const dir of watchDirs) {\n if (!existsSync(dir)) continue;\n\n watch(dir, { recursive: true }, async (eventType, filename) => {\n if (!filename || filename.includes(\"node_modules\") || isRestarting)\n return;\n\n isRestarting = true;\n\n await new Promise((resolve) => setTimeout(resolve, 100));\n\n console.log(`\\n📝 Changes detected in ${filename}. Restarting server...`);\n\n try {\n await closeServer();\n resetGlobalRegistry();\n\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (existsSync(resolvedEntry)) {\n await import(resolvedEntry);\n }\n }\n\n await createServer(options, \"Development\");\n } catch (err) {\n console.error(\"Error restarting server:\", err);\n isRestarting = false;\n return;\n }\n\n isRestarting = false;\n });\n }\n\n console.log(`\\n👀 Watching for changes in: ${watchDirs.join(\", \")}`);\n\n return app;\n}\n","import { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { isBrickApp, requireBrickApp, type BrickApp } from \"@brickkit/core\";\n\nexport { isBrickApp, requireBrickApp, type BrickApp };\n\nexport async function loadBrickApp(entry: string): Promise<BrickApp> {\n const module = await import(pathToFileURL(resolve(entry)).href);\n return requireBrickApp(module.default);\n}\n","import { mkdtemp, mkdir, rename, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { compileBrickApplication, emitCompiledApplication } from \"./compiler\";\nimport { aot } from \"elysia/plugin/aot/bun\";\nimport { loadBrickApp } from \"./app-entry\";\n\nexport interface BuildApplicationOptions {\n /** A module whose default export is a BrickApp, without starting a server. */\n entry: string;\n outdir?: string;\n port?: number;\n /** Precompile Elysia's HTTP handlers at build time (default true). */\n aot?: boolean;\n}\n\n/** Bundle an exported BrickApp with generated handlers and its original configuration. */\nexport async function buildApplication(options: BuildApplicationOptions) {\n const entry = resolve(options.entry);\n if (!(await Bun.file(entry).exists()))\n throw new Error(`Brick compiler: entry not found: ${entry}`);\n const outdir = resolve(options.outdir ?? \"dist/brick\");\n if (\n entry === join(outdir, \"server.js\") ||\n entry === join(outdir, \"routes.js\")\n )\n throw new Error(\n \"Brick compiler: output would overwrite the application entry\",\n );\n const port = options.port ?? 4000;\n if (!Number.isInteger(port) || port < 1 || port > 65535)\n throw new Error(\n \"Brick compiler: port must be an integer between 1 and 65535\",\n );\n const app = await loadBrickApp(entry);\n const services = [...app.definition.services];\n const compilation = compileBrickApplication({\n services,\n prefix: app.definition.prefix,\n });\n await mkdir(dirname(outdir), { recursive: true });\n const staging = await mkdtemp(join(dirname(outdir), \".brick-build-\"));\n try {\n await Bun.write(\n join(staging, \"routes.js\"),\n emitCompiledApplication(compilation.ir),\n );\n const source = `import { loadCompiledBrickApp } from \"@brickkit/core\";\nimport { ir, bind } from \"./routes.js\";\nexport const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir, bind);\nif (import.meta.main) {\n const port = Number(process.env.PORT ?? ${port});\n if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(\"Invalid PORT: must be between 1 and 65535\");\n app.listen(port);\n console.log(\"Brick compiled server listening on http://localhost:\" + app.server.port);\n const stop = async () => { await app.stop(); process.exit(0); };\n process.once(\"SIGINT\", stop);\n process.once(\"SIGTERM\", stop);\n}\n`;\n await Bun.write(join(staging, \"entry.ts\"), source);\n const result = await Bun.build({\n entrypoints: [join(staging, \"entry.ts\")],\n target: \"bun\",\n format: \"esm\",\n outdir: staging,\n naming: \"server.js\",\n sourcemap: \"external\",\n plugins:\n options.aot === false\n ? []\n : [aot(join(staging, \"entry.ts\"), { target: \"bun\", strip: true })],\n });\n if (!result.success)\n throw new AggregateError(result.logs, \"Brick compiler: bundling failed\");\n await Bun.write(\n join(staging, \"brick-ir.json\"),\n JSON.stringify(compilation.ir, null, 2) + \"\\n\",\n );\n await mkdir(outdir, { recursive: true });\n for (const name of [\n \"routes.js\",\n \"brick-ir.json\",\n \"server.js.map\",\n \"server.js\",\n ])\n await rename(join(staging, name), join(outdir, name));\n return { outdir, entry: join(outdir, \"server.js\"), ir: compilation.ir };\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n}\n"],"mappings":";;;;;;;;;AAeA,IAAI,gBAAqB;AAEzB,eAAe,cAAc;CAC3B,IAAI,eACF,IAAI;EACF,MAAM,cAAc,OAAO;EAC3B,gBAAgB;EAChB,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;CACzD,SAAS,KAAK;EACZ,QAAQ,MAAM,yBAAyB,GAAG;CAC5C;AAEJ;AAEA,eAAe,aAAa,SAA2B,OAAe;CACpE,IAAI;CACJ,IAAI,QAAQ,SAAS,KAAA,GACnB,OAAO,QAAQ;MACV,IAAI,QAAQ,IAAI,SAAS,KAAA,KAAa,QAAQ,IAAI,SAAS,IAChE,OAAO,OAAO,QAAQ,IAAI,IAAI;MAE9B,OAAO;CAET,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAChD,MAAM,IAAI,MACR,iBAAiB,KAAK,8CACxB;CAGF,MAAM,MAAM,MAAM;EAChB;EACA,QAAQ,QAAQ;CAClB,CAAC;CAED,gBAAgB,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AAG,KAAK,QAAQ,IAAI,CAAC;EACtD,OAAO;GAAE;GAAQ,OAAO,KAAK,QAAQ,WAAW;GAAG,IAAI,YAAY;EAAG;CACxE,UAAU;EACR,MAAM,GAAG,SAAS;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CACpD;AACF"}
1
+ {"version":3,"file":"build.js","names":[],"sources":["../src/app-entry.ts","../src/build.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { isBrickApp, requireBrickApp, type BrickApp } from \"@brickkit/core\";\n\nexport { isBrickApp, requireBrickApp, type BrickApp };\n\nexport async function loadBrickApp(entry: string): Promise<BrickApp> {\n const module = await import(pathToFileURL(resolve(entry)).href);\n return requireBrickApp(module.default);\n}\n","import { mkdtemp, mkdir, rename, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { compileBrickApplication, emitCompiledApplication } from \"./compiler\";\nimport { aot } from \"elysia/plugin/aot/bun\";\nimport { loadBrickApp } from \"./app-entry\";\n\nexport interface BuildApplicationOptions {\n /** A module whose default export is a BrickApp, without starting a server. */\n entry: string;\n outdir?: string;\n port?: number;\n /** Precompile Elysia's HTTP handlers at build time (default true). */\n aot?: boolean;\n}\n\n/** Bundle an exported BrickApp with generated handlers and its original configuration. */\nexport async function buildApplication(options: BuildApplicationOptions) {\n const entry = resolve(options.entry);\n if (!(await Bun.file(entry).exists()))\n throw new Error(`Brick compiler: entry not found: ${entry}`);\n const outdir = resolve(options.outdir ?? \"dist/brick\");\n if (\n entry === join(outdir, \"server.js\") ||\n entry === join(outdir, \"routes.js\")\n )\n throw new Error(\n \"Brick compiler: output would overwrite the application entry\",\n );\n const port = options.port ?? 4000;\n if (!Number.isInteger(port) || port < 1 || port > 65535)\n throw new Error(\n \"Brick compiler: port must be an integer between 1 and 65535\",\n );\n const app = await loadBrickApp(entry);\n const services = [...app.definition.services];\n const compilation = compileBrickApplication({\n services,\n prefix: app.definition.prefix,\n });\n await mkdir(dirname(outdir), { recursive: true });\n const staging = await mkdtemp(join(dirname(outdir), \".brick-build-\"));\n try {\n await Bun.write(\n join(staging, \"routes.js\"),\n emitCompiledApplication(compilation.ir),\n );\n const source = `import { loadCompiledBrickApp } from \"@brickkit/core\";\nimport { ir, bind } from \"./routes.js\";\nexport const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir, bind);\nif (import.meta.main) {\n const port = Number(process.env.PORT ?? ${port});\n if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(\"Invalid PORT: must be between 1 and 65535\");\n app.listen(port);\n console.log(\"Brick compiled server listening on http://localhost:\" + app.server.port);\n const stop = async () => { await app.stop(); process.exit(0); };\n process.once(\"SIGINT\", stop);\n process.once(\"SIGTERM\", stop);\n}\n`;\n await Bun.write(join(staging, \"entry.ts\"), source);\n const result = await Bun.build({\n entrypoints: [join(staging, \"entry.ts\")],\n target: \"bun\",\n format: \"esm\",\n outdir: staging,\n naming: \"server.js\",\n sourcemap: \"external\",\n plugins:\n options.aot === false\n ? []\n : [aot(join(staging, \"entry.ts\"), { target: \"bun\", strip: true })],\n });\n if (!result.success)\n throw new AggregateError(result.logs, \"Brick compiler: bundling failed\");\n await Bun.write(\n join(staging, \"brick-ir.json\"),\n JSON.stringify(compilation.ir, null, 2) + \"\\n\",\n );\n await mkdir(outdir, { recursive: true });\n for (const name of [\n \"routes.js\",\n \"brick-ir.json\",\n \"server.js.map\",\n \"server.js\",\n ])\n await rename(join(staging, name), join(outdir, name));\n return { outdir, entry: join(outdir, \"server.js\"), ir: compilation.ir };\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n}\n"],"mappings":";;;;;;;AAMA,eAAsB,aAAa,OAAkC;CACnE,MAAM,SAAS,MAAM,OAAO,cAAc,QAAQ,KAAK,CAAC,CAAC,CAAC;CAC1D,OAAO,gBAAgB,OAAO,OAAO;AACvC;;;;ACOA,eAAsB,iBAAiB,SAAkC;CACvE,MAAM,QAAQ,QAAQ,QAAQ,KA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SAAS,eAAe,GAC7B,KAAK,UAAU,YAAY,IAAI,MAAM,CAAC,IAAI,IAC5C;EACA,MAAM,MAAM,QAAQ,EAAE,WAAW,KAAK,CAAC;EACvC,KAAK,MAAM,QAAQ;GACjB;GACA;GACA;GACA;EACF,GACE,MAAM,OAAO,KAAK,SAAS,IAAI,GAAG,KAAK,QAAQ,IAAI,CAAC;EACtD,OAAO;GAAE;GAAQ,OAAO,KAAK,QAAQ,WAAW;GAAG,IAAI,YAAY;EAAG;CACxE,UAAU;EACR,MAAM,GAAG,SAAS;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CACpD;AACF"}
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,12 @@
1
+ import { t as startDevApplication } from "./runner.js";
2
+ import { t as parsePort } from "./port-utils.js";
3
+ //#region src/dev-worker.ts
4
+ await startDevApplication({
5
+ entry: process.argv[2],
6
+ port: parsePort(process.argv[3] || void 0, process.env.PORT),
7
+ prefix: process.argv[4] || void 0
8
+ });
9
+ //#endregion
10
+ export {};
11
+
12
+ //# sourceMappingURL=dev-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-worker.js","names":[],"sources":["../src/dev-worker.ts"],"sourcesContent":["import { startDevApplication } from \"./runner\";\nimport { parsePort } from \"./port-utils\";\n\nawait startDevApplication({\n entry: process.argv[2],\n port: parsePort(process.argv[3] || undefined, process.env.PORT),\n prefix: process.argv[4] || undefined,\n});\n"],"mappings":";;;AAGA,MAAM,oBAAoB;CACxB,OAAO,QAAQ,KAAK;CACpB,MAAM,UAAU,QAAQ,KAAK,MAAM,KAAA,GAAW,QAAQ,IAAI,IAAI;CAC9D,QAAQ,QAAQ,KAAK,MAAM,KAAA;AAC7B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { n as emitHandlerFactory, t as emitCompiledApplication } from "./emit.js";
2
- import { BrickApp, BrickApp as BrickApp$1, BrickIR, CompiledApplication, CompiledHandler, CompiledRoute, CreateServerOptions, EndpointContext, EndpointDefinition, EndpointLogger, EndpointMethod, HandlerFactory, ReferenceOptions, RequestLoggingOptions, RouteIR, RouteMethod, bindCompiledApplication, brick, compileBrickApplication, loadCompiledBrickApp, referencePlugin, registerReferenceRoute, requestLoggingPlugin, scalarDocsHTML } from "@brickkit/core";
2
+ import { BrickApp, BrickApp as BrickApp$1, BrickApp as BrickApp$2, BrickIR, CompiledApplication, CompiledHandler, CompiledRoute, CreateServerOptions, EndpointContext, EndpointDefinition, EndpointLogger, EndpointMethod, HandlerFactory, ReferenceOptions, RequestLoggingOptions, RouteIR, RouteMethod, bindCompiledApplication, brick, compileBrickApplication, loadCompiledBrickApp, referencePlugin, registerReferenceRoute, requestLoggingPlugin, scalarDocsHTML } from "@brickkit/core";
3
3
  //#region src/runner.d.ts
4
4
  interface DevServerOptions {
5
5
  port?: number;
6
6
  entry?: string;
7
7
  prefix?: string;
8
8
  }
9
- export declare function startDevServer(options?: DevServerOptions): Promise<import("@brickkit/core").BrickApp>;
9
+ export declare function startDevServer(options?: DevServerOptions): Promise<BrickApp$1 | {
10
+ stop: () => void;
11
+ }>;
10
12
  //#endregion
11
13
  //#region src/build.d.ts
12
14
  interface BuildApplicationOptions {
@@ -26,7 +28,7 @@ export declare function buildApplication(options: BuildApplicationOptions): Prom
26
28
  //#endregion
27
29
  //#region src/client-contract.d.ts
28
30
  /** Generate browser metadata and transport types from the app's selected services. */
29
- export declare function generateClientContract(app: BrickApp$1): string;
31
+ export declare function generateClientContract(app: BrickApp$2): string;
30
32
  //#endregion
31
33
  export { type BrickApp, type BrickIR, type BuildApplicationOptions, type CompiledApplication, type CompiledHandler, type CompiledRoute, type CreateServerOptions, type DevServerOptions, type EndpointContext, type EndpointDefinition, type EndpointLogger, type EndpointMethod, type HandlerFactory, type ReferenceOptions, type RequestLoggingOptions, type RouteIR, type RouteMethod, bindCompiledApplication, brick, compileBrickApplication, emitCompiledApplication, emitHandlerFactory, loadCompiledBrickApp, referencePlugin, registerReferenceRoute, requestLoggingPlugin, scalarDocsHTML };
32
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["BrickApp"],"sources":["../src/runner.ts","../src/build.ts","../src/client-contract.ts"],"mappings":";;;UASiB;EACf;EACA;EACA;;wBAmIoB,eAAe,UAAS,mBAAqB,iCAAA;;;UCzIlD;;EAEf;EACA;EACA;;EAEA;;;wBAIoB,iBAAiB,SAAS,0BAAuB;;;;;;;;wBCVvD,uBAAuB,KAAKA"}
1
+ {"version":3,"file":"index.d.ts","names":["BrickApp","BrickApp"],"sources":["../src/runner.ts","../src/build.ts","../src/client-contract.ts"],"mappings":";;;UAWiB;EACf;EACA;EACA;;wBA2IoB,eAAe,UAAS,mBAAqB,QAAAA;;;;;UCnJlD;;EAEf;EACA;EACA;;EAEA;;;wBAIoB,iBAAiB,SAAS,0BAAuB;;;;;;;;wBCVvD,uBAAuB,KAAKC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { r as startDevServer, t as buildApplication } from "./build.js";
1
+ import { n as startDevServer } from "./runner.js";
2
2
  import { a as emitHandlerFactory, i as emitCompiledApplication } from "./compiler2.js";
3
+ import { t as buildApplication } from "./build.js";
3
4
  import { t as generateClientContract } from "./client-contract.js";
4
5
  import { bindCompiledApplication, brick, compileBrickApplication, loadCompiledBrickApp, referencePlugin, registerReferenceRoute, requestLoggingPlugin, scalarDocsHTML } from "@brickkit/core";
5
6
  export { bindCompiledApplication, brick, buildApplication, compileBrickApplication, emitCompiledApplication, emitHandlerFactory, generateClientContract, loadCompiledBrickApp, referencePlugin, registerReferenceRoute, requestLoggingPlugin, scalarDocsHTML, startDevServer };
@@ -0,0 +1,13 @@
1
+ //#region src/port-utils.ts
2
+ function parsePort(portStr, envPort) {
3
+ let port;
4
+ if (portStr !== void 0) port = Number(portStr);
5
+ else if (envPort !== void 0 && envPort !== "") port = Number(envPort);
6
+ else port = 4e3;
7
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
8
+ return port;
9
+ }
10
+ //#endregion
11
+ export { parsePort as t };
12
+
13
+ //# sourceMappingURL=port-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port-utils.js","names":[],"sources":["../src/port-utils.ts"],"sourcesContent":["export function parsePort(\n portStr: string | undefined,\n envPort?: string | undefined,\n): number {\n let port: number | undefined;\n if (portStr !== undefined) {\n port = Number(portStr);\n } else if (envPort !== undefined && envPort !== \"\") {\n port = Number(envPort);\n } else {\n port = 4000;\n }\n\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n return port;\n}\n"],"mappings":";AAAA,SAAgB,UACd,SACA,SACQ;CACR,IAAI;CACJ,IAAI,YAAY,KAAA,GACd,OAAO,OAAO,OAAO;MAChB,IAAI,YAAY,KAAA,KAAa,YAAY,IAC9C,OAAO,OAAO,OAAO;MAErB,OAAO;CAGT,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAChD,MAAM,IAAI,MACR,iBAAiB,KAAK,8CACxB;CAEF,OAAO;AACT"}
package/dist/runner.js ADDED
@@ -0,0 +1,163 @@
1
+ import { brick, getPluginActionRoute, isBrickApp } from "@brickkit/core";
2
+ import { existsSync, watch } from "fs";
3
+ import { resolve } from "path";
4
+ import { fileURLToPath } from "node:url";
5
+ //#region src/runner.ts
6
+ async function createServer(options, label, application) {
7
+ let port;
8
+ if (options.port !== void 0) port = options.port;
9
+ else if (process.env.PORT !== void 0 && process.env.PORT !== "") port = Number(process.env.PORT);
10
+ else port = 4e3;
11
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
12
+ const app = application ?? brick({
13
+ port,
14
+ prefix: options.prefix
15
+ });
16
+ await app.listen({ port });
17
+ const prefix = app.definition.prefix;
18
+ const services = app.definition.services;
19
+ console.log(`\n🧱 Brick-TS ${label} Server`);
20
+ console.log(` Registered Services: ${services.length}`);
21
+ for (const svc of services) {
22
+ const actions = svc.listActions();
23
+ console.log(` • ${svc.name} (${actions.length} actions)`);
24
+ for (const act of actions) {
25
+ const pluginRoute = getPluginActionRoute(act, prefix);
26
+ if (pluginRoute === false) continue;
27
+ const method = pluginRoute?.method ?? act.config.method ?? "POST";
28
+ const path = pluginRoute?.path ?? act.config.path ?? `${prefix}/${svc.name}/${act.name}`;
29
+ console.log(` -> ${method.padEnd(6)} ${path}`);
30
+ }
31
+ }
32
+ console.log(`\n⚡ API Gateway running on: http://localhost:${port}`);
33
+ console.log(`🩺 Health check: http://localhost:${port}/_health`);
34
+ console.log(`🗺️ Architecture graph: http://localhost:${port}/_brick/services\n`);
35
+ return app;
36
+ }
37
+ async function startProdServer(options = {}) {
38
+ const entry = options.entry;
39
+ if (entry) {
40
+ const resolvedEntry = resolve(process.cwd(), entry);
41
+ if (!existsSync(resolvedEntry)) {
42
+ console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);
43
+ process.exit(1);
44
+ }
45
+ console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);
46
+ await import(resolvedEntry);
47
+ }
48
+ const port = options.port !== void 0 ? options.port : process.env.PORT !== void 0 && process.env.PORT !== "" ? Number(process.env.PORT) : 4e3;
49
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
50
+ const app = brick({
51
+ port,
52
+ prefix: options.prefix
53
+ });
54
+ const prefix = app.definition.prefix;
55
+ const services = app.definition.services;
56
+ console.log(`\n🧱 Brick-TS Production Server`);
57
+ console.log(` Registered Services: ${services.length}`);
58
+ for (const svc of services) {
59
+ const actions = svc.listActions();
60
+ console.log(` • ${svc.name} (${actions.length} actions)`);
61
+ for (const act of actions) {
62
+ const pluginRoute = getPluginActionRoute(act, prefix);
63
+ if (pluginRoute === false) continue;
64
+ const method = pluginRoute?.method ?? act.config.method ?? "POST";
65
+ const path = pluginRoute?.path ?? act.config.path ?? `${prefix}/${svc.name}/${act.name}`;
66
+ console.log(` -> ${method.padEnd(6)} ${path}`);
67
+ }
68
+ }
69
+ app.listen(port);
70
+ console.log(`\n⚡ API Gateway running on: http://localhost:${port}`);
71
+ console.log(`🩺 Health check: http://localhost:${port}/_health`);
72
+ console.log(`🗺️ Architecture graph: http://localhost:${port}/_brick/services\n`);
73
+ return app;
74
+ }
75
+ async function startDevApplication(options) {
76
+ const module = options.entry ? await import(resolve(options.entry)) : void 0;
77
+ if (isBrickApp(module?.default) && options.prefix !== void 0) console.warn(`[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${module.default.definition.prefix} takes precedence.`);
78
+ return createServer(options, "Development", isBrickApp(module?.default) ? module.default : void 0);
79
+ }
80
+ async function startDevServer(options = {}) {
81
+ const entry = options.entry;
82
+ if (!entry) return createServer(options, "Development");
83
+ const resolvedEntry = resolve(entry);
84
+ if (!existsSync(resolvedEntry)) {
85
+ console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);
86
+ process.exit(1);
87
+ }
88
+ const worker = new URL(import.meta.url.endsWith(".ts") ? "./dev-worker.ts" : "./dev-worker.js", import.meta.url);
89
+ let stopped = false;
90
+ const intentionalExits = /* @__PURE__ */ new WeakSet();
91
+ const launch = () => {
92
+ const application = Bun.spawn([
93
+ process.execPath,
94
+ fileURLToPath(worker),
95
+ resolvedEntry,
96
+ String(options.port ?? ""),
97
+ options.prefix ?? ""
98
+ ], {
99
+ cwd: process.cwd(),
100
+ stdout: "inherit",
101
+ stderr: "inherit"
102
+ });
103
+ application.exited.then((code) => {
104
+ if (!stopped && !intentionalExits.has(application)) console.error(`[Brick-TS] Application process exited with code ${code}. Waiting for changes to restart.`);
105
+ });
106
+ return application;
107
+ };
108
+ let child = launch();
109
+ const watchDirs = [.../* @__PURE__ */ new Set([
110
+ resolve("src"),
111
+ resolve("app"),
112
+ resolve(resolvedEntry, "..")
113
+ ])].filter(existsSync);
114
+ let pending;
115
+ let restarting = false;
116
+ let dirty = false;
117
+ async function restart() {
118
+ dirty = true;
119
+ if (restarting || stopped) return;
120
+ restarting = true;
121
+ try {
122
+ while (dirty && !stopped) {
123
+ dirty = false;
124
+ console.log("\n📝 Changes detected. Restarting server...");
125
+ intentionalExits.add(child);
126
+ child.kill();
127
+ await child.exited;
128
+ if (!stopped) child = launch();
129
+ }
130
+ } finally {
131
+ restarting = false;
132
+ }
133
+ }
134
+ const watchers = watchDirs.map((dir) => watch(dir, { recursive: true }, (_event, filename) => {
135
+ if (!filename || filename.split(/[\\/]/).includes("node_modules")) return;
136
+ clearTimeout(pending);
137
+ pending = setTimeout(() => {
138
+ restart();
139
+ }, 100);
140
+ }));
141
+ const stop = () => {
142
+ stopped = true;
143
+ clearTimeout(pending);
144
+ for (const watcher of watchers) watcher.close();
145
+ child.kill();
146
+ process.off("SIGINT", onSignal);
147
+ process.off("SIGTERM", onSignal);
148
+ process.off("exit", stop);
149
+ };
150
+ const onSignal = () => {
151
+ stop();
152
+ process.exit(0);
153
+ };
154
+ process.on("SIGINT", onSignal);
155
+ process.on("SIGTERM", onSignal);
156
+ process.on("exit", stop);
157
+ console.log(`\n👀 Watching for changes in: ${watchDirs.join(", ")}`);
158
+ return { stop };
159
+ }
160
+ //#endregion
161
+ export { startDevServer as n, startProdServer as r, startDevApplication as t };
162
+
163
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","names":[],"sources":["../src/runner.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { watch } from \"fs\";\nimport { resolve } from \"path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n brick,\n getPluginActionRoute,\n isBrickApp,\n type BrickApp,\n} from \"@brickkit/core\";\n\nexport interface DevServerOptions {\n port?: number;\n entry?: string;\n prefix?: string;\n}\n\nasync function createServer(\n options: DevServerOptions,\n label: string,\n application?: BrickApp,\n) {\n let port: number;\n if (options.port !== undefined) {\n port = options.port;\n } else if (process.env.PORT !== undefined && process.env.PORT !== \"\") {\n port = Number(process.env.PORT);\n } else {\n port = 4000;\n }\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n\n const app =\n application ??\n brick({\n port,\n prefix: options.prefix,\n });\n\n await app.listen({ port });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS ${label} Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const pluginRoute = getPluginActionRoute(act, prefix);\n if (pluginRoute === false) continue;\n const method = pluginRoute?.method ?? act.config.method ?? \"POST\";\n const path =\n pluginRoute?.path ??\n act.config.path ??\n `${prefix}/${svc.name}/${act.name}`;\n console.log(` -> ${method.padEnd(6)} ${path}`);\n }\n }\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\nexport async function startProdServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await import(resolvedEntry);\n }\n\n const port =\n options.port !== undefined\n ? options.port\n : process.env.PORT !== undefined && process.env.PORT !== \"\"\n ? Number(process.env.PORT)\n : 4000;\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n\n const app = brick({\n port,\n prefix: options.prefix,\n });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS Production Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const pluginRoute = getPluginActionRoute(act, prefix);\n if (pluginRoute === false) continue;\n const method = pluginRoute?.method ?? act.config.method ?? \"POST\";\n const path =\n pluginRoute?.path ??\n act.config.path ??\n `${prefix}/${svc.name}/${act.name}`;\n console.log(` -> ${method.padEnd(6)} ${path}`);\n }\n }\n\n app.listen(port);\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\nexport async function startDevApplication(options: DevServerOptions) {\n const module = options.entry\n ? await import(resolve(options.entry))\n : undefined;\n if (isBrickApp(module?.default) && options.prefix !== undefined) {\n console.warn(\n `[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${module.default.definition.prefix} takes precedence.`,\n );\n }\n return createServer(\n options,\n \"Development\",\n isBrickApp(module?.default) ? module.default : undefined,\n );\n}\n\nexport async function startDevServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n if (!entry) return createServer(options, \"Development\");\n const resolvedEntry = resolve(entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n\n const worker = new URL(\n import.meta.url.endsWith(\".ts\") ? \"./dev-worker.ts\" : \"./dev-worker.js\",\n import.meta.url,\n );\n let stopped = false;\n const intentionalExits = new WeakSet<ReturnType<typeof Bun.spawn>>();\n const launch = () => {\n const application = Bun.spawn(\n [\n process.execPath,\n fileURLToPath(worker),\n resolvedEntry,\n String(options.port ?? \"\"),\n options.prefix ?? \"\",\n ],\n {\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n },\n );\n void application.exited.then((code) => {\n if (!stopped && !intentionalExits.has(application)) {\n console.error(\n `[Brick-TS] Application process exited with code ${code}. Waiting for changes to restart.`,\n );\n }\n });\n return application;\n };\n let child = launch();\n const watchDirs = [\n ...new Set([resolve(\"src\"), resolve(\"app\"), resolve(resolvedEntry, \"..\")]),\n ].filter(existsSync);\n let pending: ReturnType<typeof setTimeout> | undefined;\n let restarting = false;\n let dirty = false;\n\n async function restart() {\n dirty = true;\n if (restarting || stopped) return;\n restarting = true;\n try {\n while (dirty && !stopped) {\n dirty = false;\n console.log(\"\\n📝 Changes detected. Restarting server...\");\n intentionalExits.add(child);\n child.kill();\n await child.exited;\n if (!stopped) child = launch();\n }\n } finally {\n restarting = false;\n }\n }\n\n const watchers = watchDirs.map((dir) =>\n watch(dir, { recursive: true }, (_event, filename) => {\n if (!filename || filename.split(/[\\\\/]/).includes(\"node_modules\")) return;\n clearTimeout(pending);\n pending = setTimeout(() => {\n void restart();\n }, 100);\n }),\n );\n const stop = () => {\n stopped = true;\n clearTimeout(pending);\n for (const watcher of watchers) watcher.close();\n child.kill();\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n process.off(\"exit\", stop);\n };\n const onSignal = () => {\n stop();\n process.exit(0);\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n process.on(\"exit\", stop);\n console.log(`\\n👀 Watching for changes in: ${watchDirs.join(\", \")}`);\n return { stop };\n}\n"],"mappings":";;;;;AAiBA,eAAe,aACb,SACA,OACA,aACA;CACA,IAAI;CACJ,IAAI,QAAQ,SAAS,KAAA,GACnB,OAAO,QAAQ;MACV,IAAI,QAAQ,IAAI,SAAS,KAAA,KAAa,QAAQ,IAAI,SAAS,IAChE,OAAO,OAAO,QAAQ,IAAI,IAAI;MAE9B,OAAO;CAET,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAChD,MAAM,IAAI,MACR,iBAAiB,KAAK,8CACxB;CAGF,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;EACf;CACF;CAEA,MAAM,WAAW,UAAU,KAAK,QAC9B,MAAM,KAAK,EAAE,WAAW,KAAK,IAAI,QAAQ,aAAa;EACpD,IAAI,CAAC,YAAY,SAAS,MAAM,OAAO,CAAC,CAAC,SAAS,cAAc,GAAG;EACnE,aAAa,OAAO;EACpB,UAAU,iBAAiB;GACzB,QAAa;EACf,GAAG,GAAG;CACR,CAAC,CACH;CACA,MAAM,aAAa;EACjB,UAAU;EACV,aAAa,OAAO;EACpB,KAAK,MAAM,WAAW,UAAU,QAAQ,MAAM;EAC9C,MAAM,KAAK;EACX,QAAQ,IAAI,UAAU,QAAQ;EAC9B,QAAQ,IAAI,WAAW,QAAQ;EAC/B,QAAQ,IAAI,QAAQ,IAAI;CAC1B;CACA,MAAM,iBAAiB;EACrB,KAAK;EACL,QAAQ,KAAK,CAAC;CAChB;CACA,QAAQ,GAAG,UAAU,QAAQ;CAC7B,QAAQ,GAAG,WAAW,QAAQ;CAC9B,QAAQ,GAAG,QAAQ,IAAI;CACvB,QAAQ,IAAI,iCAAiC,UAAU,KAAK,IAAI,GAAG;CACnE,OAAO,EAAE,KAAK;AAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brickkit/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "CLI and server engine for Brick-TS",
5
5
  "keywords": [
6
6
  "typescript",
@@ -61,7 +61,7 @@
61
61
  "format:check": "oxfmt --check ."
62
62
  },
63
63
  "dependencies": {
64
- "@brickkit/core": "^0.4.0",
64
+ "@brickkit/core": "^0.4.1",
65
65
  "@sinclair/typebox": "^0.34.52",
66
66
  "commander": "^15.0.0",
67
67
  "elysia": "2.0.0-beta.29"