@runium/cli 0.0.6 → 0.0.9
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{existsSync as c}from"node:fs";import{resolve as u}from"node:path";import{Command as v}from"commander";import{Container as o}from"typedi";import*as p from"./commands/index.js";import{CommandService as g,ConfigService as l,ProfileService as m,PluginService as
|
|
1
|
+
import{existsSync as c}from"node:fs";import{resolve as u}from"node:path";import{Command as v}from"commander";import{Container as o}from"typedi";import*as p from"./commands/index.js";import{CommandService as g,ConfigService as l,ProfileService as m,PluginService as d,ShutdownService as h,OutputService as S,OutputLevel as n,PluginContextService as f}from"./services/index.js";import{getVersion as P}from"./utils/index.js";const C=`\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
2
2
|
\u2551 \u2554\u2550\u2557 \u2566 \u2566 \u2554\u2557\u2554 \u2566 \u2566 \u2566 \u2554\u2566\u2557 \u2551
|
|
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(
|
|
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.initOutput(),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(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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as
|
|
1
|
+
import{dirname as h}from"node:path";import{Option as j}from"commander";import{Container as u}from"typedi";import{ProjectEvent as d,RuniumError as m}from"@runium/core";import{ErrorCode as f}from"../../constants/index.js";import{ShutdownService as P}from"../../services/index.js";import{ProjectStateCommand as S}from"./project-state-command.js";class x extends S{shutdownService;fileWriter=null;constructor(e){super(e),this.shutdownService=u.get(P)}config(){this.command.name("start").description("start project").option("-f, --file","use file path instead of project name").option("-o, --output","output project state changes").addOption(new j("-w, --working-dir <choice>","set working directory").choices(["cwd","project"]).default("cwd")).argument("<name>","project name")}async handle(e,{file:s,workingDir:p,output:c}){const o=s?this.projectService.resolvePath(e):this.ensureProfileProject(e).path,i=this.getProjectDataFileName(s?o:e),t=this.profileService.getPath("projects",i),r=await this.readProjectData(t);if(r&&this.isProjectProcessStarted(r.pid))throw new m(`Project "${e}" is already started`,f.PROJECT_ALREADY_STARTED,{name:e});if(p==="project"){const n=h(o);n!==process.cwd()&&process.chdir(n)}const a=await this.projectService.initProject(o);this.shutdownService.addBlocker(n=>a.stop(n)),await this.fileService.ensureDirExists(h(t)),this.fileWriter=this.fileService.createAtomicWriter(t),this.addProjectListeners(a,{projectPath:o,output:c}),await this.projectService.runHook("project.beforeStart",a),await a.start()}addProjectListeners(e,s){const{projectPath:p,output:c}=s,o={id:e.getConfig().id,pid:process.pid,cwd:process.cwd(),path:p,state:{project:[],tasks:{}}},i=()=>{this.fileWriter.writeJson(o).then()};i(),e.on(d.STATE_CHANGE,async t=>{o.state.project.push(t),i(),c&&this.outputService.info("Project %s",t.status)}),e.on(d.TASK_STATE_CHANGE,(t,r)=>{o.state.tasks[t]||(o.state.tasks[t]=[]),o.state.tasks[t].push(r),i(),c&&this.outputService.info("Task %s %s %s",t,r.status,r.exitCode||r.error||"")}),e.on(d.STATE_CHANGE,t=>{t.status==="stopped"&&t.reason==="action"&&this.shutdownService.shutdown("project-stop")})}}export{x as ProjectStartCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{formatTimestamp as m}from"../../utils/index.js";import{ProjectStateCommand as
|
|
1
|
+
import{SILENT_EXIT_CODE as g}from"@runium/core";import{formatTimestamp as m}from"../../utils/index.js";import{ProjectStateCommand as P}from"./project-state-command.js";class E extends P{config(){this.command.name("status").description("get project status").option("-f, --file","use file path instead of project name").option("-t, --tasks","show tasks status").option("-a, --all","show status change history").argument("<name>","project name")}async handle(a,{file:p,tasks:d,all:c}){const l=p?this.projectService.resolvePath(a):this.ensureProfileProject(a).path,f=this.getProjectDataFileName(p?l:a),j=this.profileService.getPath("projects",f),r=await this.readProjectData(j);if(r){let{project:o=[]}=r.state;if(c||(o=o.length>0?[o[o.length-1]]:[]),d){const n=o.map(t=>({name:"Project",status:t.status,time:m(t.timestamp),timestamp:t.timestamp,reason:t.reason||""})),{tasks:i=[]}=r.state,h=[];Object.entries(i).forEach(([t,e])=>{c||(e=e.length>0?[e[e.length-1]]:[]),e.forEach(s=>{const S=s.exitCode&&s.exitCode!==g?s.exitCode:"";h.push({name:t,status:s.status,time:m(s.timestamp),timestamp:s.timestamp,reason:[s.reason,S].filter(Boolean).join(" ")})})});const u=[...n,...h];u.sort((t,e)=>t.timestamp-e.timestamp),this.outputService.table(u,["time","name","status","reason"])}else{const n=o.map(i=>({status:i.status,time:m(i.timestamp)}));this.outputService.table(n,["time","status"])}}else this.outputService.info(`No project status for "${a}"`)}}export{E as ProjectStatusCommand};
|
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.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.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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runium/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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.1.
|
|
16
|
+
"@runium/core": "^0.1.1",
|
|
17
17
|
"@segment/ajv-human-errors": "^2.15.0",
|
|
18
18
|
"commander": "^14.0.2",
|
|
19
19
|
"reflect-metadata": "^0.2.2",
|
package/services/file.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=function(i,e,t,r){var a=arguments.length,n=a<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(i,e,t,r);else for(var l=i.length-1;l>=0;l--)(s=i[l])&&(n=(a<3?s(n):a>3?s(e,t,n):s(e,t))||n);return a>3&&n&&Object.defineProperty(e,t,n),n};import{basename as u,dirname as R,join as y}from"node:path";import{access as E,constants as x,mkdir as _,readFile as m,rename as d,rm as O,writeFile as w}from"node:fs/promises";import{fileURLToPath as F}from"node:url";import{Service as g}from"typedi";import{RuniumError as o}from"@runium/core";import{ErrorCode as c}from"../constants/index.js";let f=class{async read(e,t={}){try{return await m(e,{encoding:t.encoding||"utf-8"})}catch(r){throw new o(`Can not read file ${e}`,c.FILE_READ_ERROR,{path:e,options:t,original:r})}}async write(e,t,r={}){try{await w(e,t,{encoding:r.encoding||"utf-8"})}catch(a){throw new o(`Can not write file ${e}`,c.FILE_WRITE_ERROR,{path:e,data:t,options:r,original:a})}}async readJson(e){try{const t=await m(e,{encoding:"utf-8"});return JSON.parse(t)}catch(t){throw new o(`Can not read JSON file ${e}`,c.FILE_READ_JSON_ERROR,{path:e,original:t})}}async writeJson(e,t){try{await w(e,JSON.stringify(t,null,2),{encoding:"utf-8"})}catch(r){throw new o(`Can not write JSON file ${e}`,c.FILE_WRITE_JSON_ERROR,{path:e,data:t,original:r})}}async isExists(e){try{return await E(e,x.F_OK),!0}catch{return!1}}async remove(e){try{await O(e,{recursive:!0,force:!0})}catch(t){throw new o(`Can not remove ${e}`,c.FILE_REMOVE_ERROR,{path:e,original:t})}}async ensureDirExists(e){try{await _(e,{recursive:!0})}catch(t){throw new o(`Can not create directory ${e}`,c.FILE_CREATE_DIR_ERROR,{path:e,original:t})}}createAtomicWriter(e){return new p(e)}};f=h([g()],f);function D(i){const e=i instanceof URL?F(i):i.toString();return y(R(e),`.${u(e)}.tmp`)}async function v(i,e,t){for(let r=0;r<e;r++)try{return await i()}catch(a){if(r<e-1)await new Promise(n=>setTimeout(n,t));else throw a}}class p{filename;tempFilename;locked=!1;prev=null;next=null;nextPromise=null;nextData=null;constructor(e){this.filename=e,this.tempFilename=D(e)}addData(e){return this.nextData=e,this.nextPromise||=new Promise((t,r)=>{this.next=[t,r]}),new Promise((t,r)=>{this.nextPromise?.then(t).catch(r)})}async writeData(e){this.locked=!0;try{await w(this.tempFilename,e,"utf-8"),await v(async()=>{await d(this.tempFilename,this.filename)},10,100),this.prev?.[0]()}catch(t){throw t instanceof Error&&this.prev?.[1](t),t}finally{if(this.locked=!1,this.prev=this.next,this.next=this.nextPromise=null,this.nextData!==null){const t=this.nextData;this.nextData=null,await this.write(t)}}}async write(e){try{await(this.locked?this.addData(e):this.writeData(e))}catch(t){throw new o(`Can not write file ${this.filename}`,c.FILE_WRITE_ERROR,{path:this.filename,data:e,original:t})}}async writeJson(e){return this.write(JSON.stringify(e,null,2))}}export{p as AtomicWriter,f as FileService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=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},j=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,l,
|
|
1
|
+
var P=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},j=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,m,l,v;import{delimiter as O}from"node:path";import{Inject as s,Service as R}from"typedi";import{RuniumError as h,isRuniumError as W,RuniumTask as E,RuniumTrigger as x,applyMacros as C,TaskEvent as L,TaskStatus as A,ProjectEvent as T,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 w}from"./index.js";import{getVersion as I}from"../utils/index.js";import{ErrorCode as J}from"../constants/index.js";global.runium=null;let f=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(O);if(e.length===0||e.every(r=>r.trim()===""))throw new h("Invalid path",J.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,RuniumError:h,RuniumTask:E,RuniumTrigger:x},enum:{OutputLevel:Object.keys(g).filter(i=>isNaN(Number(i))).reduce((i,n)=>(i[n]=g[n],i),{}),ProjectEvent:T,ProjectStatus:B,TaskEvent:L,TaskStatus:A},utils:{applyMacros:C,isRuniumError:W},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:I()};global.runium=Object.freeze(o)}};f=P([R(),c(0,s()),c(1,s()),c(2,s()),c(3,s()),c(4,s()),j("design:paramtypes",[typeof(d=typeof S<"u"&&S)=="function"?d:Object,typeof(p=typeof y<"u"&&y)=="function"?p:Object,typeof(m=typeof w<"u"&&w)=="function"?m:Object,typeof(l=typeof b<"u"&&b)=="function"?l:Object,typeof(v=typeof _<"u"&&_)=="function"?v:Object])],f);export{f as PluginContextService};
|