@runium/cli 0.1.0 → 0.2.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/app.js +1 -1
- package/constants/error-code.js +1 -1
- package/package.json +2 -2
- package/services/config.js +1 -1
- package/services/plugin-context.js +1 -1
- package/services/profile.js +1 -1
- package/validation/get-config-schema.js +1 -1
package/app.js
CHANGED
|
@@ -3,4 +3,4 @@ import{existsSync as c}from"node:fs";import{resolve as u}from"node:path";import{
|
|
|
3
3
|
\u2551 \u2560\u2566\u255D \u2551 \u2551 \u2551\u2551\u2551 \u2551 \u2551 \u2551 \u2551\u2551\u2551 \u2551
|
|
4
4
|
\u2551 \u2569\u255A\u2550 \u255A\u2550\u255D \u255D\u255A\u255D \u2569 \u255A\u2550\u255D \u2569 \u2569 \u2551
|
|
5
5
|
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
|
|
6
|
-
One Tool to Run Them All!`;class A{program;commandService;configService;profileService;pluginService;shutdownService;outputService;pluginContextService;constructor(){this.program=new v("runium"),this.configService=o.get(l),this.profileService=o.get(m),this.pluginService=o.get(d),this.shutdownService=o.get(h),this.outputService=o.get(S),this.pluginContextService=o.get(f),this.commandService=o.get(g)}async start(){return await this.configService.init().catch(i=>{throw this.initOutput(),i}),await this.shutdownService.init(),await this.profileService.init(),await this.pluginContextService.init(),this.
|
|
6
|
+
One Tool to Run Them All!`;class A{program;commandService;configService;profileService;pluginService;shutdownService;outputService;pluginContextService;constructor(){this.program=new v("runium"),this.configService=o.get(l),this.profileService=o.get(m),this.pluginService=o.get(d),this.shutdownService=o.get(h),this.outputService=o.get(S),this.pluginContextService=o.get(f),this.commandService=o.get(g)}async start(){return await this.configService.init().catch(i=>{throw this.initOutput(),i}),this.initOutput(),await this.shutdownService.init(),await this.profileService.init(),await this.pluginContextService.init(),this.initEnv(),await this.loadPlugins(),await this.initProgram(),await this.initPlugins(),this.program.parseAsync()}async loadPlugins(){const i=this.profileService.getPlugins();for(const e of i)if(e.disabled!==!0)try{const t=this.pluginService.resolvePath(e.path,e.file);await this.pluginService.loadPlugin(t,e.options)}catch(t){this.outputService.error(`Failed to load plugin "${e.name}"`);const{code:r,message:s,payload:a}=t;this.outputService.debug("Error details:",{message:s,code:r,payload:a})}}async initProgram(){const i=this.program;i.option("-D, --debug","enable debug mode"),i.option("-E, --env [paths...]","load env files"),i.version(`runium ${P()}`),i.description(C),i.on("option:debug",()=>{this.setDebugMode()}),i.on("option:env",e=>{this.loadEnvFiles([e])}),Object.values(p).forEach(e=>{this.commandService.registerCommand(e,i)})}initOutput(){(this.configService.get("output").debug||process.argv.includes("-D")||process.argv.includes("--debug"))&&this.setDebugMode()}setDebugMode(){this.outputService.getLevel()!==n.DEBUG&&(this.outputService.setLevel(n.DEBUG),this.outputService.debug("Debug mode enabled"))}initEnv(){const i=this.configService.get("env");i.path.length>0&&this.loadEnvFiles(i.path)}loadEnvFiles(i){for(const e of i){const t=u(e&&e.trim()||".env");c(t)?(this.outputService.debug(`Loading env file "${t}"`),process.loadEnvFile(t)):this.outputService.error(`Env file "${t}" not found`)}}async initPlugins(){const i=this.pluginService.getAllPlugins();for(const e of i){const t=e.app?.commands;if(t)for(const r of t)this.commandService.registerCommand(r,this.program,e.name)}await this.pluginService.runHook("app.afterInit",{profilePath:this.configService.get("profile").path})}}export{A as RuniumCliApp};
|
package/constants/error-code.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _=(R=>(R.FILE_READ_JSON_ERROR="file-read-json-error",R.FILE_WRITE_JSON_ERROR="file-write-json-error",R.FILE_READ_ERROR="file-read-error",R.FILE_WRITE_ERROR="file-write-error",R.FILE_CREATE_DIR_ERROR="file-create-dir-error",R.FILE_REMOVE_ERROR="file-remove-error",R.PLUGIN_NOT_FOUND="plugin-not-found",R.PLUGIN_FILE_NOT_FOUND="plugin-file-not-found",R.PLUGIN_INCORRECT_MODULE="plugin-incorrect-module",R.PLUGIN_INVALID="plugin-invalid",R.PLUGIN_PATH_RESOLVE_ERROR="plugin-path-resolve-error",R.PLUGIN_LOAD_ERROR="plugin-load-error",R.PLUGIN_HOOK_ERROR="plugin-hook-error",R.PROJECT_ALREADY_STARTED="project-already-started",R.PROJECT_NOT_STARTED="project-not-started",R.PROJECT_STOP_ERROR="project-stop-error",R.PROJECT_NOT_FOUND="project-not-found",R.PROJECT_FILE_NOT_FOUND="project-file-not-found",R.PROJECT_FILE_CAN_NOT_READ="project-file-can-not-read",R.PROJECT_JSON_PARSE_ERROR="project-json-parse-error",R.INVALID_ARGUMENT="invalid-argument",R.INVALID_PATH="invalid-path",R.CONFIG_INVALID_DATA="config-invalid-data",R.COMMAND_REGISTRATION_ERROR="command-registration-error",R.COMMAND_INCORRECT="command-incorrect",R.COMMAND_NOT_FOUND="command-not-found",R.COMMAND_RUN_ERROR="command-run-error",R))(_||{});export{_ as ErrorCode};
|
|
1
|
+
var _=(R=>(R.FILE_READ_JSON_ERROR="file-read-json-error",R.FILE_WRITE_JSON_ERROR="file-write-json-error",R.FILE_READ_ERROR="file-read-error",R.FILE_WRITE_ERROR="file-write-error",R.FILE_CREATE_DIR_ERROR="file-create-dir-error",R.FILE_REMOVE_ERROR="file-remove-error",R.PLUGIN_NOT_FOUND="plugin-not-found",R.PLUGIN_FILE_NOT_FOUND="plugin-file-not-found",R.PLUGIN_INCORRECT_MODULE="plugin-incorrect-module",R.PLUGIN_INVALID="plugin-invalid",R.PLUGIN_PATH_RESOLVE_ERROR="plugin-path-resolve-error",R.PLUGIN_LOAD_ERROR="plugin-load-error",R.PLUGIN_HOOK_ERROR="plugin-hook-error",R.PLUGIN_PATH_NOT_SPECIFIED="plugin-path-not-specified",R.PROJECT_ALREADY_STARTED="project-already-started",R.PROJECT_NOT_STARTED="project-not-started",R.PROJECT_STOP_ERROR="project-stop-error",R.PROJECT_NOT_FOUND="project-not-found",R.PROJECT_FILE_NOT_FOUND="project-file-not-found",R.PROJECT_FILE_CAN_NOT_READ="project-file-can-not-read",R.PROJECT_JSON_PARSE_ERROR="project-json-parse-error",R.PROJECT_PATH_NOT_SPECIFIED="project-path-not-specified",R.INVALID_ARGUMENT="invalid-argument",R.INVALID_PATH="invalid-path",R.CONFIG_INVALID_DATA="config-invalid-data",R.COMMAND_REGISTRATION_ERROR="command-registration-error",R.COMMAND_INCORRECT="command-incorrect",R.COMMAND_NOT_FOUND="command-not-found",R.COMMAND_RUN_ERROR="command-run-error",R))(_||{});export{_ as ErrorCode};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runium/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Runium CLI",
|
|
5
5
|
"author": "TheBeastApp",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"module": "./index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@runium/core": "^0.
|
|
16
|
+
"@runium/core": "^0.2.0",
|
|
17
17
|
"@segment/ajv-human-errors": "^2.15.0",
|
|
18
18
|
"commander": "^14.0.2",
|
|
19
19
|
"reflect-metadata": "^0.2.2",
|
package/services/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=function(i,t,e,r){var s=arguments.length,o=s<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,e,r);else for(var n=i.length-1;n>=0;n--)(a=i[n])&&(o=(s<3?a(o):s>3?a(t,e,o):a(t,e))||o);return s>3&&o&&Object.defineProperty(t,e,o),o};import{existsSync as l}from"node:fs";import{homedir as g}from"node:os";import{join as c,resolve as u}from"node:path";import{Service as v}from"typedi";import{readJsonFile as _,RuniumError as O}from"@runium/core";import{ErrorCode as j}from"../constants/index.js";import{createValidator as I,getConfigSchema as E,getErrorMessages as b}from"../validation/index.js";const C=".runiumrc.json",p=c(process.cwd(),C),h=".runium",F=c(g(),h),d=c(process.cwd(),h);function A(i){const t=E(),e=I(t);if(!e(i)&&e.errors){const s=b(e.errors);throw new O(`Invalid "${p}" configuration data`,j.CONFIG_INVALID_DATA,s)}}let f=class{data={profile:{path:F},plugins:{},projects:{},output:{debug:!1},env:{path:[]}};async init(){if(l(d)&&(this.data.profile.path=d),l(p)){const t=await _(p);if(t){A(t);const e={env:Object.assign({},this.data.env,t.env??{}),output:Object.assign({},this.data.output,t.output??{}),profile:Object.assign({},this.data.profile,t.profile??{}),plugins:Object.assign({},this.data.plugins,t.plugins??{}),projects:Object.assign({},this.data.projects,t.projects??{})};e.env.path=e.env.path.map(r=>u(r)),e.profile.path=u(e.profile.path),this.data=e}}}get(t){return this.data[t]}};f=m([v()],f);export{f as ConfigService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var w=function(a,t,e,r){var o=arguments.length,i=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,t,e,r);else for(var u=a.length-1;u>=0;u--)(n=a[u])&&(i=(o<3?n(i):o>3?n(t,e,i):n(t,e))||i);return o>3&&i&&Object.defineProperty(t,e,i),i},
|
|
1
|
+
var w=function(a,t,e,r){var o=arguments.length,i=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,t,e,r);else for(var u=a.length-1;u>=0;u--)(n=a[u])&&(i=(o<3?n(i):o>3?n(t,e,i):n(t,e))||i);return o>3&&i&&Object.defineProperty(t,e,i),i},O=function(a,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(a,t)},c=function(a,t){return function(e,r){t(e,r,a)}},d,p,f,l,v;import{delimiter as j}from"node:path";import{Inject as s,Service as R}from"typedi";import{Argument as W,Option as C}from"commander";import{RuniumError as h,isRuniumError as E,RuniumTask as A,RuniumTrigger as x,applyMacros as L,TaskEvent as T,TaskStatus as I,ProjectEvent as N,ProjectStatus as B}from"@runium/core";import{RuniumCommand as D}from"../commands/runium-command.js";import{CommandService as S,FileService as b,OutputLevel as g,OutputService as y,ProfileService as _,ShutdownService as P}from"./index.js";import{getVersion as J,convertPathToValidFileName as k}from"../utils/index.js";import{ErrorCode as V}from"../constants/index.js";global.runium=null;let m=class{commandService;outputService;shutdownService;fileService;profileService;constructor(t,e,r,o,i){this.commandService=t,this.outputService=e,this.shutdownService=r,this.fileService=o,this.profileService=i}createStorageWrapper(t){return((...e)=>{const[r,...o]=e,i=this.resolveProfilePath(r),n=this.fileService[t];return n(i,...o)})}resolveProfilePath(t){const e=Array.isArray(t)?t:t.split(j);if(e.length===0||e.every(r=>r.trim()===""))throw new h("Invalid path",V.INVALID_PATH,{path:t});return this.profileService.getPath(...e)}async init(){const t=this.commandService,e=this.outputService,r=this.shutdownService,o={class:{RuniumCommand:D,CommandArgument:W,CommandOption:C,RuniumError:h,RuniumTask:A,RuniumTrigger:x},enum:{OutputLevel:Object.keys(g).filter(i=>isNaN(Number(i))).reduce((i,n)=>(i[n]=g[n],i),{}),ProjectEvent:N,ProjectStatus:B,TaskEvent:T,TaskStatus:I},utils:{applyMacros:L,isRuniumError:E,pathToId:k},output:{getLevel:e.getLevel.bind(e),setLevel:e.setLevel.bind(e),trace:e.trace.bind(e),debug:e.debug.bind(e),info:e.info.bind(e),warn:e.warn.bind(e),error:e.error.bind(e),table:e.table.bind(e),log:e.log.bind(e)},shutdown:{addBlocker:r.addBlocker.bind(r),removeBlocker:r.removeBlocker.bind(r)},command:{has:t.hasCommand.bind(t),run:t.runCommand.bind(t)},storage:{read:this.createStorageWrapper("read"),write:this.createStorageWrapper("write"),readJson:this.createStorageWrapper("readJson"),writeJson:this.createStorageWrapper("writeJson"),isExists:this.createStorageWrapper("isExists"),ensureDirExists:this.createStorageWrapper("ensureDirExists"),remove:this.createStorageWrapper("remove"),createAtomicWriter:this.createStorageWrapper("createAtomicWriter"),getPath:this.resolveProfilePath.bind(this)},version:J()};global.runium=Object.freeze(o)}};m=w([R(),c(0,s()),c(1,s()),c(2,s()),c(3,s()),c(4,s()),O("design:paramtypes",[typeof(d=typeof S<"u"&&S)=="function"?d:Object,typeof(p=typeof y<"u"&&y)=="function"?p:Object,typeof(f=typeof P<"u"&&P)=="function"?f:Object,typeof(l=typeof b<"u"&&b)=="function"?l:Object,typeof(v=typeof _<"u"&&_)=="function"?v:Object])],m);export{m as PluginContextService};
|
package/services/profile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var w=function(s,t,e,i){var r=arguments.length,n=r<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(s,t,e,i);else for(var c=s.length-1;c>=0;c--)(a=s[c])&&(n=(r<3?a(n):r>3?a(t,e,n):a(t,e))||n);return r>3&&n&&Object.defineProperty(t,e,n),n},v=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)},h=function(s,t){return function(e,i){t(e,i,s)}},p,f;import{existsSync as _}from"node:fs";import{mkdir as y}from"node:fs/promises";import{join as S}from"node:path";import{Inject as l,Service as E}from"typedi";import{RuniumError as u}from"@runium/core";import{ErrorCode as g}from"../constants/index.js";import{ConfigService as m,FileService as P}from"./index.js";const j="plugins.json",d="projects.json";let o=class{configService;fileService;path=process.cwd();plugins=[];projects=[];constructor(t,e){this.configService=t,this.fileService=e}async init(){this.path=this.configService.get("profile").path,_(this.path)||await y(this.path,{recursive:!0}),await this.readPlugins(),await this.patchPlugins(),await this.readProjects(),await this.patchProjects()}getPlugins(){return this.plugins}getPluginByName(t){return this.plugins.find(e=>e.name===t)}async addPlugin(t){this.plugins=this.plugins.filter(e=>e.name!==t.name).concat(t),await this.writePlugins()}async removePlugin(t){this.plugins=this.plugins.filter(e=>e.name!==t),await this.writePlugins()}async updatePlugin(t,e){const i=this.plugins.findIndex(r=>r.name===t);i!==-1&&(this.plugins[i]={...this.plugins[i],...e},await this.writePlugins())}getProjects(){return this.projects}getProjectByName(t){return this.projects.find(e=>e.name===t)}async addProject(t){this.projects=this.projects.filter(e=>e.name!==t.name).concat(t),await this.writeProjects()}async removeProject(t){this.projects=this.projects.filter(e=>e.name!==t),await this.writeProjects()}getPath(...t){return S(this.path,...t)}async readPlugins(){this.plugins=await this.fileService.readJson(this.getPath(j)).catch(()=>[])||this.plugins}async writePlugins(){await this.fileService.writeJson(this.getPath(j),this.plugins)}async patchPlugins(){const t={...this.configService.get("plugins")};for(const e of this.plugins){const i=t[e.name];i&&(Object.assign(e,i),delete t[e.name])}for(const e in t)if(t[e].path)this.plugins.push({name:e,...t[e]});else throw new u("Plugin path is not specified",g.PLUGIN_PATH_NOT_SPECIFIED,{name:e,data:t[e]})}async readProjects(){this.projects=await this.fileService.readJson(this.getPath(d)).catch(()=>[])||this.projects}async writeProjects(){await this.fileService.writeJson(this.getPath(d),this.projects)}async patchProjects(){const t={...this.configService.get("projects")};for(const e of this.projects){const i=t[e.name];i&&(Object.assign(e,i),delete t[e.name])}for(const e in t)if(t[e].path)this.projects.push({name:e,...t[e]});else throw new u("Project path is not specified",g.PROJECT_PATH_NOT_SPECIFIED,{name:e,data:t[e]})}};o=w([E(),h(0,l()),h(1,l()),v("design:paramtypes",[typeof(p=typeof m<"u"&&m)=="function"?p:Object,typeof(f=typeof P<"u"&&P)=="function"?f:Object])],o);export{o as ProfileService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(){return{$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://runium.dev/schemas/config.json",title:"Runium Config",type:"object",properties:{env:{type:"object",properties:{path:{type:"array",items:{type:"string"}}},additionalProperties:!1},output:{type:"object",properties:{debug:{type:"boolean"}},additionalProperties:!1},profile:{type:"object",properties:{path:{type:"string"}},additionalProperties:!1},plugins:{type:"object",additionalProperties:{type:"object",properties:{disabled:{type:"boolean"},options:{type:"object"}},additionalProperties:!1}}},additionalProperties:!1}}export{e as getConfigSchema};
|
|
1
|
+
function e(){return{$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://runium.dev/schemas/config.json",title:"Runium Config",type:"object",properties:{env:{type:"object",properties:{path:{type:"array",items:{type:"string"}}},additionalProperties:!1},output:{type:"object",properties:{debug:{type:"boolean"}},additionalProperties:!1},profile:{type:"object",properties:{path:{type:"string"}},additionalProperties:!1},plugins:{type:"object",additionalProperties:{type:"object",properties:{path:{type:"string"},file:{type:"boolean"},disabled:{type:"boolean"},options:{type:"object"}},additionalProperties:!1}},projects:{type:"object",additionalProperties:{type:"object",properties:{path:{type:"string"}},additionalProperties:!1,required:["path"]}}},additionalProperties:!1}}export{e as getConfigSchema};
|