@runium/cli 0.0.8 → 0.1.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
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:i,workingDir:p,output:c}){const o=i?this.projectService.resolvePath(e):this.ensureProfileProject(e).path,s=this.getProjectDataFileName(i?o:e),t=this.profileService.getPath("projects",s),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",{project:a,path:o,name:i?null:e}),await a.start()}addProjectListeners(e,i){const{projectPath:p,output:c}=i,o={id:e.getConfig().id,pid:process.pid,cwd:process.cwd(),path:p,state:{project:[],tasks:{}}},s=()=>{this.fileWriter.writeJson(o).then()};s(),e.on(d.STATE_CHANGE,async t=>{o.state.project.push(t),s(),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),s(),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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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},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)}},f,p,l,m,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 T,ProjectEvent as A,ProjectStatus as I}from"@runium/core";import{RuniumCommand as N}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 B,convertPathToValidFileName as D}from"../utils/index.js";import{ErrorCode as J}from"../constants/index.js";global.runium=null;let d=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:N,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:A,ProjectStatus:I,TaskEvent:L,TaskStatus:T},utils:{applyMacros:C,isRuniumError:W,pathToId:D},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:B()};global.runium=Object.freeze(o)}};d=w([R(),c(0,s()),c(1,s()),c(2,s()),c(3,s()),c(4,s()),j("design:paramtypes",[typeof(f=typeof S<"u"&&S)=="function"?f:Object,typeof(p=typeof y<"u"&&y)=="function"?p:Object,typeof(l=typeof P<"u"&&P)=="function"?l:Object,typeof(m=typeof b<"u"&&b)=="function"?m:Object,typeof(v=typeof _<"u"&&_)=="function"?v:Object])],d);export{d as PluginContextService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const n=200;function i(
|
|
1
|
+
const n=200;function i(t,r="-"){let e=t.trim();e=e.replace(/^\/+/,""),e=e.replace(/[/\\]/g,r),e=e.replace(/[.<>:"|?*\x00-\x1F]/g,r),e=e.replace(/^[.\s]+|[.\s]+$/g,"");const g=new RegExp(`${r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}+`,"g");return e=e.replace(g,r),e.length>200&&(e=e.substring(0,200)),e.toLowerCase()}export{i as convertPathToValidFileName};
|