@routecraft/cli 0.3.0-canary.9 → 0.3.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/README.md +18 -23
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/run-265W63J5.js +2 -0
- package/dist/run-265W63J5.js.map +1 -0
- package/package.json +4 -3
- package/dist/run-IJNIE5VV.js +0 -2
- package/dist/run-IJNIE5VV.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @routecraft/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run RouteCraft capabilities from the terminal.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -16,17 +16,13 @@ pnpm add -g @routecraft/cli
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
Run a RouteCraft route file:
|
|
20
|
-
|
|
21
19
|
```bash
|
|
22
|
-
craft run
|
|
20
|
+
craft run my-capability.ts
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
The CLI
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- Keep the process running for continuous processing
|
|
29
|
-
- Handle graceful shutdown on SIGINT/SIGTERM
|
|
23
|
+
The CLI loads your capability file, starts all registered capabilities, and keeps the process running. It handles graceful shutdown on `SIGINT`/`SIGTERM` and automatically loads a `.env` file from the current directory if present.
|
|
24
|
+
|
|
25
|
+
TypeScript files are supported directly -- no build step required.
|
|
30
26
|
|
|
31
27
|
## Options
|
|
32
28
|
|
|
@@ -34,36 +30,36 @@ The CLI will:
|
|
|
34
30
|
craft run [options] <file>
|
|
35
31
|
|
|
36
32
|
Options:
|
|
37
|
-
-
|
|
38
|
-
-
|
|
33
|
+
--log-level <level> Log level: info, warn, error, silent (default: warn)
|
|
34
|
+
--log-file <path> Write logs to a file instead of stdout
|
|
35
|
+
-h, --help Display help information
|
|
36
|
+
-V, --version Display version information
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
##
|
|
42
|
-
|
|
43
|
-
The CLI automatically loads environment variables from a `.env` file in the current directory if present.
|
|
44
|
-
|
|
45
|
-
## Example Route File
|
|
39
|
+
## Example
|
|
46
40
|
|
|
47
41
|
```typescript
|
|
48
|
-
//
|
|
42
|
+
// capabilities/timer-ping.ts
|
|
49
43
|
import { craft, timer, log } from '@routecraft/routecraft';
|
|
50
44
|
|
|
51
45
|
export default craft()
|
|
52
|
-
.id('timer-
|
|
46
|
+
.id('timer-ping')
|
|
53
47
|
.from(timer({ intervalMs: 1000 }))
|
|
54
48
|
.transform((ex) => ({ timestamp: Date.now() }))
|
|
55
49
|
.to(log());
|
|
56
50
|
```
|
|
57
51
|
|
|
58
|
-
Run it:
|
|
59
|
-
|
|
60
52
|
```bash
|
|
61
|
-
craft run
|
|
53
|
+
craft run capabilities/timer-ping.ts
|
|
62
54
|
```
|
|
63
55
|
|
|
56
|
+
## Use as an MCP Server
|
|
57
|
+
|
|
58
|
+
The CLI is the entry point for exposing your capabilities to Claude Desktop, Cursor, and other MCP clients. See the [`@routecraft/ai`](https://www.npmjs.com/package/@routecraft/ai) package for setup instructions.
|
|
59
|
+
|
|
64
60
|
## Documentation
|
|
65
61
|
|
|
66
|
-
For
|
|
62
|
+
For full guides and examples, visit [routecraft.dev](https://routecraft.dev).
|
|
67
63
|
|
|
68
64
|
## License
|
|
69
65
|
|
|
@@ -74,4 +70,3 @@ Apache-2.0
|
|
|
74
70
|
- [Documentation](https://routecraft.dev)
|
|
75
71
|
- [GitHub Repository](https://github.com/routecraftjs/routecraft)
|
|
76
72
|
- [Issue Tracker](https://github.com/routecraftjs/routecraft/issues)
|
|
77
|
-
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var[
|
|
2
|
+
var[i,l]=process.version.slice(1).split(".").map(Number);i>18||i===18&&l>=19||(console.error(`[routecraft] Node.js ${process.version} is not supported. Routecraft requires Node.js 18.19.0 or later (e.g. 20 or 22). Please upgrade Node or configure your MCP client to use a newer Node.`),process.exit(1));var p=process.argv.slice(2).some(e=>!e.startsWith("-")&&e.endsWith(".ts"));if(p&&!process.env.CRAFT_TSX_LOADER){let{execFileSync:e}=await import('child_process'),{createRequire:s}=await import('module'),o=s(import.meta.url).resolve("tsx/esm");try{e(process.execPath,["--import",o,...process.execArgv,process.argv[1],...process.argv.slice(2)],{stdio:"inherit",env:{...process.env,CRAFT_TSX_LOADER:"1"}}),process.exit(0);}catch(t){process.exit(t.status??1);}}var{Command:m}=await import('commander'),r=new m;r.name("craft").description("A modern routing framework for TypeScript").version("0.3.0").option("--log-level <level>","Log level (e.g. info, warn, error, silent to disable)").option("--log-file <path>","Write logs to a file (keeps stdout clear for MCP stdio)").showSuggestionAfterError().showHelpAfterError().exitOverride(e=>{e.code==="commander.unknownCommand"&&process.exit(0);});process.argv.length<=2&&r.help({error:false});r.command("run").description("Run routes from a single TypeScript/JavaScript file").argument("<file>","Path to a file containing routes").option("--env <path>","Load environment variables from a .env file (default: .env)").action(async(e,s)=>{let o=r.opts();o.logLevel!==void 0&&(process.env.LOG_LEVEL=o.logLevel,process.env.CRAFT_LOG_LEVEL=o.logLevel),o.logFile!==void 0&&(process.env.LOG_FILE=o.logFile,process.env.CRAFT_LOG_FILE=o.logFile);let{loadEnvFile:t}=await import('./util-5TR67ZZL.js');s.env!==void 0?t(s.env):t();let{runCommand:a}=await import('./run-265W63J5.js'),n=await a(e);if(!n.success){n.message&&console.error(n.message);let c=n.code??1;setImmediate(()=>process.exit(c));return}});r.parse();//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["major","minor","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["major","minor","hasTSFile","arg","execFileSync","createRequire","tsxEsmPath","err","Command","program","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AC,CAAY,CAAA,CAAI,MAAM,OAAO,oBAAW,CAAA,CAC5CF,CAAAA,CAAQ,GAAA,GAAQ,OAClBE,CAAAA,CAAYF,CAAAA,CAAQ,GAAG,CAAA,CAEvBE,GAAY,CAGd,GAAM,CAAE,UAAA,CAAAC,CAAW,CAAA,CAAI,MAAM,OAAO,mBAAU,CAAA,CACxCC,CAAAA,CAAS,MAAMD,CAAAA,CAAWJ,CAAQ,CAAA,CACxC,GAAI,CAACK,CAAAA,CAAO,QAAS,CACfA,CAAAA,CAAO,OAAA,EAET,OAAA,CAAQ,MAAMA,CAAAA,CAAO,OAAO,CAAA,CAG9B,IAAMC,EAAOD,CAAAA,CAAO,IAAA,EAAQ,CAAA,CAC5B,YAAA,CAAa,IAAM,OAAA,CAAQ,IAAA,CAAKC,CAAI,CAAC,EACrC,MACF,CAIF,CAAC,CAAA,CAGHP,EAAQ,KAAA,EAAM","file":"index.js","sourcesContent":["#!/usr/bin/env node\n\n/**\n * Routecraft CLI — single entry point.\n *\n * 1. Check Node version (Pino 10 needs Node 18.19+)\n * 2. Define program and parse; log options are global and applied before lazy-loading run/util (which load the logger)\n */\n\n// ── 1. Node version gate ────────────────────────────────────────────\nconst [major, minor] = process.version.slice(1).split(\".\").map(Number) as [\n number,\n number,\n];\n\nif (!(major > 18 || (major === 18 && minor >= 19))) {\n // eslint-disable-next-line no-console\n console.error(\n `[routecraft] Node.js ${process.version} is not supported. ` +\n `Routecraft requires Node.js 18.19.0 or later (e.g. 20 or 22). ` +\n `Please upgrade Node or configure your MCP client to use a newer Node.`,\n );\n process.exit(1);\n}\n\n// ── 2. Re-exec with tsx loader if a .ts file is being run ───────────────────\n// Node's native --experimental-strip-types does not handle extensionless\n// imports or .js-to-.ts resolution. tsx (via --import tsx/esm) does.\n// We set CRAFT_TSX_LOADER=1 before re-execing to avoid an infinite loop.\nconst hasTSFile = process.argv\n .slice(2)\n .some((arg) => !arg.startsWith(\"-\") && arg.endsWith(\".ts\"));\n\nif (hasTSFile && !process.env[\"CRAFT_TSX_LOADER\"]) {\n const { execFileSync } = await import(\"node:child_process\");\n const { createRequire } = await import(\"node:module\");\n // Resolve tsx/esm relative to the CLI package so it works regardless of CWD\n const tsxEsmPath = createRequire(import.meta.url).resolve(\"tsx/esm\");\n try {\n execFileSync(\n process.execPath,\n [\n \"--import\",\n tsxEsmPath,\n ...process.execArgv,\n process.argv[1]!,\n ...process.argv.slice(2),\n ],\n { stdio: \"inherit\", env: { ...process.env, CRAFT_TSX_LOADER: \"1\" } },\n );\n process.exit(0);\n } catch (err: unknown) {\n process.exit(\n (err as NodeJS.ErrnoException & { status?: number }).status ?? 1,\n );\n }\n}\n\n// ── 3. CLI definition (only Commander; run/util are lazy-loaded so logger sees env) ─\nconst { Command } = await import(\"commander\");\nconst program = new Command();\n\nprogram\n .name(\"craft\")\n .description(\"A modern routing framework for TypeScript\")\n .version(\"0.3.0\")\n .option(\n \"--log-level <level>\",\n \"Log level (e.g. info, warn, error, silent to disable)\",\n )\n .option(\n \"--log-file <path>\",\n \"Write logs to a file (keeps stdout clear for MCP stdio)\",\n )\n .showSuggestionAfterError()\n .showHelpAfterError()\n .exitOverride((err) => {\n if (err.code === \"commander.unknownCommand\") {\n process.exit(0);\n }\n });\n\n// Show help by default if no arguments provided\nif (process.argv.length <= 2) {\n program.help({ error: false });\n}\n\n/**\n * The 'run' command executes routes from a single file.\n *\n * Example:\n * craft run ./my-routes.ts\n */\nprogram\n .command(\"run\")\n .description(\"Run routes from a single TypeScript/JavaScript file\")\n .argument(\"<file>\", \"Path to a file containing routes\")\n .option(\n \"--env <path>\",\n \"Load environment variables from a .env file (default: .env)\",\n )\n .action(async (filePath, options) => {\n // Apply global log options to env before any import that creates the logger\n const globalOpts = program.opts();\n if (globalOpts[\"logLevel\"] !== undefined) {\n process.env[\"LOG_LEVEL\"] = globalOpts[\"logLevel\"];\n process.env[\"CRAFT_LOG_LEVEL\"] = globalOpts[\"logLevel\"];\n }\n if (globalOpts[\"logFile\"] !== undefined) {\n process.env[\"LOG_FILE\"] = globalOpts[\"logFile\"];\n process.env[\"CRAFT_LOG_FILE\"] = globalOpts[\"logFile\"];\n }\n\n const { loadEnvFile } = await import(\"./util.js\");\n if (options.env !== undefined) {\n loadEnvFile(options.env);\n } else {\n loadEnvFile();\n }\n\n const { runCommand } = await import(\"./run.js\");\n const result = await runCommand(filePath);\n if (!result.success) {\n if (result.message) {\n // eslint-disable-next-line no-console\n console.error(result.message);\n }\n // Defer exit so pino/sonic-boom can finish initializing and avoid \"sonic boom is not ready yet\"\n const code = result.code ?? 1;\n setImmediate(() => process.exit(code));\n return;\n }\n // Don't call process.exit() — let the event loop drain naturally.\n // process.exit() triggers C++ static destructors that race with ONNX\n // Runtime cleanup (onnxruntime#25038: \"mutex lock failed\").\n });\n\n// Parse the command line arguments and execute the appropriate command\nprogram.parse();\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'./chunk-MEHNJKKK.js';import {resolve,extname}from'path';import {logger,ContextBuilder,isRouteBuilder,isRouteDefinition}from'@routecraft/routecraft';var l=[".mjs",".js",".cjs",".ts"];async function C(t){let e=resolve(process.cwd(),t),o=extname(e);if(!l.includes(o))return {success:false,code:1,message:`Error: Only the following file types are supported: ${l.join(", ")}`};try{let s=await import(e),u=s.craftConfig;logger.info(`Loading file: ${e}`);let n=new ContextBuilder;u&&(logger.info("Found craftConfig export, applying configuration"),n.with(u));let i=R(n,s.default);if(!i.success)return i;let a=await n.build();return b(a),await a.start(),{success:!0}}catch(s){return s instanceof Error?(logger.error(`Failed to run ${e}: ${s.message}`),{success:false,code:1,message:s.message}):(logger.error(`Failed to run ${e}: Unknown error occurred`),{success:false,code:1,message:"Unknown error"})}}function R(t,e){return e?isRouteBuilder(e)?(t.routes(e),logger.info("Loaded single RouteBuilder from default export"),{success:true}):isRouteDefinition(e)?(t.routes(e),logger.info("Loaded single route from default export"),{success:true}):Array.isArray(e)?e.every(o=>isRouteBuilder(o)||isRouteDefinition(o))?(e.forEach(o=>t.routes(o)),logger.info(`Loaded ${e.length} routes from default export array`),{success:true}):(logger.error("All items in default export array must be RouteDefinition or RouteBuilder"),{success:false,code:1,message:"Invalid items in default export array"}):(logger.error("Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those."),{success:false,code:1,message:"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those."}):(logger.error("No default export found. Expected routes as default export."),{success:false,code:1,message:"No default export found"})}export{C as runCommand};//# sourceMappingURL=run-265W63J5.js.map
|
|
2
|
+
//# sourceMappingURL=run-265W63J5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/run.ts"],"names":["SUPPORTED_EXTENSIONS","runCommand","filePath","absFilePath","resolve","ext","extname","module","craftConfig","logger","contextBuilder","ContextBuilder","configured","configureRoutes","context","registerContextSignalHandlers","error","defaultExport","isRouteBuilder","isRouteDefinition","item","routeOrBuilder"],"mappings":"mKAYA,IAAMA,CAAAA,CAAuB,CAAC,MAAA,CAAQ,KAAA,CAAO,MAAA,CAAQ,KAAK,CAAA,CAM1D,eAAsBC,CAAAA,CAAWC,CAAAA,CAAsC,CACrE,IAAMC,EAAcC,OAAAA,CAAQ,OAAA,CAAQ,GAAA,EAAI,CAAGF,CAAQ,CAAA,CAC7CG,CAAAA,CAAMC,OAAAA,CAAQH,CAAW,CAAA,CAG/B,GACE,CAACH,CAAAA,CAAqB,QAAA,CAASK,CAA4C,CAAA,CAE3E,OAAO,CACL,OAAA,CAAS,KAAA,CACT,IAAA,CAAM,CAAA,CACN,OAAA,CAAS,CAAA,oDAAA,EAAuDL,CAAAA,CAAqB,IAAA,CAAK,IAAI,CAAC,CAAA,CACjG,CAAA,CAGF,GAAI,CAGF,IAAMO,EAAS,MAAM,OAAOJ,CAAAA,CAAAA,CACtBK,CAAAA,CAAcD,CAAAA,CAAO,WAAA,CAE3BE,MAAAA,CAAO,IAAA,CAAK,CAAA,cAAA,EAAiBN,CAAW,CAAA,CAAE,CAAA,C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A,CACtDR,MAAAA,CAAO,IAAA,CAAK,yCAAyC,CAAA,CAC9C,CAAE,OAAA,CAAS,IAAK,CAAA,EAIrB,MAAM,OAAA,CAAQQ,CAAa,CAAA,CAG1BA,CAAAA,CAAc,KAAA,CACZG,CAAAA,EAASF,cAAAA,CAAeE,CAAI,CAAA,EAAKD,iBAAAA,CAAkBC,CAAI,CAC1D,CAAA,EAYFH,CAAAA,CAAc,OAAA,CAASI,CAAAA,EACrBX,CAAAA,CAAe,MAAA,CACbW,CACF,CACF,CAAA,CACAZ,MAAAA,CAAO,IAAA,CACL,CAAA,OAAA,EAAUQ,CAAAA,CAAc,MAAM,CAAA,iCAAA,CAChC,CAAA,CACO,CAAE,OAAA,CAAS,IAAK,CAAA,GAlBrBR,OAAO,KAAA,CACL,2EACF,CAAA,CACO,CACL,OAAA,CAAS,KAAA,CACT,IAAA,CAAM,CAAA,CACN,OAAA,CAAS,uCACX,CAAA,CAAA,EAeJA,MAAAA,CAAO,KAAA,CACL,qFACF,CAAA,CACO,CACL,QAAS,KAAA,CACT,IAAA,CAAM,CAAA,CACN,OAAA,CACE,qFACJ,CAAA,CAAA,EAvDEA,MAAAA,CAAO,KAAA,CAAM,6DAA6D,CAAA,CACnE,CAAE,OAAA,CAAS,KAAA,CAAO,IAAA,CAAM,CAAA,CAAG,OAAA,CAAS,yBAA0B,CAAA,CAuDzE","file":"run-265W63J5.js","sourcesContent":["import { resolve, extname } from \"node:path\";\nimport {\n ContextBuilder,\n type CraftConfig,\n isRouteBuilder,\n isRouteDefinition,\n logger,\n type RouteBuilder,\n type RouteDefinition,\n} from \"@routecraft/routecraft\";\nimport { registerContextSignalHandlers } from \"./util\";\n\nconst SUPPORTED_EXTENSIONS = [\".mjs\", \".js\", \".cjs\", \".ts\"] as const;\n\ntype RunResult =\n | { success: true }\n | { success: false; code?: number; message: string };\n\nexport async function runCommand(filePath: string): Promise<RunResult> {\n const absFilePath = resolve(process.cwd(), filePath);\n const ext = extname(absFilePath);\n\n // Validate file extension\n if (\n !SUPPORTED_EXTENSIONS.includes(ext as (typeof SUPPORTED_EXTENSIONS)[number])\n ) {\n return {\n success: false,\n code: 1,\n message: `Error: Only the following file types are supported: ${SUPPORTED_EXTENSIONS.join(\", \")}`,\n };\n }\n\n try {\n // Load the module (CLI already set LOG_LEVEL / LOG_FILE from argv in index.ts).\n // Logger uses env first; context will apply craftConfig.log when built (env wins if set).\n const module = await import(absFilePath);\n const craftConfig = module.craftConfig as CraftConfig | undefined;\n\n logger.info(`Loading file: ${absFilePath}`);\n\n // Create context builder\n const contextBuilder = new ContextBuilder();\n\n // Apply craftConfig (routes, plugins, etc.); context applies config.log when built.\n if (craftConfig) {\n logger.info(\"Found craftConfig export, applying configuration\");\n contextBuilder.with(craftConfig);\n }\n\n // Handle routes from the default export\n const configured = configureRoutes(contextBuilder, module.default);\n if (!configured.success) {\n return configured;\n }\n\n // Build and start the context\n const context = await contextBuilder.build();\n registerContextSignalHandlers(context);\n await context.start();\n\n return { success: true };\n } catch (error: unknown) {\n if (error instanceof Error) {\n logger.error(`Failed to run ${absFilePath}: ${error.message}`);\n return { success: false, code: 1, message: error.message };\n }\n logger.error(`Failed to run ${absFilePath}: Unknown error occurred`);\n return { success: false, code: 1, message: \"Unknown error\" };\n }\n}\n\nfunction configureRoutes(\n contextBuilder: InstanceType<typeof ContextBuilder>,\n defaultExport: unknown,\n): RunResult {\n if (!defaultExport) {\n logger.error(\"No default export found. Expected routes as default export.\");\n return { success: false, code: 1, message: \"No default export found\" };\n }\n\n // Handle single RouteBuilder or RouteDefinition (brand-based guards for cross-instance)\n if (isRouteBuilder(defaultExport)) {\n contextBuilder.routes(defaultExport as RouteBuilder<unknown>);\n logger.info(\"Loaded single RouteBuilder from default export\");\n return { success: true };\n }\n\n if (isRouteDefinition(defaultExport)) {\n contextBuilder.routes(defaultExport as RouteDefinition);\n logger.info(\"Loaded single route from default export\");\n return { success: true };\n }\n\n // Handle array of routes\n if (Array.isArray(defaultExport)) {\n // Check each item, prioritizing RouteBuilder check\n if (\n !defaultExport.every(\n (item) => isRouteBuilder(item) || isRouteDefinition(item),\n )\n ) {\n logger.error(\n \"All items in default export array must be RouteDefinition or RouteBuilder\",\n );\n return {\n success: false,\n code: 1,\n message: \"Invalid items in default export array\",\n };\n }\n\n defaultExport.forEach((routeOrBuilder) =>\n contextBuilder.routes(\n routeOrBuilder as RouteDefinition | RouteBuilder<unknown>,\n ),\n );\n logger.info(\n `Loaded ${defaultExport.length} routes from default export array`,\n );\n return { success: true };\n }\n\n // Invalid default export\n logger.error(\n \"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those.\",\n );\n return {\n success: false,\n code: 1,\n message:\n \"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those.\",\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routecraft/cli",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "CLI for running RouteCraft routes",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
"prepublishOnly": "pnpm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@routecraft/routecraft": "^0.
|
|
25
|
+
"@routecraft/routecraft": "^0.4.0",
|
|
26
26
|
"commander": "^14.0.3",
|
|
27
27
|
"dotenv": "^17.3.1",
|
|
28
|
-
"pino-pretty": "^13.1.3"
|
|
28
|
+
"pino-pretty": "^13.1.3",
|
|
29
|
+
"tsx": "^4.21.0"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
package/dist/run-IJNIE5VV.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {b}from'./chunk-MEHNJKKK.js';import {resolve,extname}from'path';import {logger,ContextBuilder,isRouteBuilder,isRouteDefinition}from'@routecraft/routecraft';var l=[".mjs",".js",".cjs"];async function C(t){let e=resolve(process.cwd(),t),o=extname(e);if(!l.includes(o))return {success:false,code:1,message:`Error: Only the following file types are supported: ${l.join(", ")}`};try{let s=await import(e),u=s.craftConfig;logger.info(`Loading file: ${e}`);let n=new ContextBuilder;u&&(logger.info("Found craftConfig export, applying configuration"),n.with(u));let i=R(n,s.default);if(!i.success)return i;let a=await n.build();return b(a),await a.start(),{success:!0}}catch(s){return s instanceof Error?(logger.error(`Failed to run ${e}: ${s.message}`),{success:false,code:1,message:s.message}):(logger.error(`Failed to run ${e}: Unknown error occurred`),{success:false,code:1,message:"Unknown error"})}}function R(t,e){return e?isRouteBuilder(e)?(t.routes(e),logger.info("Loaded single RouteBuilder from default export"),{success:true}):isRouteDefinition(e)?(t.routes(e),logger.info("Loaded single route from default export"),{success:true}):Array.isArray(e)?e.every(o=>isRouteBuilder(o)||isRouteDefinition(o))?(e.forEach(o=>t.routes(o)),logger.info(`Loaded ${e.length} routes from default export array`),{success:true}):(logger.error("All items in default export array must be RouteDefinition or RouteBuilder"),{success:false,code:1,message:"Invalid items in default export array"}):(logger.error("Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those."),{success:false,code:1,message:"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those."}):(logger.error("No default export found. Expected routes as default export."),{success:false,code:1,message:"No default export found"})}export{C as runCommand};//# sourceMappingURL=run-IJNIE5VV.js.map
|
|
2
|
-
//# sourceMappingURL=run-IJNIE5VV.js.map
|
package/dist/run-IJNIE5VV.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/run.ts"],"names":["SUPPORTED_EXTENSIONS","runCommand","filePath","absFilePath","resolve","ext","extname","module","craftConfig","logger","contextBuilder","ContextBuilder","configured","configureRoutes","context","registerContextSignalHandlers","error","defaultExport","isRouteBuilder","isRouteDefinition","item","routeOrBuilder"],"mappings":"mKAYA,IAAMA,CAAAA,CAAuB,CAAC,MAAA,CAAQ,KAAA,CAAO,MA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IAAA,CAAM,CAAA,CACN,OAAA,CACE,qFACJ,CAAA,CAAA,EAvDEA,MAAAA,CAAO,KAAA,CAAM,6DAA6D,CAAA,CACnE,CAAE,OAAA,CAAS,KAAA,CAAO,IAAA,CAAM,CAAA,CAAG,OAAA,CAAS,yBAA0B,CAAA,CAuDzE","file":"run-IJNIE5VV.js","sourcesContent":["import { resolve, extname } from \"node:path\";\nimport {\n ContextBuilder,\n type CraftConfig,\n isRouteBuilder,\n isRouteDefinition,\n logger,\n type RouteBuilder,\n type RouteDefinition,\n} from \"@routecraft/routecraft\";\nimport { registerContextSignalHandlers } from \"./util\";\n\nconst SUPPORTED_EXTENSIONS = [\".mjs\", \".js\", \".cjs\"] as const;\n\ntype RunResult =\n | { success: true }\n | { success: false; code?: number; message: string };\n\nexport async function runCommand(filePath: string): Promise<RunResult> {\n const absFilePath = resolve(process.cwd(), filePath);\n const ext = extname(absFilePath);\n\n // Validate file extension\n if (\n !SUPPORTED_EXTENSIONS.includes(ext as (typeof SUPPORTED_EXTENSIONS)[number])\n ) {\n return {\n success: false,\n code: 1,\n message: `Error: Only the following file types are supported: ${SUPPORTED_EXTENSIONS.join(\", \")}`,\n };\n }\n\n try {\n // Load the module (CLI already set LOG_LEVEL / LOG_FILE from argv in index.ts).\n // Logger uses env first; context will apply craftConfig.log when built (env wins if set).\n const module = await import(absFilePath);\n const craftConfig = module.craftConfig as CraftConfig | undefined;\n\n logger.info(`Loading file: ${absFilePath}`);\n\n // Create context builder\n const contextBuilder = new ContextBuilder();\n\n // Apply craftConfig (routes, plugins, etc.); context applies config.log when built.\n if (craftConfig) {\n logger.info(\"Found craftConfig export, applying configuration\");\n contextBuilder.with(craftConfig);\n }\n\n // Handle routes from the default export\n const configured = configureRoutes(contextBuilder, module.default);\n if (!configured.success) {\n return configured;\n }\n\n // Build and start the context\n const context = await contextBuilder.build();\n registerContextSignalHandlers(context);\n await context.start();\n\n return { success: true };\n } catch (error: unknown) {\n if (error instanceof Error) {\n logger.error(`Failed to run ${absFilePath}: ${error.message}`);\n return { success: false, code: 1, message: error.message };\n }\n logger.error(`Failed to run ${absFilePath}: Unknown error occurred`);\n return { success: false, code: 1, message: \"Unknown error\" };\n }\n}\n\nfunction configureRoutes(\n contextBuilder: InstanceType<typeof ContextBuilder>,\n defaultExport: unknown,\n): RunResult {\n if (!defaultExport) {\n logger.error(\"No default export found. Expected routes as default export.\");\n return { success: false, code: 1, message: \"No default export found\" };\n }\n\n // Handle single RouteBuilder or RouteDefinition (brand-based guards for cross-instance)\n if (isRouteBuilder(defaultExport)) {\n contextBuilder.routes(defaultExport as RouteBuilder<unknown>);\n logger.info(\"Loaded single RouteBuilder from default export\");\n return { success: true };\n }\n\n if (isRouteDefinition(defaultExport)) {\n contextBuilder.routes(defaultExport as RouteDefinition);\n logger.info(\"Loaded single route from default export\");\n return { success: true };\n }\n\n // Handle array of routes\n if (Array.isArray(defaultExport)) {\n // Check each item, prioritizing RouteBuilder check\n if (\n !defaultExport.every(\n (item) => isRouteBuilder(item) || isRouteDefinition(item),\n )\n ) {\n logger.error(\n \"All items in default export array must be RouteDefinition or RouteBuilder\",\n );\n return {\n success: false,\n code: 1,\n message: \"Invalid items in default export array\",\n };\n }\n\n defaultExport.forEach((routeOrBuilder) =>\n contextBuilder.routes(\n routeOrBuilder as RouteDefinition | RouteBuilder<unknown>,\n ),\n );\n logger.info(\n `Loaded ${defaultExport.length} routes from default export array`,\n );\n return { success: true };\n }\n\n // Invalid default export\n logger.error(\n \"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those.\",\n );\n return {\n success: false,\n code: 1,\n message:\n \"Invalid default export. Expected: RouteDefinition, RouteBuilder, or array of those.\",\n };\n}\n"]}
|