@runium/cli 0.0.2 → 0.0.3
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/.eslintrc.json +31 -0
- package/.prettierrc.json +10 -0
- package/README.md +3 -0
- package/build.js +125 -0
- package/lib/app.js +6 -0
- package/{commands → lib/commands}/index.js +0 -0
- package/lib/commands/plugin/plugin-add.js +1 -0
- package/lib/commands/plugin/plugin-disable.js +1 -0
- package/lib/commands/plugin/plugin-enable.js +1 -0
- package/lib/commands/plugin/plugin-remove.js +1 -0
- package/lib/commands/plugin/plugin.js +1 -0
- package/lib/commands/project/project-add.js +1 -0
- package/lib/commands/project/project-command.js +1 -0
- package/lib/commands/project/project-start.js +1 -0
- package/lib/commands/project/project-state-command.js +1 -0
- package/lib/commands/project/project-status.js +1 -0
- package/lib/commands/project/project-stop.js +1 -0
- package/lib/commands/project/project-validate.js +4 -0
- package/lib/commands/project/project.js +1 -0
- package/lib/commands/runium-command.js +1 -0
- package/lib/constants/error-code.js +1 -0
- package/{constants → lib/constants}/index.js +0 -0
- package/lib/index.js +2 -0
- package/lib/macros/date.js +1 -0
- package/lib/macros/index.js +1 -0
- package/lib/macros/path.js +1 -0
- package/lib/package.json +22 -0
- package/lib/services/command.js +1 -0
- package/lib/services/config.js +1 -0
- package/lib/services/file.js +1 -0
- package/lib/services/index.js +1 -0
- package/lib/services/output.js +3 -0
- package/lib/services/plugin-context.js +1 -0
- package/lib/services/plugin.js +1 -0
- package/lib/services/profile.js +1 -0
- package/lib/services/project.js +1 -0
- package/lib/services/shutdown.js +1 -0
- package/lib/utils/get-version.js +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/validation/create-validator.js +1 -0
- package/lib/validation/get-config-schema.js +1 -0
- package/lib/validation/get-error-messages.js +1 -0
- package/lib/validation/get-plugin-schema.js +1 -0
- package/lib/validation/index.js +1 -0
- package/package.json +33 -7
- package/src/app.ts +190 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/plugin/plugin-add.ts +48 -0
- package/src/commands/plugin/plugin-command.ts +36 -0
- package/src/commands/plugin/plugin-disable.ts +46 -0
- package/src/commands/plugin/plugin-enable.ts +50 -0
- package/src/commands/plugin/plugin-list.ts +61 -0
- package/src/commands/plugin/plugin-remove.ts +42 -0
- package/src/commands/plugin/plugin.ts +36 -0
- package/src/commands/project/project-add.ts +64 -0
- package/src/commands/project/project-command.ts +43 -0
- package/src/commands/project/project-list.ts +32 -0
- package/src/commands/project/project-remove.ts +41 -0
- package/src/commands/project/project-start.ts +158 -0
- package/src/commands/project/project-state-command.ts +53 -0
- package/src/commands/project/project-status.ts +116 -0
- package/src/commands/project/project-stop.ts +59 -0
- package/src/commands/project/project-validate.ts +56 -0
- package/src/commands/project/project.ts +40 -0
- package/src/commands/runium-command.ts +52 -0
- package/src/constants/error-code.ts +28 -0
- package/src/constants/index.ts +1 -0
- package/src/global.d.ts +6 -0
- package/src/index.ts +24 -0
- package/src/macros/conditional.ts +31 -0
- package/src/macros/date.ts +15 -0
- package/src/macros/empty.ts +6 -0
- package/src/macros/env.ts +8 -0
- package/src/macros/index.ts +17 -0
- package/src/macros/path.ts +24 -0
- package/src/services/command.ts +171 -0
- package/src/services/config.ts +119 -0
- package/src/services/file.ts +272 -0
- package/src/services/index.ts +9 -0
- package/src/services/output.ts +205 -0
- package/src/services/plugin-context.ts +140 -0
- package/src/services/plugin.ts +248 -0
- package/src/services/profile.ts +199 -0
- package/src/services/project.ts +142 -0
- package/src/services/shutdown.ts +147 -0
- package/src/utils/convert-path-to-valid-file-name.ts +39 -0
- package/src/utils/debounce.ts +23 -0
- package/src/utils/format-timestamp.ts +17 -0
- package/src/utils/get-version.ts +13 -0
- package/src/utils/index.ts +4 -0
- package/src/validation/create-validator.ts +27 -0
- package/src/validation/get-config-schema.ts +59 -0
- package/src/validation/get-error-messages.ts +35 -0
- package/src/validation/get-plugin-schema.ts +137 -0
- package/src/validation/index.ts +4 -0
- package/tsconfig.json +38 -0
- package/app.js +0 -6
- package/commands/plugin/plugin-add.js +0 -1
- package/commands/plugin/plugin-disable.js +0 -1
- package/commands/plugin/plugin-enable.js +0 -1
- package/commands/plugin/plugin-remove.js +0 -1
- package/commands/plugin/plugin.js +0 -1
- package/commands/project/project-add.js +0 -1
- package/commands/project/project-command.js +0 -1
- package/commands/project/project-start.js +0 -1
- package/commands/project/project-state-command.js +0 -1
- package/commands/project/project-status.js +0 -1
- package/commands/project/project-stop.js +0 -1
- package/commands/project/project-validate.js +0 -1
- package/commands/project/project.js +0 -1
- package/commands/runium-command.js +0 -1
- package/constants/error-code.js +0 -1
- package/index.js +0 -2
- package/macros/index.js +0 -1
- package/macros/path.js +0 -1
- package/services/config.js +0 -1
- package/services/index.js +0 -1
- package/services/output.js +0 -3
- package/services/plugin-context.js +0 -1
- package/services/plugin.js +0 -1
- package/services/profile.js +0 -1
- package/services/project.js +0 -1
- package/services/shutdown.js +0 -1
- package/utils/index.js +0 -1
- /package/{commands → lib/commands}/plugin/plugin-command.js +0 -0
- /package/{commands → lib/commands}/plugin/plugin-list.js +0 -0
- /package/{commands → lib/commands}/project/project-list.js +0 -0
- /package/{commands → lib/commands}/project/project-remove.js +0 -0
- /package/{macros → lib/macros}/conditional.js +0 -0
- /package/{macros → lib/macros}/empty.js +0 -0
- /package/{macros → lib/macros}/env.js +0 -0
- /package/{utils → lib/utils}/convert-path-to-valid-file-name.js +0 -0
- /package/{utils → lib/utils}/debounce.js +0 -0
- /package/{utils → lib/utils}/format-timestamp.js +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ErrorObject } from 'ajv';
|
|
2
|
+
import { AggregateAjvError, Options } from '@segment/ajv-human-errors';
|
|
3
|
+
import { AjvError } from '@segment/ajv-human-errors/dist/cjs/aggregate-ajv-error';
|
|
4
|
+
|
|
5
|
+
interface GetErrorMessagesOptions extends Options {
|
|
6
|
+
filter?: (error: AjvError) => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get error messages
|
|
11
|
+
* @param errors
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
export function getErrorMessages(
|
|
15
|
+
errors: ErrorObject[],
|
|
16
|
+
options: GetErrorMessagesOptions = {
|
|
17
|
+
filter: () => true,
|
|
18
|
+
}
|
|
19
|
+
): string[] {
|
|
20
|
+
const humanErrors = new AggregateAjvError(errors, {
|
|
21
|
+
fieldLabels: 'jsonPath',
|
|
22
|
+
includeData: true,
|
|
23
|
+
includeOriginalError: true,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const filter = options?.filter ?? (_ => true);
|
|
27
|
+
const messages = [];
|
|
28
|
+
for (const error of humanErrors) {
|
|
29
|
+
if (filter(error)) {
|
|
30
|
+
messages.push(error.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return messages;
|
|
35
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { ID_REGEX } from '@runium/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get plugin schema with function validation
|
|
5
|
+
*/
|
|
6
|
+
export function getPluginSchema(): object {
|
|
7
|
+
return {
|
|
8
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
9
|
+
$id: 'https://runium.dev/schemas/plugin.json',
|
|
10
|
+
title: 'Runium Plugin',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
name: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
minLength: 2,
|
|
16
|
+
pattern: ID_REGEX.source,
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
description: 'Plugin configuration options',
|
|
21
|
+
},
|
|
22
|
+
project: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
description: 'Project-level plugin definitions',
|
|
25
|
+
properties: {
|
|
26
|
+
macros: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
description: 'Macro definitions for config file expansion',
|
|
29
|
+
additionalProperties: {
|
|
30
|
+
instanceof: 'Function',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
tasks: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
description: 'Task constructor definitions',
|
|
36
|
+
additionalProperties: {
|
|
37
|
+
instanceof: 'Function',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
actions: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
description: 'Action function definitions',
|
|
43
|
+
additionalProperties: {
|
|
44
|
+
instanceof: 'Function',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
triggers: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
description: 'Trigger constructor definitions',
|
|
50
|
+
additionalProperties: {
|
|
51
|
+
instanceof: 'Function',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
validationSchema: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
description: 'JSON Schema extension for project config validation',
|
|
57
|
+
additionalProperties: true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
},
|
|
62
|
+
app: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
description: 'Application-level plugin definitions',
|
|
65
|
+
properties: {
|
|
66
|
+
commands: {
|
|
67
|
+
type: 'array',
|
|
68
|
+
description: 'Command constructor definitions',
|
|
69
|
+
items: {
|
|
70
|
+
instanceof: 'Function',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
},
|
|
76
|
+
hooks: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
description: 'Lifecycle hooks for app and project events',
|
|
79
|
+
properties: {
|
|
80
|
+
app: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
description: 'Application lifecycle hooks',
|
|
83
|
+
properties: {
|
|
84
|
+
afterInit: {
|
|
85
|
+
instanceof: 'Function',
|
|
86
|
+
description: 'Hook called after app initialization',
|
|
87
|
+
},
|
|
88
|
+
beforeExit: {
|
|
89
|
+
instanceof: 'Function',
|
|
90
|
+
description: 'Hook called before app exit',
|
|
91
|
+
},
|
|
92
|
+
beforeCommandRun: {
|
|
93
|
+
instanceof: 'Function',
|
|
94
|
+
description: 'Hook called before command execution',
|
|
95
|
+
},
|
|
96
|
+
afterCommandRun: {
|
|
97
|
+
instanceof: 'Function',
|
|
98
|
+
description: 'Hook called after command execution',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
},
|
|
103
|
+
project: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
description: 'Project lifecycle hooks',
|
|
106
|
+
properties: {
|
|
107
|
+
beforeConfigRead: {
|
|
108
|
+
instanceof: 'Function',
|
|
109
|
+
description: 'Hook called before reading config file',
|
|
110
|
+
},
|
|
111
|
+
afterConfigRead: {
|
|
112
|
+
instanceof: 'Function',
|
|
113
|
+
description: 'Hook called after reading config file content',
|
|
114
|
+
},
|
|
115
|
+
afterConfigMacrosApply: {
|
|
116
|
+
instanceof: 'Function',
|
|
117
|
+
description: 'Hook called after applying macros to config',
|
|
118
|
+
},
|
|
119
|
+
afterConfigParse: {
|
|
120
|
+
instanceof: 'Function',
|
|
121
|
+
description: 'Hook called after parsing config',
|
|
122
|
+
},
|
|
123
|
+
beforeStart: {
|
|
124
|
+
instanceof: 'Function',
|
|
125
|
+
description: 'Hook called before project starts',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
additionalProperties: false,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
required: ['name'],
|
|
135
|
+
additionalProperties: false,
|
|
136
|
+
};
|
|
137
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"outDir": "./lib",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"declaration": false,
|
|
14
|
+
"sourceMap": false,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"removeComments": true,
|
|
17
|
+
"emitDecoratorMetadata": true,
|
|
18
|
+
"experimentalDecorators": true,
|
|
19
|
+
"allowSyntheticDefaultImports": true,
|
|
20
|
+
"paths": {
|
|
21
|
+
"@commands/*": ["src/commands/*"],
|
|
22
|
+
"@commands": ["src/commands/index.js"],
|
|
23
|
+
"@constants/*": ["src/constants/*"],
|
|
24
|
+
"@constants": ["src/constants/index.js"],
|
|
25
|
+
"@macros/*": ["src/macros/*"],
|
|
26
|
+
"@macros": ["src/macros/index.js"],
|
|
27
|
+
"@services/*": ["src/services/*"],
|
|
28
|
+
"@services": ["src/services/index.js"],
|
|
29
|
+
"@utils/*": ["src/utils/*"],
|
|
30
|
+
"@utils": ["src/utils/index.js"],
|
|
31
|
+
"@validation/*": ["src/validation/*"],
|
|
32
|
+
"@validation": ["src/validation/index.js"]
|
|
33
|
+
},
|
|
34
|
+
"types": ["node", "@runium/types-core"]
|
|
35
|
+
},
|
|
36
|
+
"include": ["src/**/*"],
|
|
37
|
+
"exclude": ["lib/**/*"]
|
|
38
|
+
}
|
package/app.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{existsSync as u}from"node:fs";import{resolve as p}from"node:path";import{Command as v}from"commander";import{Container as o}from"typedi";import*as c from"./commands/index.js";import{ConfigService as l,ProfileService as g,PluginService as d,ShutdownService as m,OutputService as h,OutputLevel as r,PluginContextService as S}from"./services/index.js";const f=`\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
|
-
\u2551 \u2554\u2550\u2557 \u2566 \u2566 \u2554\u2557\u2554 \u2566 \u2566 \u2566 \u2554\u2566\u2557 \u2551
|
|
3
|
-
\u2551 \u2560\u2566\u255D \u2551 \u2551 \u2551\u2551\u2551 \u2551 \u2551 \u2551 \u2551\u2551\u2551 \u2551
|
|
4
|
-
\u2551 \u2569\u255A\u2550 \u255A\u2550\u255D \u255D\u255A\u255D \u2569 \u255A\u2550\u255D \u2569 \u2569 \u2551
|
|
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 F{program;configService;profileService;pluginService;shutdownService;outputService;pluginContextService;constructor(){this.program=new v("runium"),this.configService=o.get(l),this.profileService=o.get(g),this.pluginService=o.get(d),this.shutdownService=o.get(m),this.outputService=o.get(h),this.pluginContextService=o.get(S)}async start(){return await this.shutdownService.init(),await this.configService.init(),await this.profileService.init(),await this.pluginContextService.init(),this.initOutput(),this.initEnv(),await this.loadPlugins(),await this.initProgram(),this.program.parseAsync()}async loadPlugins(){const e=this.profileService.getPlugins();for(const i of e)if(i.disabled!==!0)try{const t=this.pluginService.resolvePath(i.path,i.file);await this.pluginService.loadPlugin(t)}catch(t){this.outputService.error(`Failed to load plugin "${i.name}"`);const{code:n,message:s,payload:a}=t;this.outputService.debug("Error details:",{message:s,code:n,payload:a})}}async initProgram(){const e=this.program;e.option("-D, --debug","enable debug mode"),e.option("-e, --env [paths...]","load env files"),e.version(await this.getVersion()),e.description(f),e.on("option:debug",()=>{this.setDebugMode()}),e.on("option:env",t=>{this.loadEnvFiles([t])});const i=[];Object.values(c).forEach(t=>{i.push(new t(e))})}initOutput(){(this.configService.get("output").debug||process.argv.includes("-D")||process.argv.includes("--debug"))&&this.setDebugMode()}setDebugMode(){this.outputService.getLevel()!==r.DEBUG&&(this.outputService.setLevel(r.DEBUG),this.outputService.debug("Debug mode enabled"))}initEnv(){const e=this.configService.get("env");e.path.length>0&&this.loadEnvFiles(e.path)}loadEnvFiles(e){for(const i of e)i?u(i)?process.loadEnvFile(p(i)):this.outputService.debug(`Env file "${i}" not found`):process.loadEnvFile()}async getVersion(){return(await import("./package.json",{with:{type:"json"}})).default.version}}export{F as RuniumCliApp};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{RuniumError as a}from"@runium/core";import{ErrorCode as l}from"../../constants/index.js";import{PluginCommand as t}from"./plugin-command.js";class g extends t{config(){this.command.name("add").description("add plugin").option("-f, --file","use file path instead of plugin package name").argument("<plugin>","plugin package name or absolute file path")}async handle(e,{file:n}){const o=this.pluginService.resolvePath(e,n),i=await this.pluginService.loadPlugin(o);if(this.pluginService.getPluginByName(i))await this.profileService.addPlugin({name:i,path:n?o:e,file:n,disabled:!1,options:{}}),this.outputService.success('Plugin "%s" successfully added',i);else throw new a(`Failed to add plugin "${e}"`,l.PLUGIN_NOT_FOUND,{name:i,path:e})}}export{g as PluginAddCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PluginCommand as n}from"./plugin-command.js";class o extends n{config(){this.command.name("disable").description("disable plugin").option("-a, --all","disable all plugins").argument("[plugin...]","plugin names")}async handle(e,{all:l}){if(e.length===0&&!l){this.outputService.warn("No plugins specified to disable");return}l&&(e=this.profileService.getPlugins().map(i=>i.name));for(const i of e){if(this.ensureProfilePlugin(i).disabled){this.outputService.info('Plugin "%s" is already disabled',i);continue}await this.profileService.updatePlugin(i,{disabled:!0}),await this.pluginService.unloadPlugin(i),this.outputService.success('Plugin "%s" successfully disabled',i)}}}export{o as PluginDisableCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PluginCommand as a}from"./plugin-command.js";class u extends a{config(){this.command.name("enable").description("enable plugin").option("-a, --all","enable all plugins").argument("[plugin...]","plugin names")}async handle(i,{all:l}){if(i.length===0&&!l){this.outputService.warn("No plugins specified to enable");return}l&&(i=this.profileService.getPlugins().map(e=>e.name));for(const e of i){const n=this.ensureProfilePlugin(e);if(!n.disabled){this.outputService.info('Plugin "%s" is already enabled',e);continue}await this.profileService.updatePlugin(e,{disabled:!1});const t=this.pluginService.resolvePath(n.path,n.file);await this.pluginService.loadPlugin(t),this.outputService.success('Plugin "%s" successfully enabled',e)}}}export{u as PluginEnableCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PluginCommand as n}from"./plugin-command.js";class l extends n{config(){this.command.name("remove").description("remove plugin").option("-a, --all","remove all plugins").argument("[plugin...]","plugin names")}async handle(i,{all:o}){if(i.length===0&&!o){this.outputService.warn("No plugins specified to remove");return}o&&(i=this.profileService.getPlugins().map(e=>e.name));for(const e of i)this.ensureProfilePlugin(e),await this.profileService.removePlugin(e),await this.pluginService.unloadPlugin(e),this.outputService.success('Plugin "%s" successfully removed',e)}}export{l as PluginRemoveCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{RuniumCommand as n}from"../runium-command.js";import{PluginAddCommand as i}from"./plugin-add.js";import{PluginDisableCommand as d}from"./plugin-disable.js";import{PluginEnableCommand as t}from"./plugin-enable.js";import{PluginListCommand as r}from"./plugin-list.js";import{PluginRemoveCommand as a}from"./plugin-remove.js";class f extends n{config(){this.command.name("plugin").description("manage plugins")}async handle(){this.command.help()}addSubcommands(){const o=[r,i,a,d,t];for(const m of o)this.subcommands.push(new m(this.command))}}export{f as PluginCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{RuniumError as i}from"@runium/core";import{ErrorCode as c}from"../../constants/index.js";import{ProjectCommand as d}from"./project-command.js";class m extends d{config(){this.command.name("add").description("add project").argument("<path>","project file path").argument("[name]","project name (default: project config id)")}async handle(r,o){const e=this.projectService.resolvePath(r),t=await this.projectService.initProject(e);if(t)await this.profileService.addProject({name:o??t.getConfig().id,path:e}),this.outputService.success('Project "%s" successfully added',o??t.getConfig().id);else throw new i(`Failed to add project "${e}"`,c.PROJECT_NOT_FOUND,{path:e})}}export{m as ProjectAddCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Container as o}from"typedi";import{RuniumError as t}from"@runium/core";import{RuniumCommand as i}from"../runium-command.js";import{ErrorCode as c}from"../../constants/index.js";import{ProfileService as m,ProjectService as p}from"../../services/index.js";class S extends i{projectService;profileService;constructor(r){super(r),this.projectService=o.get(p),this.profileService=o.get(m)}ensureProfileProject(r){const e=this.profileService.getProjectByName(r);if(!e)throw new t(`Project "${r}" not found`,c.PROJECT_NOT_FOUND,{name:r});return e}}export{S as ProjectCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{dirname as d}from"node:path";import{Option as j}from"commander";import{Container as m}from"typedi";import{ProjectEvent as p,RuniumError as h}from"@runium/core";import{ErrorCode as u}from"../../constants/index.js";import{ShutdownService as P}from"../../services/index.js";import{debounce as f}from"../../utils/index.js";import{ProjectStateCommand as w}from"./project-state-command.js";const S=100;class b extends w{shutdownService;constructor(t){super(t),this.shutdownService=m.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(t,{file:a,workingDir:c,output:n}){const i=a?this.projectService.resolvePath(t):this.ensureProfileProject(t).path,r=this.getProjectDataFileName(a?i:t),s=await this.readProjectData(r);if(s&&this.isProjectProcessStarted(s.pid))throw new h(`Project "${t}" is already started`,u.PROJECT_ALREADY_STARTED,{name:t});if(c==="project"){const o=d(i);o!==process.cwd()&&process.chdir(o)}const e=await this.projectService.initProject(i);this.shutdownService.addBlocker(o=>e.stop(o)),this.addProjectListeners(e,{dataFileName:r,projectPath:i,output:n}),await e.start()}addProjectListeners(t,a){const{dataFileName:c,projectPath:n,output:i}=a,r={id:t.getConfig().id,pid:process.pid,cwd:process.cwd(),path:n,state:{project:[],tasks:{}}},s=f(()=>{this.writeProjectData(r,c)},S);s(),t.on(p.STATE_CHANGE,async e=>{r.state.project.push(e),s(),i&&this.outputService.info("Project %s",e.status)}),t.on(p.TASK_STATE_CHANGE,(e,o)=>{r.state.tasks[e]||(r.state.tasks[e]=[]),r.state.tasks[e].push(o),s(),i&&this.outputService.info("Task %s %s %s",e,o.status,o.exitCode||o.error||"")})}}export{b as ProjectStartCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{convertPathToValidFileName as r}from"../../utils/index.js";import{ProjectCommand as o}from"./project-command.js";class l extends o{getProjectDataFileName(e){let t=r(e);return t.endsWith(".json")||(t=t+".json"),t}async readProjectData(e){return this.profileService.readJsonFile("projects",e).catch(()=>null)}async writeProjectData(e,t){return this.profileService.writeJsonFile(e,"projects",t)}isProjectProcessStarted(e){try{return process.kill(Number(e),0)}catch(t){return t.code==="EPERM"}}}export{l as ProjectStateCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{formatTimestamp as p}from"../../utils/index.js";import{ProjectStateCommand as j}from"./project-state-command.js";class b extends j{config(){this.command.name("status").description("get project status").option("-f, --file","use file path instead of project name").option("-t, --tasks","show task status").option("-a, --all","show status change history").argument("<name>","project name")}async handle(a,{file:n,tasks:d,all:c}){const f=n?this.projectService.resolvePath(a):this.ensureProfileProject(a).path,l=this.getProjectDataFileName(n?f:a),i=await this.readProjectData(l);if(i){let{project:s=[]}=i.state;if(c||(s=s.length>0?[s[s.length-1]]:[]),d){const r=s.map(t=>({name:"Project",status:t.status,time:p(t.timestamp),timestamp:t.timestamp})),{tasks:o=[]}=i.state,h=[];Object.entries(o).forEach(([t,e])=>{c||(e=e.length>0?[e[e.length-1]]:[]),e.forEach(m=>{h.push({name:t,status:m.status,time:p(m.timestamp),timestamp:m.timestamp})})});const u=[...r,...h];u.sort((t,e)=>t.timestamp-e.timestamp),this.outputService.table(u,["time","name","status"])}else{const r=s.map(o=>({status:o.status,time:p(o.timestamp)}));this.outputService.table(r,["time","status"])}}else this.outputService.info(`No project status for "${a}"`)}}export{b as ProjectStatusCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{RuniumError as r}from"@runium/core";import{ErrorCode as i}from"../../constants/index.js";import{ProjectStateCommand as p}from"./project-state-command.js";class j extends p{config(){this.command.name("stop").description("stop project").option("-f, --file","use file path instead of project name").argument("<name>","project name")}async handle(t,{file:e}){const a=e?this.projectService.resolvePath(t):this.ensureProfileProject(t).path,s=this.getProjectDataFileName(e?a:t),o=await this.readProjectData(s);if(!o||!this.isProjectProcessStarted(o.pid))throw new r(`Project "${t}" is not started`,i.PROJECT_NOT_STARTED,{name:t});try{process.kill(o.pid,"SIGTERM")}catch(c){throw new r(`Failed to stop project "${t}"`,i.PROJECT_STOP_ERROR,{name:t,original:c})}}}export{j as ProjectStopCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ProjectCommand as r}from"./project-command.js";class n extends r{config(){this.command.name("validate").description("validate project").option("-f, --file","use file path instead of project name").argument("<project>","project name or file path")}async handle(e,{file:t}){const i=t?this.projectService.resolvePath(e):this.ensureProfileProject(e).path,o=await this.projectService.initProject(i);try{await o.validate(),this.outputService.success('Project "%s" is valid',e)}catch(a){this.outputService.error('Project "%s" validation failed',e,a)}}}export{n as ProjectValidateCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{RuniumCommand as t}from"../runium-command.js";import{ProjectAddCommand as r}from"./project-add.js";import{ProjectListCommand as d}from"./project-list.js";import{ProjectRemoveCommand as e}from"./project-remove.js";import{ProjectStartCommand as n}from"./project-start.js";import{ProjectStopCommand as c}from"./project-stop.js";import{ProjectStatusCommand as a}from"./project-status.js";import{ProjectValidateCommand as i}from"./project-validate.js";class v extends t{config(){this.command.name("project").description("manage projects")}async handle(){this.command.help()}addSubcommands(){const o=[d,r,e,n,c,a,i];for(const m of o)this.subcommands.push(new m(this.command))}}export{v as ProjectCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Command as o}from"commander";import{Container as m}from"typedi";import{OutputService as d}from"../services/index.js";class i{outputService;parent;command;subcommands=[];constructor(t){this.outputService=m.get(d),this.parent=t,this.command=new o,this.config(),this.command.action(this.handle.bind(this)),this.addSubcommands(),this.parent.addCommand(this.command)}addSubcommands(){}}export{i as RuniumCommand};
|
package/constants/error-code.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var R=(_=>(_.PLUGIN_NOT_FOUND="plugin-not-found",_.PLUGIN_FILE_NOT_FOUND="plugin-file-not-found",_.PLUGIN_INCORRECT_MODULE="plugin-incorrect-module",_.PLUGIN_INCORRECT_PLUGIN="plugin-incorrect-plugin",_.PLUGIN_PATH_RESOLVE_ERROR="plugin-path-resolve-error",_.PROJECT_ALREADY_STARTED="project-already-started",_.PROJECT_NOT_STARTED="project-not-started",_.PROJECT_STOP_ERROR="project-stop-error",_.PROJECT_NOT_FOUND="project-not-found",_.PROJECT_FILE_NOT_FOUND="project-file-not-found",_.PROJECT_FILE_CAN_NOT_READ="project-file-can-not-read",_.PROJECT_JSON_PARSE_ERROR="project-json-parse-error",_.PROFILE_JSON_WRITE_ERROR="profile-json-write-error",_))(R||{});export{R as ErrorCode};
|
package/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import"reflect-metadata";import{Container as e}from"typedi";import{RuniumCliApp as r}from"./app.js";import{OutputService as a}from"./services/index.js";async function i(){await new r().start()}i().catch(o=>{const t=e.get(a);t.error("Error: %s",o.message),t.debug("Error details:",{code:o.code,payload:o.payload}),process.exit(1)});
|
package/macros/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{eqMacro as o,neMacro as r}from"./conditional.js";import{emptyMacro as m}from"./empty.js";import{envMacro as t}from"./env.js";import{pathMacro as e}from"./path.js";const M={env:t,empty:m,eq:o,ne:r,path:e};export{M as macros};
|
package/macros/path.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{resolve as t}from"node:path";function n(r){return t(r)}export{n as pathMacro};
|
package/services/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=function(r,t,e,i){var n=arguments.length,o=n<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,t,e,i);else for(var p=r.length-1;p>=0;p--)(a=r[p])&&(o=(n<3?a(o):n>3?a(t,e,o):a(t,e))||o);return n>3&&o&&Object.defineProperty(t,e,o),o};import{existsSync as f}from"node:fs";import{homedir as _}from"node:os";import{join as s,resolve as l}from"node:path";import{Service as v}from"typedi";import{readJsonFile as O}from"@runium/core";const j=".runiumrc.json",u=s(process.cwd(),j),h=".runium",E=s(_(),h),m=s(process.cwd(),h);let c=class{data={profile:{path:E},output:{debug:!1},env:{path:[]}};async init(){if(f(m)&&(this.data.profile.path=m),f(u)){const t=await O(u);if(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??{})};e.env.path=e.env.path.map(i=>l(i)),e.profile.path=l(e.profile.path),this.data=e}}}get(t){return this.data[t]}};c=d([v()],c);export{c as ConfigService};
|
package/services/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export*from"./config.js";export*from"./output.js";export*from"./profile.js";export*from"./plugin.js";export*from"./project.js";export*from"./shutdown.js";export*from"./plugin-context.js";
|
package/services/output.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var a=function(t,o,e,s){var i=arguments.length,r=i<3?o:s===null?s=Object.getOwnPropertyDescriptor(o,e):s,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(t,o,e,s);else for(var c=t.length-1;c>=0;c--)(l=t[c])&&(r=(i<3?l(r):i>3?l(o,e,r):l(o,e))||r);return i>3&&r&&Object.defineProperty(o,e,r),r};import{Console as u}from"node:console";import{Transform as h}from"node:stream";import{Service as p}from"typedi";var n;(function(t){t[t.TRACE=0]="TRACE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT"})(n||(n={}));class R extends u{transform;constructor(){const o=new h({transform:(e,s,i)=>i(null,e)});super({stdout:o,stderr:o,colorMode:!1}),this.transform=o}getPatchedTable(o,e){this.table(o,e);const s=(this.transform.read()||"").toString(),i=s.indexOf("\u252C")+1;return s.split(`
|
|
2
|
-
`).map(r=>r.charAt(0)+r.slice(i)).join(`
|
|
3
|
-
`)}}const m=new R;let f=class{outputLevel=n.INFO;setLevel(o){this.outputLevel=o}getLevel(){return this.outputLevel}trace(o,...e){this.outputLevel<=n.TRACE&&console.log(o,...e)}debug(o,...e){this.outputLevel<=n.DEBUG&&console.log(o,...e)}info(o,...e){this.outputLevel<=n.INFO&&console.log(o,...e)}success(o,...e){this.outputLevel<=n.INFO&&console.log(o,...e)}warn(o,...e){this.outputLevel<=n.WARN&&console.warn(o,...e)}error(o,...e){this.outputLevel<=n.ERROR&&console.error(o,...e)}log(o,...e){this.outputLevel<n.SILENT&&console.log(o,...e)}table(o,e){if(this.outputLevel<n.SILENT){const s=o.map((r,l)=>({...r,"#":l+1})),i=m.getPatchedTable(s,e?["#",...e]:void 0);console.log(i)}}newLine(){this.outputLevel<n.SILENT&&console.log("")}clear(){this.outputLevel<n.SILENT&&console.clear()}};f=a([p()],f);export{n as OutputLevel,f as OutputService};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var v=function(i,e,t,o){var n=arguments.length,r=n<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(i,e,t,o);else for(var c=i.length-1;c>=0;c--)(u=i[c])&&(r=(n<3?u(r):n>3?u(e,t,r):u(e,t))||r);return n>3&&r&&Object.defineProperty(e,t,r),r},h=function(i,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,e)},l=function(i,e){return function(t,o){e(t,o,i)}},s,f;import{Inject as d,Service as S}from"typedi";import{RuniumError as _,isRuniumError as g,RuniumTask as j,RuniumTrigger as R,readJsonFile as w,writeJsonFile as O,applyMacros as y,Task as L,TaskEvent as P,TaskStatus as T,ProjectEvent as k,ProjectStatus as B}from"@runium/core";import{RuniumCommand as E}from"../commands/runium-command.js";import{OutputLevel as m,OutputService as p,ShutdownService as b}from"./index.js";global.runium=null;let a=class{outputService;shutdownService;constructor(e,t){this.outputService=e,this.shutdownService=t}async init(){const e=this.outputService,t=this.shutdownService,o={class:{RuniumCommand:E,RuniumError:_,RuniumTask:j,RuniumTrigger:R,Task:L},enum:{OutputLevel:Object.keys(m).filter(n=>isNaN(Number(n))).reduce((n,r)=>(n[r]=m[r],n),{}),ProjectEvent:k,ProjectStatus:B,TaskEvent:P,TaskStatus:T},utils:{applyMacros:y,isRuniumError:g,readJsonFile:w,writeJsonFile:O},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:t.addBlocker.bind(t),removeBlocker:t.removeBlocker.bind(t)}};global.runium=Object.freeze(o)}};a=v([S(),l(0,d()),l(1,d()),h("design:paramtypes",[typeof(s=typeof p<"u"&&p)=="function"?s:Object,typeof(f=typeof b<"u"&&b)=="function"?f:Object])],a);export{a as PluginContextService};
|
package/services/plugin.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=function(u,e,r,n){var t=arguments.length,o=t<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(u,e,r,n);else for(var a=u.length-1;a>=0;a--)(s=u[a])&&(o=(t<3?s(o):t>3?s(e,r,o):s(e,r))||o);return t>3&&o&&Object.defineProperty(e,r,o),o};import{existsSync as m}from"node:fs";import{resolve as g}from"node:path";import{Service as P}from"typedi";import{isRuniumError as d,RuniumError as i}from"@runium/core";import{ErrorCode as l}from"../constants/index.js";let f=class{plugins=new Map;getAllPlugins(){return Array.from(this.plugins.values())}getPluginByName(e){return this.plugins.get(e)}async loadPlugin(e){if(!e||!m(e))throw new i(`Plugin file "${e}" does not exist`,l.PLUGIN_FILE_NOT_FOUND,{path:e});try{const r=await import(e),{default:n}=r;if(!n||typeof n!="function")throw new i("Plugin module must have a default function",l.PLUGIN_INCORRECT_MODULE,{path:e});const t=n();return this.validate(t),this.plugins.set(t.name,t),t.name}catch(r){throw d(r)?r:new i(`Failed to load plugin "${e}"`,l.PLUGIN_INCORRECT_PLUGIN,{path:e,original:r})}}async unloadPlugin(e){return this.plugins.delete(e)}resolvePath(e,r=!1){try{return(r?g(e):import.meta.resolve(e)).replace("file://","")}catch(n){throw new i(`Failed to resolve plugin path "${e}"`,l.PLUGIN_PATH_RESOLVE_ERROR,{path:e,original:n})}}validate(e){if(!e||!e?.name)throw new i("Incorrect plugin format",l.PLUGIN_INCORRECT_PLUGIN,{name:e.name})}};f=c([P()],f);export{f as PluginService};
|
package/services/profile.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=function(s,t,i,e){var r=arguments.length,n=r<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,i):e,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(s,t,i,e);else for(var o=s.length-1;o>=0;o--)(a=s[o])&&(n=(r<3?a(n):r>3?a(t,i,n):a(t,i))||n);return r>3&&n&&Object.defineProperty(t,i,n),n},j=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)},w=function(s,t){return function(i,e){t(i,e,s)}},l;import{existsSync as u}from"node:fs";import{mkdir as f}from"node:fs/promises";import{dirname as y,join as _}from"node:path";import{Inject as v,Service as R}from"typedi";import{readJsonFile as c,RuniumError as S,writeJsonFile as h}from"@runium/core";import{ConfigService as g}from"./index.js";import{ErrorCode as E}from"../constants/index.js";const m="plugins.json",P="projects.json";let p=class{configService;path=process.cwd();plugins=[];projects=[];constructor(t){this.configService=t}async init(){this.path=this.configService.get("profile").path,u(this.path)||await f(this.path,{recursive:!0}),await this.readPlugins(),await this.readProjects()}getPlugins(){return this.plugins}getPluginByName(t){return this.plugins.find(i=>i.name===t)}async addPlugin(t){this.plugins=this.plugins.filter(i=>i.name!==t.name).concat(t),await this.writePlugins()}async removePlugin(t){this.plugins=this.plugins.filter(i=>i.name!==t),await this.writePlugins()}async updatePlugin(t,i){const e=this.plugins.findIndex(r=>r.name===t);e!==-1&&(this.plugins[e]={...this.plugins[e],...i},await this.writePlugins())}getProjects(){return this.projects}getProjectByName(t){return this.projects.find(i=>i.name===t)}async addProject(t){this.projects=this.projects.filter(i=>i.name!==t.name).concat(t),await this.writeProjects()}async removeProject(t){this.projects=this.projects.filter(i=>i.name!==t),await this.writeProjects()}async readJsonFile(...t){return c(this.getPath(...t))}async writeJsonFile(t,...i){const e=this.getPath(...i);try{const r=y(e);u(r)||await f(r,{recursive:!0}),await h(e,t)}catch(r){throw new S("Failed to write JSON file",E.PROFILE_JSON_WRITE_ERROR,{path:e,data:t,original:r})}}getPath(...t){return _(this.path,...t)}async readPlugins(){this.plugins=await c(this.getPath(m)).catch(()=>[])||this.plugins}async writePlugins(){await h(this.getPath(m),this.plugins)}async readProjects(){this.projects=await c(this.getPath(P)).catch(()=>[])||this.projects}async writeProjects(){await h(this.getPath(P),this.projects)}};p=d([R(),w(0,v()),j("design:paramtypes",[typeof(l=typeof g<"u"&&g)=="function"?l:Object])],p);export{p as ProfileService};
|
package/services/project.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=function(n,e,t,r){var i=arguments.length,o=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,e,t,r);else for(var s=n.length-1;s>=0;s--)(c=n[s])&&(o=(i<3?c(o):i>3?c(e,t,o):c(e,t))||o);return i>3&&o&&Object.defineProperty(e,t,o),o},_=function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},h=function(n,e){return function(t,r){e(t,r,n)}},m;import{existsSync as j}from"node:fs";import{readFile as P}from"node:fs/promises";import{resolve as v}from"node:path";import{Inject as O,Service as R}from"typedi";import{applyMacros as E,Project as S,RuniumError as f}from"@runium/core";import{ErrorCode as u}from"../constants/index.js";import{macros as y}from"../macros/index.js";import{PluginService as g}from"./index.js";let p=class{pluginService;constructor(e){this.pluginService=e}async initProject(e){const t=await this.readFile(e),r=this.applyMacros(t),i=this.parseProjectContent(r,e),o=new S(i);return this.extendProjectWithPlugins(o)}resolvePath(e){return v(e)}async readFile(e){if(!j(e))throw new f(`Project file "${e}" does not exist`,u.PROJECT_FILE_NOT_FOUND,{path:e});try{return P(e,{encoding:"utf-8"})}catch(t){throw new f(`Failed to read project file "${e}"`,u.PROJECT_FILE_CAN_NOT_READ,{path:e,original:t})}}applyMacros(e){const r=this.pluginService.getAllPlugins().reduce((i,o)=>({...i,...o.project?.macros||{}}),{});return E(e,{...r,...y})}parseProjectContent(e,t){try{return JSON.parse(e)}catch(r){throw new f(`Failed to parse project "${t}"`,u.PROJECT_JSON_PARSE_ERROR,{path:t,original:r})}}extendProjectWithPlugins(e){return this.pluginService.getAllPlugins().forEach(r=>{const{tasks:i,actions:o,triggers:c,validationSchema:s}=r.project||{};Object.entries(o||{}).forEach(([a,l])=>{e.registerAction(a,l)}),Object.entries(i||{}).forEach(([a,l])=>{e.registerTask(a,l)}),Object.entries(c||{}).forEach(([a,l])=>{e.registerTrigger(a,l)}),s&&e.extendValidationSchema(s)}),e}};p=d([R(),h(0,O()),_("design:paramtypes",[typeof(m=typeof g<"u"&&g)=="function"?m:Object])],p);export{p as ProjectService};
|
package/services/shutdown.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=function(i,t,e,o){var s=arguments.length,r=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(i,t,e,o);else for(var n=i.length-1;n>=0;n--)(c=i[n])&&(r=(s<3?c(r):s>3?c(t,e,r):c(t,e))||r);return s>3&&r&&Object.defineProperty(t,e,r),r},f=function(i,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,t)},l=function(i,t){return function(e,o){t(e,o,i)}},a;import{Inject as m,Service as S}from"typedi";import{OutputService as h}from"./index.js";const p=3e4,w=250,v=["SIGHUP","SIGINT","SIGTERM","SIGQUIT"];let u=class{outputService;blockers=new Set;isShuttingDown=!1;constructor(t){this.outputService=t}async init(){v.forEach(t=>{process.on(t,()=>{this.shutdown(t).catch(e=>{this.outputService.error("Error during shutdown: %s",e.message),this.outputService.debug("Error details:",e),process.exit(1)})})}),process.on("uncaughtException",t=>{this.outputService.error("Uncaught exception: %s",t.message),this.outputService.debug("Error details:",t),this.shutdown("uncaughtException").catch(()=>{process.exit(1)})}),process.on("unhandledRejection",(t,e)=>{this.outputService.error("Unhandled rejection at:",e,"reason:",t),this.outputService.debug("Error details:",{reason:t,promise:e}),this.shutdown("unhandledRejection").catch(()=>{process.exit(1)})}),process.on("beforeExit",()=>{this.isShuttingDown||this.shutdown("exit").catch(()=>{process.exit(1)})})}addBlocker(t){this.blockers.add(t)}removeBlocker(t){return this.blockers.delete(t)}async shutdown(t){if(this.isShuttingDown||!t)return;this.isShuttingDown=!0;const e=o=>{setTimeout(()=>{process.exit(o)},w)};if(this.blockers.size===0){e(0);return}try{await this.executeBlockersWithTimeout(t),e(0)}catch{e(1)}}async executeBlockersWithTimeout(t){const e=Array.from(this.blockers).map(s=>this.executeBlocker(s,t)),o=new Promise((s,r)=>{setTimeout(()=>{r(new Error(`Shutdown timeout after ${p}ms`))},p)});await Promise.race([Promise.allSettled(e),o])}async executeBlocker(t,e){await t(e)}};u=d([S(),l(0,m()),f("design:paramtypes",[typeof(a=typeof h<"u"&&h)=="function"?a:Object])],u);export{u as ShutdownService};
|
package/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{convertPathToValidFileName as r}from"./convert-path-to-valid-file-name.js";import{debounce as t}from"./debounce.js";import{formatTimestamp as f}from"./format-timestamp.js";export{r as convertPathToValidFileName,t as debounce,f as formatTimestamp};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|