@routecraft/cli 0.2.0 → 0.3.0-canary.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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/run-7VWZQA3U.js +2 -0
- package/dist/run-7VWZQA3U.js.map +1 -0
- package/package.json +2 -2
- package/dist/run-QPVX635B.js +0 -2
- package/dist/run-QPVX635B.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var[
|
|
2
|
+
var[t,c]=process.version.slice(1).split(".").map(Number);t>18||t===18&&c>=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{Command:p}=await import('commander'),o=new p;o.name("craft").description("A modern routing framework for TypeScript").version("0.3.0-canary.2").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(n=>{n.code==="commander.unknownCommand"&&process.exit(0);});process.argv.length<=2&&o.help({error:false});o.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(n,s)=>{let e=o.opts();e.logLevel!==void 0&&(process.env.LOG_LEVEL=e.logLevel,process.env.CRAFT_LOG_LEVEL=e.logLevel),e.logFile!==void 0&&(process.env.LOG_FILE=e.logFile,process.env.CRAFT_LOG_FILE=e.logFile);let{loadEnvFile:i}=await import('./util-Q5GDRTSI.js');s.env!==void 0?i(s.env):i();let{runCommand:a}=await import('./run-7VWZQA3U.js'),r=await a(n);if(!r.success){r.message&&console.error(r.message);let l=r.code??1;setImmediate(()=>process.exit(l));return}});o.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","Command","program","err","filePath","options","globalOpts","loadEnvFile","runCommand","result","code"],"mappings":";AAUA,GAAM,CAACA,EAAOC,CAAK,CAAA,CAAI,QAAQ,OAAA,CAAQ,KAAA,CAAM,CAAC,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,CAAI,MAAM,CAAA,CAK/DD,CAAAA,CAAQ,IAAOA,CAAAA,GAAU,EAAA,EAAMC,CAAAA,EAAS,EAAA,GAE5C,OAAA,CAAQ,KAAA,CACN,wBAAwB,OAAA,CAAQ,OAAO,wJAGzC,CAAA,CACA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA,CAIhB,GAAM,CAAE,OAAA,CAAAC,CAAQ,EAAI,MAAM,OAAO,WAAW,CAAA,CACtCC,CAAAA,CAAU,IAAID,CAAAA,CAEpBC,CAAAA,CACG,IAAA,CAAK,OAAO,CAAA,CACZ,WAAA,CAAY,2CAA2C,CAAA,CACvD,OAAA,CAAQ,gBAAgB,CAAA,CACxB,MAAA,CACC,sBACA,uDACF,CAAA,CACC,OACC,mBAAA,CACA,yDACF,EACC,wBAAA,EAAyB,CACzB,oBAAmB,CACnB,YAAA,CAAcC,GAAQ,CACjBA,CAAAA,CAAI,IAAA,GAAS,0BAAA,EACf,OAAA,CAAQ,IAAA,CAAK,CAAC,EAElB,CAAC,EAGC,OAAA,CAAQ,IAAA,CAAK,QAAU,CAAA,EACzBD,CAAAA,CAAQ,IAAA,CAAK,CAAE,KAAA,CAAO,KAAM,CAAC,CAAA,CAS/BA,CAAAA,CACG,QAAQ,KAAK,CAAA,CACb,YAAY,qDAAqD,CAAA,CACjE,QAAA,CAAS,QAAA,CAAU,kCAAkC,CAAA,CACrD,OACC,cAAA,CACA,6DACF,EACC,MAAA,CAAO,MAAOE,EAAUC,CAAAA,GAAY,CAEnC,IAAMC,CAAAA,CAAaJ,CAAAA,CAAQ,MAAK,CAC5BI,CAAAA,CAAW,WAAgB,MAAA,GAC7B,OAAA,CAAQ,IAAI,SAAA,CAAeA,CAAAA,CAAW,QAAA,CACtC,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAqBA,EAAW,QAAA,CAAA,CAE1CA,CAAAA,CAAW,UAAe,MAAA,GAC5B,OAAA,CAAQ,IAAI,QAAA,CAAcA,CAAAA,CAAW,OAAA,CACrC,OAAA,CAAQ,GAAA,CAAI,cAAA,CAAoBA,EAAW,OAAA,CAAA,CAG7C,GAAM,CAAE,WAAA,CAAAC,CAAY,EAAI,MAAM,OAAO,oBAAW,CAAA,CAC5CF,CAAAA,CAAQ,GAAA,GAAQ,OAClBE,CAAAA,CAAYF,CAAAA,CAAQ,GAAG,CAAA,CAEvBE,CAAAA,GAGF,GAAM,CAAE,UAAA,CAAAC,CAAW,CAAA,CAAI,aAAa,mBAAU,CAAA,CACxCC,EAAS,MAAMD,CAAAA,CAAWJ,CAAQ,CAAA,CACxC,GAAI,CAACK,CAAAA,CAAO,OAAA,CAAS,CACfA,EAAO,OAAA,EAET,OAAA,CAAQ,MAAMA,CAAAA,CAAO,OAAO,EAG9B,IAAMC,CAAAA,CAAOD,CAAAA,CAAO,IAAA,EAAQ,CAAA,CAC5B,YAAA,CAAa,IAAM,OAAA,CAAQ,IAAA,CAAKC,CAAI,CAAC,CAAA,CACrC,MACF,CACF,CAAC,CAAA,CAGHR,CAAAA,CAAQ,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. 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-canary.2\")\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 });\n\n// Parse the command line arguments and execute the appropriate command\nprogram.parse();\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'./chunk-5NEKGUV3.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-7VWZQA3U.js.map
|
|
2
|
+
//# sourceMappingURL=run-7VWZQA3U.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,MAAM,CAAA,CAMnD,eAAsBC,CAAAA,CAAWC,CAAAA,CAAsC,CACrE,IAAMC,CAAAA,CAAcC,QAAQ,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,CAG1C,IAAMO,CAAAA,CAAiB,IAAIC,cAAAA,CAGvBH,CAAAA,GACFC,MAAAA,CAAO,IAAA,CAAK,kDAAkD,CAAA,CAC9DC,CAAAA,CAAe,IAAA,CAAKF,CAAW,CAAA,CAAA,CAIjC,IAAMI,CAAAA,CAAaC,CAAAA,CAAgBH,CAAAA,CAAgBH,CAAAA,CAAO,OAAO,CAAA,CACjE,GAAI,CAACK,CAAAA,CAAW,OAAA,CACd,OAAOA,CAAAA,CAIT,IAAME,CAAAA,CAAU,MAAMJ,CAAAA,CAAe,K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AAO,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-7VWZQA3U.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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routecraft/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-canary.2",
|
|
4
4
|
"description": "CLI for running RouteCraft routes",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "pnpm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@routecraft/routecraft": "
|
|
25
|
+
"@routecraft/routecraft": "^0.3.0-canary.2",
|
|
26
26
|
"commander": "^14.0.3",
|
|
27
27
|
"dotenv": "^17.3.1"
|
|
28
28
|
},
|
package/dist/run-QPVX635B.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {b}from'./chunk-5NEKGUV3.js';import {resolve,extname}from'path';import {configureLogger,logger,ContextBuilder,isRouteBuilder,isRouteDefinition}from'@routecraft/routecraft';var g=[".mjs",".js",".cjs"];async function E(n){let e=resolve(process.cwd(),n),o=extname(e);if(o===".ts"||o===".tsx")return {success:false,code:1,message:"TypeScript files are not supported by 'craft run'. Compile to .js or use .mjs/.js/.cjs."};if(!g.includes(o))return {success:false,code:1,message:`Error: Only the following file types are supported: ${g.join(", ")}`};try{let s=await import(e),t=s.craftConfig,u=process.env.LOG_FILE??process.env.CRAFT_LOG_FILE??t?.log?.file,m={level:process.env.LOG_LEVEL??process.env.CRAFT_LOG_LEVEL??t?.log?.level??"warn",...u!==void 0&&{logFile:u},...t?.log?.redact!==void 0&&{redact:t.log.redact}};configureLogger(m),logger.info(`Loading file: ${e}`);let i=new ContextBuilder;t&&(logger.info("Found craftConfig export, applying configuration"),i.with(t));let a=w(i,s.default);if(!a.success)return a;let c=await i.build();return b(c),await c.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 w(n,e){return e?isRouteBuilder(e)?(n.routes(e),logger.info("Loaded single RouteBuilder from default export"),{success:true}):isRouteDefinition(e)?(n.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=>n.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{E as runCommand};//# sourceMappingURL=run-QPVX635B.js.map
|
|
2
|
-
//# sourceMappingURL=run-QPVX635B.js.map
|
package/dist/run-QPVX635B.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/run.ts"],"names":["SUPPORTED_EXTENSIONS","runCommand","filePath","absFilePath","resolve","ext","extname","module","craftConfig","logFile","mergedLog","configureLogger","logger","contextBuilder","ContextBuilder","configured","configureRoutes","context","registerContextSignalHandlers","error","defaultExport","isRouteBuilder","isRouteDefinition","item","routeOrBuilder"],"mappings":"mLAaA,IAAMA,CAAAA,CAAuB,CAAC,OAAQ,KAAA,CAAO,MAAM,CAAA,CAMnD,eAAsBC,EAAWC,CAAAA,CAAsC,CACrE,IAAMC,CAAAA,CAAcC,QAAQ,OAAA,CAAQ,GAAA,GAAOF,CAAQ,CAAA,CAC7CG,EAAMC,OAAAA,CAAQH,CAAW,CAAA,CAG/B,GAAIE,IAAQ,KAAA,EAASA,CAAAA,GAAQ,MAAA,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CACO,CAAE,OAAA,CAAS,IAAK,CAAA,GAlBrBR,MAAAA,CAAO,KAAA,CACL,2EACF,EACO,CACL,OAAA,CAAS,KAAA,CACT,IAAA,CAAM,EACN,OAAA,CAAS,uCACX,CAAA,CAAA,EAeJA,MAAAA,CAAO,MACL,qFACF,CAAA,CACO,CACL,OAAA,CAAS,MACT,IAAA,CAAM,CAAA,CACN,OAAA,CACE,qFACJ,IAvDEA,MAAAA,CAAO,KAAA,CAAM,6DAA6D,CAAA,CACnE,CAAE,OAAA,CAAS,KAAA,CAAO,KAAM,CAAA,CAAG,OAAA,CAAS,yBAA0B,CAAA,CAuDzE","file":"run-QPVX635B.js","sourcesContent":["import { resolve, extname } from \"node:path\";\nimport {\n ContextBuilder,\n type CraftConfig,\n configureLogger,\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 // Reject TypeScript files explicitly (before generic extension check)\n if (ext === \".ts\" || ext === \".tsx\") {\n return {\n success: false,\n code: 1,\n message:\n \"TypeScript files are not supported by 'craft run'. Compile to .js or use .mjs/.js/.cjs.\",\n };\n }\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 first so we can read craftConfig and set up logging before any logger use.\n const module = await import(absFilePath);\n const craftConfig = module.craftConfig as CraftConfig | undefined;\n\n // Merge log options: CLI env over craft config over defaults, then configure once.\n const logFile =\n process.env[\"LOG_FILE\"] ??\n process.env[\"CRAFT_LOG_FILE\"] ??\n craftConfig?.log?.file;\n const mergedLog: Parameters<typeof configureLogger>[0] = {\n level:\n process.env[\"LOG_LEVEL\"] ??\n process.env[\"CRAFT_LOG_LEVEL\"] ??\n craftConfig?.log?.level ??\n \"warn\",\n ...(logFile !== undefined && { logFile }),\n ...(craftConfig?.log?.redact !== undefined && {\n redact: craftConfig.log.redact,\n }),\n };\n configureLogger(mergedLog);\n\n logger.info(`Loading file: ${absFilePath}`);\n\n // Create context builder\n const contextBuilder = new ContextBuilder();\n\n // Apply craftConfig (routes, plugins, etc.); log was already applied above.\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"]}
|