@routecraft/cli 0.1.1 → 0.2.0-canary.10

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.
@@ -0,0 +1,2 @@
1
+ import {logger}from'@routecraft/routecraft';import {resolve}from'path';import {config}from'dotenv';function g(e){let t={quiet:true};if(e){let l=resolve(process.cwd(),e),n=config({path:l,...t});return n.error?logger.info(`Could not load .env file from ${e}: ${n.error.message}`):n.parsed&&logger.debug(`Loaded ${Object.keys(n.parsed).length} environment variables from ${e}`),n}let o=config({path:resolve(process.cwd(),".env"),...t});o.parsed?logger.debug(`Loaded ${Object.keys(o.parsed).length} environment variables from .env`):o.error&&logger.debug("No .env file found");let r=config({path:resolve(process.cwd(),".env.local"),override:true,...t});return r.parsed&&logger.debug(`Loaded ${Object.keys(r.parsed).length} environment variables from .env.local`),r.parsed?r:o.parsed?o:r}function u(e){process.on("SIGINT",async()=>{e.logger.info("Shutting down (SIGINT)..."),await e.stop(),process.exit(0);}),process.on("SIGTERM",async()=>{e.logger.info("Shutting down (SIGTERM)..."),await e.stop(),process.exit(0);}),process.on("exit",()=>{e.logger.info("Cleanup complete");});}export{g as a,u as b};//# sourceMappingURL=chunk-5NEKGUV3.js.map
2
+ //# sourceMappingURL=chunk-5NEKGUV3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util.ts"],"names":["loadEnvFile","path","dotenvOpts","envPath","resolve","result","loadDotenv","logger","envResult","envLocalResult","registerContextSignalHandlers","context"],"mappings":"mGAUO,SAASA,CAAAA,CAAYC,EAAe,CACzC,IAAMC,EAAa,CAAE,KAAA,CAAO,IAAK,CAAA,CACjC,GAAID,CAAAA,CAAM,CAER,IAAME,CAAAA,CAAUC,QAAQ,OAAA,CAAQ,GAAA,GAAOH,CAAI,CAAA,CACrCI,EAASC,MAAAA,CAAW,CAAE,KAAMH,CAAAA,CAAS,GAAGD,CAAW,CAAC,CAAA,CAE1D,OAAIG,CAAAA,CAAO,KAA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,CAAG,SAAA,CAAW,SAAY,CAChCA,CAAAA,CAAQ,MAAA,CAAO,KAAK,4BAA4B,CAAA,CAChD,MAAMA,CAAAA,CAAQ,IAAA,GACd,OAAA,CAAQ,IAAA,CAAK,CAAC,EAChB,CAAC,CAAA,CACD,QAAQ,EAAA,CAAG,MAAA,CAAQ,IAAM,CACvBA,CAAAA,CAAQ,OAAO,IAAA,CAAK,kBAAkB,EACxC,CAAC,EACH","file":"chunk-5NEKGUV3.js","sourcesContent":["import { logger, CraftContext } from \"@routecraft/routecraft\";\nimport { resolve } from \"node:path\";\nimport { config as loadDotenv } from \"dotenv\";\n\n/**\n * Loads environment variables from .env files\n *\n * @param path Optional path to .env file. If not specified, loads .env and .env.local (if they exist)\n * @returns The parsed dotenv config result\n */\nexport function loadEnvFile(path?: string) {\n const dotenvOpts = { quiet: true };\n if (path) {\n // Explicit path provided - load that file only\n const envPath = resolve(process.cwd(), path);\n const result = loadDotenv({ path: envPath, ...dotenvOpts });\n\n if (result.error) {\n logger.info(\n `Could not load .env file from ${path}: ${result.error.message}`,\n );\n } else if (result.parsed) {\n logger.debug(\n `Loaded ${Object.keys(result.parsed).length} environment variables from ${path}`,\n );\n }\n\n return result;\n }\n\n // No path provided - load .env, then .env.local (with override)\n // Load .env first\n const envResult = loadDotenv({\n path: resolve(process.cwd(), \".env\"),\n ...dotenvOpts,\n });\n if (envResult.parsed) {\n logger.debug(\n `Loaded ${Object.keys(envResult.parsed).length} environment variables from .env`,\n );\n } else if (envResult.error) {\n logger.debug(`No .env file found`);\n }\n\n // Load .env.local next, allowing it to override .env values\n const envLocalResult = loadDotenv({\n path: resolve(process.cwd(), \".env.local\"),\n override: true,\n ...dotenvOpts,\n });\n if (envLocalResult.parsed) {\n logger.debug(\n `Loaded ${Object.keys(envLocalResult.parsed).length} environment variables from .env.local`,\n );\n }\n\n // Return the most successful result:\n // - If .env.local loaded successfully, return it\n // - If .env loaded successfully but .env.local failed (doesn't exist), return .env result\n // - If both failed, return the last error (from .env.local)\n if (envLocalResult.parsed) {\n return envLocalResult;\n }\n if (envResult.parsed) {\n return envResult;\n }\n return envLocalResult;\n}\n\n/**\n * Registers SIGINT, SIGTERM, and exit handlers for a CraftContext instance.\n * Ensures graceful shutdown and logging.\n *\n * @param context The CraftContext instance\n */\nexport function registerContextSignalHandlers(\n context: InstanceType<typeof CraftContext>,\n) {\n process.on(\"SIGINT\", async () => {\n context.logger.info(\"Shutting down (SIGINT)...\");\n await context.stop();\n process.exit(0);\n });\n process.on(\"SIGTERM\", async () => {\n context.logger.info(\"Shutting down (SIGTERM)...\");\n await context.stop();\n process.exit(0);\n });\n process.on(\"exit\", () => {\n context.logger.info(\"Cleanup complete\");\n });\n}\n"]}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {Command}from'commander';import {resolve,extname}from'path';import {logger,ContextBuilder}from'@routecraft/routecraft';import {config}from'dotenv';function f(o){if(o){let s=resolve(process.cwd(),o),r=config({path:s});return r.error?logger.info(`Could not load .env file from ${o}: ${r.error.message}`):r.parsed&&logger.debug(`Loaded ${Object.keys(r.parsed).length} environment variables from ${o}`),r}let e=config({path:resolve(process.cwd(),".env")});e.parsed?logger.debug(`Loaded ${Object.keys(e.parsed).length} environment variables from .env`):e.error&&logger.debug("No .env file found");let n=config({path:resolve(process.cwd(),".env.local"),override:true});return n.parsed&&logger.debug(`Loaded ${Object.keys(n.parsed).length} environment variables from .env.local`),n.parsed?n:e.parsed?e:n}function p(o){process.on("SIGINT",async()=>{o.logger.info("Shutting down (SIGINT)..."),await o.stop(),process.exit(0);}),process.on("SIGTERM",async()=>{o.logger.info("Shutting down (SIGTERM)..."),await o.stop(),process.exit(0);}),process.on("exit",()=>{o.logger.info("Cleanup complete");});}var m=[".mjs",".js",".cjs"];async function g(o){let e=resolve(process.cwd(),o),n=extname(e);if(!m.includes(n))return {success:false,code:1,message:`Error: Only the following file types are supported: ${m.join(", ")}`};if(n===".ts"||n===".tsx")return {success:false,code:1,message:"TypeScript files are not supported by 'craft run'. Compile to .js or use .mjs/.js/.cjs."};try{logger.info(`Loading file: ${e}`);let s=await import(e),r=new ContextBuilder;s.craftConfig&&(logger.info("Found craftConfig export, applying configuration"),r.with(s.craftConfig));let l=w(r,s.default);if(!l.success)return l;let d=r.build();return p(d),await d.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(o,e){let n=r=>typeof r=="object"&&r!==null&&"id"in r,s=r=>typeof r=="object"&&r!==null&&typeof r.build=="function";return e?n(e)||s(e)?(o.routes(e),logger.info("Loaded single route from default export"),{success:true}):Array.isArray(e)?e.every(r=>n(r)||s(r))?(e.forEach(r=>o.routes(r)),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"})}var a=new Command;a.name("craft").description("A modern routing framework for TypeScript").version("0.1.1").showSuggestionAfterError().showHelpAfterError().exitOverride(o=>{o.code==="commander.unknownCommand"&&process.exit(0);});process.argv.length<=2&&a.help({error:false});a.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(o,e)=>{e.env!==void 0?f(e.env):f();let n=await g(o);n.success||(n.message&&console.error(n.message),process.exit(n.code??1));});a.parse();//# sourceMappingURL=index.js.map
2
+ var[n,i]=process.version.slice(1).split(".").map(Number);n>18||n===18&&i>=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));process.env.LOG_LEVEL===void 0&&(process.env.LOG_LEVEL="warn");process.env.CRAFT_LOG_LEVEL===void 0&&(process.env.CRAFT_LOG_LEVEL="warn");for(let o=0;o<process.argv.length;o++){let r=process.argv[o];if(r==="--log-file"&&process.argv[o+1]){let e=process.argv[o+1];process.env.LOG_FILE=e,process.env.CRAFT_LOG_FILE=e;}else if(r.startsWith("--log-file=")){let e=r.slice(11);process.env.LOG_FILE=e,process.env.CRAFT_LOG_FILE=e;}if(r==="--log-level"&&process.argv[o+1]){let e=process.argv[o+1];process.env.LOG_LEVEL=e,process.env.CRAFT_LOG_LEVEL=e;}else if(r.startsWith("--log-level=")){let e=r.slice(12);process.env.LOG_LEVEL=e,process.env.CRAFT_LOG_LEVEL=e;}}var{Command:a}=await import('commander'),{runCommand:l}=await import('./run-XS263DYP.js'),{loadEnvFile:t}=await import('./util-Q5GDRTSI.js'),s=new a;s.name("craft").description("A modern routing framework for TypeScript").version("0.2.0-canary.10").showSuggestionAfterError().showHelpAfterError().exitOverride(o=>{o.code==="commander.unknownCommand"&&process.exit(0);});process.argv.length<=2&&s.help({error:false});s.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)").option("--log-file <path>","Write logs to a file (keeps stdout clear for MCP stdio)").option("--log-level <level>","Log level (e.g. info, warn, error, silent to disable)","warn").action(async(o,r)=>{r.env!==void 0?t(r.env):t();let e=await l(o);e.success||(e.message&&console.error(e.message),process.exit(e.code??1));});s.parse();//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/util.ts","../src/run.ts","../src/index.ts"],"names":["loadEnvFile","path","envPath","resolve","result","loadDotenv","logger","envResult","envLocalResult","registerContextSignalHandlers","context","SUPPORTED_EXTENSIONS","runCommand","filePath","absFilePath","ext","extname","module","contextBuilder","ContextBuilder","configured","configureRoutes","error","defaultExport","isRouteDefinition","obj","isRouteBuilder","item","routeOrBuilder","program","Command","err","options"],"mappings":";0JAUO,SAASA,CAAAA,CAAYC,CAAAA,CAAe,CACzC,GAAIA,CAAAA,CAAM,CAER,IAAMC,CAAAA,CAAUC,OAAAA,CAAQ,OAAA,CAAQ,GAAA,GAAOF,CAAI,CAAA,CACrCG,CAAAA,CAASC,MAAAA,CAAW,CAAE,IAAA,CAAMH,CAAQ,CAAC,EAE3C,OAAIE,CAAAA,CAAO,KAAA,CACTE,MAAAA,CAAO,IAAA,CACL,CAAA,8BAAA,EAAiCL,CAAI,CAAA,EAAA,EAAKG,EAAO,KAAA,CAAM,OAAO,CAAA,CAChE,CAAA,CACSA,CAAAA,CAAO,MAAA,EAChBE,MAAAA,CAAO,KAAA,CACL,UAAU,MAAA,CAAO,IAAA,CAAKF,CAAAA,CAAO,MAAM,CAAA,CAAE,MAAM,CAAA,4BAAA,EAA+BH,CAAI,EAChF,CAAA,CAGKG,CACT,CAIA,IAAMG,CAAAA,CAAYF,MAAAA,CAAW,CAAE,IAAA,CAAMF,QAAQ,OAAA,CAAQ,GAAA,EAAI,CAAG,MAAM,CAAE,CAAC,CAAA,CACjEI,CAAAA,CAAU,OACZD,MAAAA,CAAO,KAAA,CACL,CAAA,OAAA,EAAU,MAAA,CAAO,IAAA,CAAKC,CAAAA,CAAU,MAAM,CAAA,CAAE,MAAM,CAAA,gCAAA,CAChD,CAAA,CACSA,CAAAA,CAAU,KAAA,EACnBD,MAAAA,CAAO,KAAA,CAAM,oBAAoB,CAAA,CAInC,IAAME,CAAAA,CAAiBH,MAAAA,CAAW,CAChC,IAAA,CAAMF,OAAAA,CAAQ,OAAA,CAAQ,GAAA,EAAI,CAAG,YAAY,CAAA,CACzC,QAAA,CAAU,IACZ,CAAC,CAAA,CAWD,OAVIK,CAAAA,CAAe,MAAA,EACjBF,OAAO,KAAA,CACL,CAAA,OAAA,EAAU,MAAA,CAAO,IAAA,CAAKE,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CAA2C,CAAA,CACvD,OAAA,CAAQ,OAAO,CAAA,CACf,wBAAA,EAAyB,CACzB,kBAAA,EAAmB,CACnB,YAAA,CAAcE,CAAAA,EAAQ,CACjBA,EAAI,IAAA,GAAS,0BAAA,EACf,OAAA,CAAQ,IAAA,CAAK,CAAC,EAElB,CAAC,CAAA,CAGC,QAAQ,IAAA,CAAK,MAAA,EAAU,CAAA,EACzBF,CAAAA,CAAQ,IAAA,CAAK,CAAE,KAAA,CAAO,KAAM,CAAC,CAAA,CAS/BA,CAAAA,CACG,OAAA,CAAQ,KAAK,CAAA,CACb,WAAA,CAAY,qDAAqD,CAAA,CACjE,SAAS,QAAA,CAAU,kCAAkC,CAAA,CACrD,MAAA,CACC,cAAA,CACA,6DACF,CAAA,CACC,MAAA,CAAO,MAAOhB,CAAAA,CAAUmB,CAAAA,GAAY,CAE/BA,CAAAA,CAAQ,GAAA,GAAQ,MAAA,CAClBhC,CAAAA,CAAYgC,CAAAA,CAAQ,GAAG,CAAA,CAEvBhC,CAAAA,EAAY,CAGd,IAAMI,CAAAA,CAAS,MAAMQ,CAAAA,CAAWC,CAAQ,EACnCT,CAAAA,CAAO,OAAA,GACNA,CAAAA,CAAO,OAAA,EAET,OAAA,CAAQ,KAAA,CAAMA,CAAAA,CAAO,OAAO,EAE9B,OAAA,CAAQ,IAAA,CAAKA,CAAAA,CAAO,IAAA,EAAQ,CAAC,CAAA,EAEjC,CAAC,CAAA,CAGHyB,EAAQ,KAAA,EAAM","file":"index.js","sourcesContent":["import { logger, CraftContext } from \"@routecraft/routecraft\";\nimport { resolve } from \"node:path\";\nimport { config as loadDotenv } from \"dotenv\";\n\n/**\n * Loads environment variables from .env files\n *\n * @param path Optional path to .env file. If not specified, loads .env and .env.local (if they exist)\n * @returns The parsed dotenv config result\n */\nexport function loadEnvFile(path?: string) {\n if (path) {\n // Explicit path provided - load that file only\n const envPath = resolve(process.cwd(), path);\n const result = loadDotenv({ path: envPath });\n\n if (result.error) {\n logger.info(\n `Could not load .env file from ${path}: ${result.error.message}`,\n );\n } else if (result.parsed) {\n logger.debug(\n `Loaded ${Object.keys(result.parsed).length} environment variables from ${path}`,\n );\n }\n\n return result;\n }\n\n // No path provided - load .env, then .env.local (with override)\n // Load .env first\n const envResult = loadDotenv({ path: resolve(process.cwd(), \".env\") });\n if (envResult.parsed) {\n logger.debug(\n `Loaded ${Object.keys(envResult.parsed).length} environment variables from .env`,\n );\n } else if (envResult.error) {\n logger.debug(`No .env file found`);\n }\n\n // Load .env.local next, allowing it to override .env values\n const envLocalResult = loadDotenv({\n path: resolve(process.cwd(), \".env.local\"),\n override: true,\n });\n if (envLocalResult.parsed) {\n logger.debug(\n `Loaded ${Object.keys(envLocalResult.parsed).length} environment variables from .env.local`,\n );\n }\n\n // Return the most successful result:\n // - If .env.local loaded successfully, return it\n // - If .env loaded successfully but .env.local failed (doesn't exist), return .env result\n // - If both failed, return the last error (from .env.local)\n if (envLocalResult.parsed) {\n return envLocalResult;\n }\n if (envResult.parsed) {\n return envResult;\n }\n return envLocalResult;\n}\n\n/**\n * Registers SIGINT, SIGTERM, and exit handlers for a CraftContext instance.\n * Ensures graceful shutdown and logging.\n *\n * @param context The CraftContext instance\n */\nexport function registerContextSignalHandlers(\n context: InstanceType<typeof CraftContext>,\n) {\n process.on(\"SIGINT\", async () => {\n context.logger.info(\"Shutting down (SIGINT)...\");\n await context.stop();\n process.exit(0);\n });\n process.on(\"SIGTERM\", async () => {\n context.logger.info(\"Shutting down (SIGTERM)...\");\n await context.stop();\n process.exit(0);\n });\n process.on(\"exit\", () => {\n context.logger.info(\"Cleanup complete\");\n });\n}\n","import { resolve, extname } from \"node:path\";\nimport {\n ContextBuilder,\n type RouteDefinition,\n type CraftConfig,\n logger,\n RouteBuilder,\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 // Reject TypeScript files explicitly\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 try {\n logger.info(`Loading file: ${absFilePath}`);\n\n // Load the module with both default and named exports\n const module = await import(absFilePath);\n\n // Create context builder\n const contextBuilder = new ContextBuilder();\n\n // Check for optional craftConfig named export\n if (module.craftConfig) {\n logger.info(\"Found craftConfig export, applying configuration\");\n contextBuilder.with(module.craftConfig as 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 = 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 // Type guards\n const isRouteDefinition = (obj: unknown): obj is RouteDefinition =>\n typeof obj === \"object\" && obj !== null && \"id\" in obj;\n\n const isRouteBuilder = (\n obj: unknown,\n ): obj is InstanceType<typeof RouteBuilder> =>\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as { build?: unknown }).build === \"function\";\n\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 route or RouteBuilder\n if (isRouteDefinition(defaultExport) || isRouteBuilder(defaultExport)) {\n contextBuilder.routes(\n defaultExport as RouteDefinition | InstanceType<typeof RouteBuilder>,\n );\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 if (\n !defaultExport.every(\n (item) => isRouteDefinition(item) || isRouteBuilder(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 | InstanceType<typeof RouteBuilder>,\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","#!/usr/bin/env node\n\n/**\n * Routecraft CLI Module\n *\n * This module provides the command-line interface for Routecraft.\n */\nimport { Command } from \"commander\";\nimport { runCommand } from \"./run.ts\";\nimport { loadEnvFile } from \"./util.ts\";\n\n/**\n * The main command program for the Routecraft CLI.\n * Built using the commander.js library.\n */\nconst program = new Command();\n\nprogram\n .name(\"craft\")\n .description(\"A modern routing framework for TypeScript\")\n .version(\"0.1.1\")\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 // Load environment variables if specified or use default .env\n if (options.env !== undefined) {\n loadEnvFile(options.env);\n } else {\n loadEnvFile();\n }\n\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 process.exit(result.code ?? 1);\n }\n });\n\n// Parse the command line arguments and execute the appropriate command\nprogram.parse();\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["major","minor","i","arg","path","level","Command","runCommand","loadEnvFile","program","err","filePath","options","result"],"mappings":";AAWA,GAAM,CAACA,CAAAA,CAAOC,CAAK,CAAA,CAAI,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,CAAC,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,MAAM,CAAA,CAK/DD,CAAAA,CAAQ,EAAA,EAAOA,CAAAA,GAAU,EAAA,EAAMC,CAAAA,EAAS,EAAA,GAE5C,QAAQ,KAAA,CACN,CAAA,qBAAA,EAAwB,OAAA,CAAQ,OAAO,CAAA,sJAAA,CAGzC,CAAA,CACA,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAAA,CAKZ,OAAA,CAAQ,GAAA,CAAI,SAAA,GAAiB,MAAA,GAC/B,OAAA,CAAQ,GAAA,CAAI,SAAA,CAAe,QAEzB,OAAA,CAAQ,GAAA,CAAI,eAAA,GAAuB,MAAA,GACrC,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAqB,MAAA,CAAA,CAEnC,QAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAI,OAAA,CAAQ,IAAA,CAAK,MAAA,CAAQA,CAAAA,EAAAA,CAAK,CAC5C,IAAMC,CAAAA,CAAM,OAAA,CAAQ,IAAA,CAAKD,CAAC,CAAA,CAC1B,GAAIC,CAAAA,GAAQ,YAAA,EAAgB,QAAQ,IAAA,CAAKD,CAAAA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AA2C,CAAA,CACvD,OAAA,CAAQ,iBAAiB,CAAA,CACzB,wBAAA,EAAyB,CACzB,kBAAA,EAAmB,CACnB,YAAA,CAAcC,CAAAA,EAAQ,CACjBA,EAAI,IAAA,GAAS,0BAAA,EACf,OAAA,CAAQ,IAAA,CAAK,CAAC,EAElB,CAAC,CAAA,CAGC,QAAQ,IAAA,CAAK,MAAA,EAAU,CAAA,EACzBD,CAAAA,CAAQ,IAAA,CAAK,CAAE,KAAA,CAAO,KAAM,CAAC,CAAA,CAS/BA,CAAAA,CACG,OAAA,CAAQ,KAAK,CAAA,CACb,WAAA,CAAY,qDAAqD,CAAA,CACjE,SAAS,QAAA,CAAU,kCAAkC,CAAA,CACrD,MAAA,CACC,cAAA,CACA,6DACF,CAAA,CACC,MAAA,CACC,oBACA,yDACF,CAAA,CACC,MAAA,CACC,qBAAA,CACA,uDAAA,CACA,MACF,CAAA,CACC,MAAA,CAAO,MAAOE,CAAAA,CAAUC,CAAAA,GAAY,CAE/BA,CAAAA,CAAQ,GAAA,GAAQ,MAAA,CAClBJ,CAAAA,CAAYI,CAAAA,CAAQ,GAAG,CAAA,CAEvBJ,CAAAA,EAAY,CAGd,IAAMK,CAAAA,CAAS,MAAMN,CAAAA,CAAWI,CAAQ,EACnCE,CAAAA,CAAO,OAAA,GACNA,CAAAA,CAAO,OAAA,EAET,OAAA,CAAQ,KAAA,CAAMA,CAAAA,CAAO,OAAO,EAE9B,OAAA,CAAQ,IAAA,CAAKA,CAAAA,CAAO,IAAA,EAAQ,CAAC,CAAA,EAEjC,CAAC,CAAA,CAGHJ,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. Set LOG_FILE / LOG_LEVEL from argv before any import touches pino\n * 3. Dynamically import the rest so env is ready when the logger initialises\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. Early argv scan for log options (before loadEnvFile/runCommand) ─\n// Default level so logger sees \"warn\" if nothing else is set\nif (process.env[\"LOG_LEVEL\"] === undefined) {\n process.env[\"LOG_LEVEL\"] = \"warn\";\n}\nif (process.env[\"CRAFT_LOG_LEVEL\"] === undefined) {\n process.env[\"CRAFT_LOG_LEVEL\"] = \"warn\";\n}\nfor (let i = 0; i < process.argv.length; i++) {\n const arg = process.argv[i];\n if (arg === \"--log-file\" && process.argv[i + 1]) {\n const path = process.argv[i + 1];\n process.env[\"LOG_FILE\"] = path;\n process.env[\"CRAFT_LOG_FILE\"] = path;\n } else if (arg.startsWith(\"--log-file=\")) {\n const path = arg.slice(\"--log-file=\".length);\n process.env[\"LOG_FILE\"] = path;\n process.env[\"CRAFT_LOG_FILE\"] = path;\n }\n if (arg === \"--log-level\" && process.argv[i + 1]) {\n const level = process.argv[i + 1];\n process.env[\"LOG_LEVEL\"] = level;\n process.env[\"CRAFT_LOG_LEVEL\"] = level;\n } else if (arg.startsWith(\"--log-level=\")) {\n const level = arg.slice(\"--log-level=\".length);\n process.env[\"LOG_LEVEL\"] = level;\n process.env[\"CRAFT_LOG_LEVEL\"] = level;\n }\n}\n\n// ── 3. Dynamic imports (pino is loaded here, sees env vars above) ───\nconst { Command } = await import(\"commander\");\nconst { runCommand } = await import(\"./run.js\");\nconst { loadEnvFile } = await import(\"./util.js\");\n\n// ── 4. CLI definition ──────────────────────────────────────────────\nconst program = new Command();\n\nprogram\n .name(\"craft\")\n .description(\"A modern routing framework for TypeScript\")\n .version(\"0.2.0-canary.10\")\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 .option(\n \"--log-file <path>\",\n \"Write logs to a file (keeps stdout clear for MCP stdio)\",\n )\n .option(\n \"--log-level <level>\",\n \"Log level (e.g. info, warn, error, silent to disable)\",\n \"warn\",\n )\n .action(async (filePath, options) => {\n // Load environment variables if specified or use default .env\n if (options.env !== undefined) {\n loadEnvFile(options.env);\n } else {\n loadEnvFile();\n }\n\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 process.exit(result.code ?? 1);\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}from'@routecraft/routecraft';var a=[".mjs",".js",".cjs"];async function w(n){let r=resolve(process.cwd(),n),t=extname(r);if(t===".ts"||t===".tsx")return {success:false,code:1,message:"TypeScript files are not supported by 'craft run'. Compile to .js or use .mjs/.js/.cjs."};if(!a.includes(t))return {success:false,code:1,message:`Error: Only the following file types are supported: ${a.join(", ")}`};try{logger.info(`Loading file: ${r}`);let s=await import(r),e=new ContextBuilder;s.craftConfig&&(logger.info("Found craftConfig export, applying configuration"),e.with(s.craftConfig));let i=p(e,s.default);if(!i.success)return i;let u=await e.build();return b(u),await u.start(),{success:!0}}catch(s){return s instanceof Error?(logger.error(`Failed to run ${r}: ${s.message}`),{success:false,code:1,message:s.message}):(logger.error(`Failed to run ${r}: Unknown error occurred`),{success:false,code:1,message:"Unknown error"})}}function p(n,r){let t=e=>typeof e=="object"&&e!==null&&typeof e.build=="function",s=e=>typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"&&"source"in e&&"steps"in e&&"consumer"in e;return r?t(r)?(n.routes(r),logger.info("Loaded single RouteBuilder from default export"),{success:true}):s(r)?(n.routes(r),logger.info("Loaded single route from default export"),{success:true}):Array.isArray(r)?r.every(e=>t(e)||s(e))?(r.forEach(e=>n.routes(e)),logger.info(`Loaded ${r.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{w as runCommand};//# sourceMappingURL=run-XS263DYP.js.map
2
+ //# sourceMappingURL=run-XS263DYP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run.ts"],"names":["SUPPORTED_EXTENSIONS","runCommand","filePath","absFilePath","resolve","ext","extname","logger","module","contextBuilder","ContextBuilder","configured","configureRoutes","context","registerContextSignalHandlers","error","defaultExport","isRouteBuilder","obj","isRouteDefinition","item","routeOrBuilder"],"mappings":"kIAUA,IAAMA,CAAAA,CAAuB,CAAC,OAAQ,KAAA,CAAO,MAAM,CAAA,CAMnD,eAAsBC,CAAAA,CAAWC,CAAAA,CAAsC,CACrE,IAAMC,EAAcC,OAAAA,CAAQ,OAAA,CAAQ,GAAA,EAAI,CAAGF,CAAQ,CAAA,CAC7CG,CAAAA,CAAMC,OAAAA,CAAQH,CAAW,EAG/B,GAAIE,CAAAA,GAAQ,KAAA,EAASA,CAAAA,GAAQ,MAAA,CAC3B,OAAO,CACL,OAAA,CAAS,MACT,IAAA,CAAM,CAAA,CACN,OAAA,CACE,yFACJ,EAIF,GACE,CAACL,CAAAA,CAA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AAM,CAAA,CACN,OAAA,CACE,qFACJ,CAAA,CAAA,EAxDEA,OAAO,KAAA,CAAM,6DAA6D,CAAA,CACnE,CAAE,QAAS,KAAA,CAAO,IAAA,CAAM,CAAA,CAAG,OAAA,CAAS,yBAA0B,CAAA,CAwDzE","file":"run-XS263DYP.js","sourcesContent":["import { resolve, extname } from \"node:path\";\nimport {\n ContextBuilder,\n type RouteDefinition,\n type CraftConfig,\n logger,\n RouteBuilder,\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 logger.info(`Loading file: ${absFilePath}`);\n\n // Load the module with both default and named exports\n const module = await import(absFilePath);\n\n // Create context builder\n const contextBuilder = new ContextBuilder();\n\n // Check for optional craftConfig named export\n if (module.craftConfig) {\n logger.info(\"Found craftConfig export, applying configuration\");\n contextBuilder.with(module.craftConfig as 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 // Type guards\n const isRouteBuilder = (\n obj: unknown,\n ): obj is InstanceType<typeof RouteBuilder> =>\n typeof obj === \"object\" &&\n obj !== null &&\n typeof (obj as { build?: unknown }).build === \"function\";\n\n const isRouteDefinition = (obj: unknown): obj is RouteDefinition =>\n typeof obj === \"object\" &&\n obj !== null &&\n \"id\" in obj &&\n typeof obj.id === \"string\" && // Ensure id is a string, not a method\n \"source\" in obj &&\n \"steps\" in obj &&\n \"consumer\" in obj;\n\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\n // Check RouteBuilder first since it also has an 'id' property (as a method)\n if (isRouteBuilder(defaultExport)) {\n contextBuilder.routes(defaultExport);\n logger.info(\"Loaded single RouteBuilder from default export\");\n return { success: true };\n }\n\n if (isRouteDefinition(defaultExport)) {\n contextBuilder.routes(defaultExport);\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 | InstanceType<typeof RouteBuilder>,\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"]}
@@ -0,0 +1,2 @@
1
+ export{a as loadEnvFile,b as registerContextSignalHandlers}from'./chunk-5NEKGUV3.js';//# sourceMappingURL=util-Q5GDRTSI.js.map
2
+ //# sourceMappingURL=util-Q5GDRTSI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"util-Q5GDRTSI.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routecraft/cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.0-canary.10",
4
4
  "description": "CLI for running RouteCraft routes",
5
5
  "private": false,
6
6
  "type": "module",
@@ -15,9 +15,15 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format esm --dts",
20
+ "test": "vitest",
21
+ "test:coverage": "vitest --coverage",
22
+ "prepublishOnly": "pnpm run build"
23
+ },
18
24
  "dependencies": {
19
- "@routecraft/routecraft": "^0.1.1",
20
- "commander": "^14.0.2",
25
+ "@routecraft/routecraft": "^0.2.0-canary.10",
26
+ "commander": "^14.0.3",
21
27
  "dotenv": "^17.2.3"
22
28
  },
23
29
  "publishConfig": {
@@ -27,6 +33,9 @@
27
33
  "bin": {
28
34
  "craft": "./dist/index.js"
29
35
  },
36
+ "engines": {
37
+ "node": ">=18.19.0"
38
+ },
30
39
  "keywords": [
31
40
  "routecraft",
32
41
  "cli",
@@ -36,10 +45,5 @@
36
45
  ],
37
46
  "author": "routecraftjs",
38
47
  "license": "Apache-2.0",
39
- "homepage": "https://routecraft.dev",
40
- "scripts": {
41
- "build": "tsup src/index.ts --format esm --dts",
42
- "test": "vitest",
43
- "test:coverage": "vitest --coverage"
44
- }
45
- }
48
+ "homepage": "https://routecraft.dev"
49
+ }
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.