@akala/pm 9.0.1 → 9.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/changelog.md +2 -3
- package/commands.json +5 -2
- package/dist/esm/akala.mjs +2 -1
- package/dist/esm/akala.mjs.map +1 -1
- package/dist/esm/commands/restart.js +1 -1
- package/dist/esm/commands/restart.js.map +1 -1
- package/dist/esm/commands/start.d.ts +2 -2
- package/dist/esm/commands/start.js +24 -23
- package/dist/esm/commands/start.js.map +1 -1
- package/dist/esm/container.d.ts +2 -2
- package/dist/esm/container.js +1 -1
- package/dist/esm/container.js.map +1 -1
- package/dist/esm/fork.js +17 -17
- package/dist/esm/fork.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/akala.mts +2 -1
- package/src/commands/restart.ts +1 -1
- package/src/commands/start.json +3 -1
- package/src/commands/start.ts +24 -24
- package/src/container.ts +3 -3
- package/src/fork.ts +24 -24
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"pm": "dist/esm/cli.js",
|
5
5
|
"pm-fork": "dist/esm/fork.js"
|
6
6
|
},
|
7
|
-
"version": "9.0.
|
7
|
+
"version": "9.0.3",
|
8
8
|
"scripts": {
|
9
9
|
"test": "echo 1",
|
10
10
|
"generate": "ac generate dist/esm/commands commands.json",
|
@@ -26,11 +26,11 @@
|
|
26
26
|
"src/fork.ts"
|
27
27
|
],
|
28
28
|
"dependencies": {
|
29
|
-
"@akala/cli": "^2.13.
|
30
|
-
"@akala/commands": "^8.0.
|
31
|
-
"@akala/config": "^4.0.
|
32
|
-
"@akala/core": "^15.0.
|
33
|
-
"@akala/json-rpc-ws": "^10.5.
|
29
|
+
"@akala/cli": "^2.13.23",
|
30
|
+
"@akala/commands": "^8.0.2",
|
31
|
+
"@akala/config": "^4.0.36",
|
32
|
+
"@akala/core": "^15.0.2",
|
33
|
+
"@akala/json-rpc-ws": "^10.5.2",
|
34
34
|
"reflect-metadata": "^0.2.2",
|
35
35
|
"source-map-support": "^0.5.21"
|
36
36
|
},
|
package/src/akala.mts
CHANGED
@@ -12,6 +12,7 @@ import { CliContext, ErrorMessage, NamespaceMiddleware, unparse } from '@akala/c
|
|
12
12
|
import { InteractError } from './index.js';
|
13
13
|
import { ObservableObject, Parser } from '@akala/core';
|
14
14
|
import module from 'module'
|
15
|
+
import commands from './container.js';
|
15
16
|
|
16
17
|
const require = module.createRequire(import.meta.url);
|
17
18
|
|
@@ -152,7 +153,7 @@ export default function (_config, program: NamespaceMiddleware)
|
|
152
153
|
if (!processor)
|
153
154
|
processor = new Processors.JsonRpc(Processors.JsonRpc.getConnection(new NetSocketAdapter(socket)));
|
154
155
|
if (!metaContainer)
|
155
|
-
metaContainer =
|
156
|
+
metaContainer = commands.meta;
|
156
157
|
if (!container)
|
157
158
|
{
|
158
159
|
container = proxy(metaContainer, processor);
|
package/src/commands/restart.ts
CHANGED
@@ -5,5 +5,5 @@ import { CliContext } from "@akala/cli";
|
|
5
5
|
export default async function restart(pm: pmContainer.container, name: string, context?: CliContext<{ new?: boolean, name: string, inspect?: boolean, verbose?: boolean, wait?: boolean }>): Promise<void | { execPath: string, args: string[], cwd: string, stdio: StdioOptions, shell: boolean, windowsHide: boolean }>
|
6
6
|
{
|
7
7
|
await pm.dispatch('stop', name);
|
8
|
-
await pm.dispatch('start', name, context);
|
8
|
+
await pm.dispatch('start', name, context.options, context);
|
9
9
|
}
|
package/src/commands/start.json
CHANGED
package/src/commands/start.ts
CHANGED
@@ -16,18 +16,18 @@ import { fileURLToPath } from 'url'
|
|
16
16
|
//@ts-ignore
|
17
17
|
const _dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url))
|
18
18
|
|
19
|
-
export default async function start(this: State, pm: pmContainer.container & Container<State>, name: string,
|
19
|
+
export default async function start(this: State, pm: pmContainer.container & Container<State>, name: string, options?: CliContext<{ new?: boolean, name: string, keepAttached?: boolean, inspect?: boolean, verbose?: boolean, wait?: boolean }>['options'], context?: Pick<CliContext<{}>, 'args'>): Promise<void | { execPath: string, args: string[], cwd: string, stdio: StdioOptions, shell: boolean, windowsHide: boolean }>
|
20
20
|
{
|
21
21
|
let args: string[];
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
if (options)
|
23
|
+
if (!options.name && options.new)
|
24
|
+
options.name = getRandomName();
|
25
|
+
else if (!options.name)
|
26
|
+
options.name = name;
|
27
27
|
|
28
28
|
if (this.isDaemon)
|
29
29
|
{
|
30
|
-
var instanceConfig = this.config.mapping[
|
30
|
+
var instanceConfig = this.config.mapping[options.name || name];
|
31
31
|
var def: ProxyConfiguration<SidecarMetadata>;
|
32
32
|
if (typeof instanceConfig == 'undefined')
|
33
33
|
def = this.config.containers[name];
|
@@ -35,7 +35,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
35
35
|
def = this.config.containers[instanceConfig.container];
|
36
36
|
|
37
37
|
// eslint-disable-next-line no-var
|
38
|
-
var container = this.processes[
|
38
|
+
var container = this.processes[options.name || name];
|
39
39
|
if (container && container.running)
|
40
40
|
throw new Error(container.name + ' is already started');
|
41
41
|
|
@@ -47,7 +47,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
47
47
|
throw new ErrorWithStatus(404, `No mapping was found for ${name}. Did you want to run \`pm install ${name}\` or maybe are you missing the folder to ${name} ?`)
|
48
48
|
}
|
49
49
|
|
50
|
-
args.unshift(...context
|
50
|
+
args.unshift(...context?.args, ...unparseOptions({ ...options, program: undefined, new: undefined, inspect: undefined }, { ignoreUndefined: true }));
|
51
51
|
if (def && def.get('path'))
|
52
52
|
args.unshift('--program=' + def.get('path'));
|
53
53
|
else
|
@@ -58,7 +58,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
58
58
|
if (name != 'pm')
|
59
59
|
throw new ErrorWithStatus(40, 'this command needs to run through daemon process');
|
60
60
|
|
61
|
-
args = [...context
|
61
|
+
args = [...context?.args, ...unparseOptions({ ...options, inspect: undefined })];
|
62
62
|
}
|
63
63
|
|
64
64
|
if (!def?.type || def.type == 'nodejs')
|
@@ -67,18 +67,18 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
67
67
|
args.unshift(path.resolve(_dirname, '../fork'))
|
68
68
|
}
|
69
69
|
|
70
|
-
if (
|
70
|
+
if (options && options.inspect)
|
71
71
|
args.unshift('--inspect-brk');
|
72
72
|
|
73
73
|
args.unshift(...process.execArgv);
|
74
74
|
|
75
|
-
if (
|
75
|
+
if (options && options.verbose)
|
76
76
|
args.push('-v')
|
77
77
|
|
78
78
|
let cp: ChildProcess;
|
79
79
|
if (!this.isDaemon)
|
80
80
|
{
|
81
|
-
if (
|
81
|
+
if (options.keepAttached)
|
82
82
|
cp = spawn(process.execPath, args, { cwd: process.cwd(), stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
|
83
83
|
else
|
84
84
|
cp = spawn(process.execPath, args, { cwd: process.cwd(), detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });
|
@@ -95,7 +95,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
95
95
|
{
|
96
96
|
cp.on('disconnect', function ()
|
97
97
|
{
|
98
|
-
if (!
|
98
|
+
if (!options.keepAttached)
|
99
99
|
cp.unref();
|
100
100
|
console.log('pm started');
|
101
101
|
resolve();
|
@@ -108,21 +108,21 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
108
108
|
{
|
109
109
|
var missingDeps = def.dependencies.filter(d => !this.config.mapping[d]);
|
110
110
|
if (missingDeps.length > 0)
|
111
|
-
throw new ErrorWithStatus(404, `Some dependencies are missing to start ${
|
111
|
+
throw new ErrorWithStatus(404, `Some dependencies are missing to start ${options.name}:\n\t-${missingDeps.join('\n\t-')}`);
|
112
112
|
|
113
|
-
await eachAsync(def.dependencies, (dep) => pm.dispatch('start', dep, { name:
|
113
|
+
await eachAsync(def.dependencies, async (dep) => { await pm.dispatch('start', dep, { name: options.name + '-' + dep, wait: true }) });
|
114
114
|
}
|
115
115
|
|
116
116
|
if (def?.type && def.type !== 'nodejs')
|
117
117
|
throw new ErrorWithStatus(400, `container with type ${this.config.containers[name]?.type} are not yet supported`);
|
118
|
-
cp = spawn(process.execPath, args, { cwd: process.cwd(), detached: !
|
119
|
-
cp.stderr?.pipe(new NewLinePrefixer(
|
120
|
-
cp.stdout?.pipe(new NewLinePrefixer(
|
118
|
+
cp = spawn(process.execPath, args, { cwd: process.cwd(), detached: !options.keepAttached, env: Object.assign({ DEBUG_COLORS: true }, process.env), stdio: ['ignore', 'pipe', 'pipe', 'ipc'], shell: false, windowsHide: true });
|
119
|
+
cp.stderr?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: true })).pipe(process.stderr);
|
120
|
+
cp.stdout?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: true })).pipe(process.stdout);
|
121
121
|
|
122
122
|
if (!container || !container.running)
|
123
123
|
{
|
124
124
|
const socket = new IpcAdapter(cp);
|
125
|
-
container = new Container(
|
125
|
+
container = new Container(options.name, null) as RunningContainer;
|
126
126
|
const connection = Processors.JsonRpc.getConnection(socket, pm, (params) =>
|
127
127
|
{
|
128
128
|
params.process = cp;
|
@@ -132,14 +132,14 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
132
132
|
|
133
133
|
connection.on('close', function disconnected()
|
134
134
|
{
|
135
|
-
console.warn(`${
|
135
|
+
console.warn(`${options.name} has disconnected`);
|
136
136
|
container.running = false;
|
137
137
|
});
|
138
138
|
|
139
139
|
if (def?.commandable)
|
140
140
|
pm.register(container, def?.stateless);
|
141
141
|
|
142
|
-
this.processes[
|
142
|
+
this.processes[options.name] = container;
|
143
143
|
}
|
144
144
|
container.process = cp;
|
145
145
|
|
@@ -161,7 +161,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
161
161
|
});
|
162
162
|
}, () =>
|
163
163
|
{
|
164
|
-
console.warn(`${
|
164
|
+
console.warn(`${options.name} has disconnected`);
|
165
165
|
container.running = false;
|
166
166
|
});
|
167
167
|
|
@@ -177,7 +177,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
|
|
177
177
|
container.ready.reject(new Error('program stopped: ' + buffer?.join('')));
|
178
178
|
}
|
179
179
|
});
|
180
|
-
if (
|
180
|
+
if (options.wait && container.commandable)
|
181
181
|
{
|
182
182
|
//eslint-disable-next-line no-inner-declarations
|
183
183
|
function gather(chunk: string)
|
package/src/container.ts
CHANGED
@@ -24,7 +24,7 @@ namespace commands
|
|
24
24
|
dispatch (cmd:'ready', ...args: []): ReturnType<typeof import('./commands/ready.js').default>
|
25
25
|
dispatch (cmd:'reload-metadata', ...args: [Argument0<typeof import('./commands/reload-metadata.js').default>]): ReturnType<typeof import('./commands/reload-metadata.js').default>
|
26
26
|
dispatch (cmd:'restart', ...args: [Argument1<typeof import('./commands/restart.js').default>, Argument2<typeof import('./commands/restart.js').default>]): ReturnType<typeof import('./commands/restart.js').default>
|
27
|
-
dispatch (cmd:'start', ...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
|
27
|
+
dispatch (cmd:'start', ...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>, Argument3<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
|
28
28
|
dispatch (cmd:'status', ...args: [Argument0<typeof import('./commands/status.js').default>]): ReturnType<typeof import('./commands/status.js').default>
|
29
29
|
dispatch (cmd:'stop', ...args: [Argument0<typeof import('./commands/stop.js').default>]): ReturnType<typeof import('./commands/stop.js').default>
|
30
30
|
dispatch (cmd:'update', ...args: [Argument0<typeof import('./commands/update.js').default>, Argument1<typeof import('./commands/update.js').default>, Argument2<typeof import('./commands/update.js').default>]): ReturnType<typeof import('./commands/update.js').default>
|
@@ -48,13 +48,13 @@ namespace commands
|
|
48
48
|
'ready'(...args: []): ReturnType<typeof import('./commands/ready.js').default>
|
49
49
|
'reload-metadata'(...args: [Argument0<typeof import('./commands/reload-metadata.js').default>]): ReturnType<typeof import('./commands/reload-metadata.js').default>
|
50
50
|
'restart'(...args: [Argument1<typeof import('./commands/restart.js').default>, Argument2<typeof import('./commands/restart.js').default>]): ReturnType<typeof import('./commands/restart.js').default>
|
51
|
-
'start'(...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
|
51
|
+
'start'(...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>, Argument3<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
|
52
52
|
'status'(...args: [Argument0<typeof import('./commands/status.js').default>]): ReturnType<typeof import('./commands/status.js').default>
|
53
53
|
'stop'(...args: [Argument0<typeof import('./commands/stop.js').default>]): ReturnType<typeof import('./commands/stop.js').default>
|
54
54
|
'update'(...args: [Argument0<typeof import('./commands/update.js').default>, Argument1<typeof import('./commands/update.js').default>, Argument2<typeof import('./commands/update.js').default>]): ReturnType<typeof import('./commands/update.js').default>
|
55
55
|
'version'(...args: [Argument0<typeof import('./commands/version.js').default>, Argument1<typeof import('./commands/version.js').default>]): ReturnType<typeof import('./commands/version.js').default>
|
56
56
|
}
|
57
|
-
export const meta={"name":"commands","commands":[{"name":"$init","config":{"fs":{"disabled":true,"path":"dist/esm/commands/$init.js","source":"src/commands/$init.ts","inject":["$container","param.0"]},"":{"inject":["$container","param.0"]},"cli":{"inject":["$container","context"],"usage":"$init [...args]","options":{"configFile":{"needsValue":true,"aliases":["c"]},"keepAttached":{"needsValue":true}}}}},{"name":"bridge","config":{"fs":{"inject":["param.0","param.1"],"path":"dist/esm/commands/bridge.js","source":"src/commands/bridge.ts"},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":[]}}},{"name":"config","config":{"fs":{"path":"dist/esm/commands/config.js","source":"src/commands/config.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["param.0","options"]}}},{"name":"connect","config":{"fs":{"path":"dist/esm/commands/connect.js","source":"src/commands/connect.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"usage":"connect <name>","inject":["options.name","context"],"options":{"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"discover","config":{"fs":{"path":"dist/esm/commands/discover.js","source":"src/commands/discover.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"usage":"discover <name> <folder>","options":{"folder":{"normalize":true}},"inject":["options.name","options.folder","$container"]}}},{"name":"install","config":{"fs":{"path":"dist/esm/commands/install.js","source":"src/commands/install.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"link","config":{"fs":{"path":"dist/esm/commands/link.js","source":"src/commands/link.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"inject":["param.0","param.1","$container"]}}},{"name":"log","config":{"fs":{"path":"dist/esm/commands/log.js","source":"src/commands/log.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"ls","config":{"fs":{"path":"dist/esm/commands/ls.js","source":"src/commands/ls.ts","inject":[]},"":{"inject":[]},"cli":{"inject":[]}}},{"name":"map","config":{"fs":{"path":"dist/esm/commands/map.js","source":"src/commands/map.ts","inject":["param.0","param.1","param.2","param.3"]},"":{"inject":["param.0","param.1","param.2","param.3"]},"cli":{"inject":["options.name","options.path","cwd","options"],"options":{"commandable":{"aliases":["c"],"needsValue":false},"stateless":{"aliases":["s"],"needsValue":false}},"usage":"map <name> <path>"}}},{"name":"name","config":{"fs":{"path":"dist/esm/commands/name.js","source":"src/commands/name.ts","inject":["param.0"]},"":{"inject":["param.0"]}}},{"name":"plugin.add","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/plugin/add.js","source":"src/commands/plugin/add.ts"},"":{"inject":["param.0"]},"cli":{"usage":"add <plugin>","inject":["options.plugin"],"options":{"plugin":{"normalize":true}}}}},{"name":"plugin.remove","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/plugin/remove.js","source":"src/commands/plugin/remove.ts"},"":{"inject":["param.0"]},"cli":{"usage":"remove <plugin>","inject":["options.plugin"],"options":{"plugin":{"normalize":true}}}}},{"name":"proxy","config":{"fs":{"path":"dist/esm/commands/proxy.js","source":"src/commands/proxy.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"ready","config":{"fs":{"path":"dist/esm/commands/ready.js","source":"src/commands/ready.ts","inject":["$container","ignore"]},"jsonrpc":{"inject":["$container","dummy","connectionAsContainer"]},"":{"inject":["$container","connectionAsContainer"]}}},{"name":"reload-metadata","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/reload-metadata.js","source":"src/commands/reload-metadata.ts"},"jsonrpc":{"inject":["connectionAsContainer"]},"":{"inject":["param.0"]}}},{"name":"restart","config":{"fs":{"path":"dist/esm/commands/restart.js","source":"src/commands/restart.ts","inject":["$container","param.0","param.1"]},"":{"inject":["$container","param.0","param.1"]},"cli":{"options":{"wait":{"aliases":["w"]},"inspect":{},"new":{},"name":{}},"inject":["$container","param.0","context"]}}},{"name":"start","config":{"fs":{"path":"dist/esm/commands/start.js","source":"src/commands/start.ts","inject":["$container","param.0","param.1"]},"":{"inject":["$container","param.0","param.1"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["$container","options.program","context"],"usage":"start <program>"}}},{"name":"status","config":{"fs":{"path":"dist/esm/commands/status.js","source":"src/commands/status.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"stop","config":{"fs":{"path":"dist/esm/commands/stop.js","source":"src/commands/stop.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["options.process","$container"],"options":{"process":{"doc":"process to stop. Stops all the processes otherwise (including pm)."}},"usage":"stop [process]"}}},{"name":"update","config":{"fs":{"path":"dist/esm/commands/update.js","source":"src/commands/update.ts","inject":["param.0","param.1","param.2"]},"cli":{"inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","param.2"]}}},{"name":"version","config":{"fs":{"path":"dist/esm/commands/version.js","source":"src/commands/version.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["param.0","param.1"]}}}]} as Metadata.Container;
|
57
|
+
export const meta={"name":"commands","commands":[{"name":"$init","config":{"fs":{"disabled":true,"path":"dist/esm/commands/$init.js","source":"src/commands/$init.ts","inject":["$container","param.0"]},"":{"inject":["$container","param.0"]},"cli":{"inject":["$container","context"],"usage":"$init [...args]","options":{"configFile":{"needsValue":true,"aliases":["c"]},"keepAttached":{"needsValue":true}}}}},{"name":"bridge","config":{"fs":{"inject":["param.0","param.1"],"path":"dist/esm/commands/bridge.js","source":"src/commands/bridge.ts"},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":[]}}},{"name":"config","config":{"fs":{"path":"dist/esm/commands/config.js","source":"src/commands/config.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["param.0","options"]}}},{"name":"connect","config":{"fs":{"path":"dist/esm/commands/connect.js","source":"src/commands/connect.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"usage":"connect <name>","inject":["options.name","context"],"options":{"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"discover","config":{"fs":{"path":"dist/esm/commands/discover.js","source":"src/commands/discover.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"usage":"discover <name> <folder>","options":{"folder":{"normalize":true}},"inject":["options.name","options.folder","$container"]}}},{"name":"install","config":{"fs":{"path":"dist/esm/commands/install.js","source":"src/commands/install.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"link","config":{"fs":{"path":"dist/esm/commands/link.js","source":"src/commands/link.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"inject":["param.0","param.1","$container"]}}},{"name":"log","config":{"fs":{"path":"dist/esm/commands/log.js","source":"src/commands/log.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"ls","config":{"fs":{"path":"dist/esm/commands/ls.js","source":"src/commands/ls.ts","inject":[]},"":{"inject":[]},"cli":{"inject":[]}}},{"name":"map","config":{"fs":{"path":"dist/esm/commands/map.js","source":"src/commands/map.ts","inject":["param.0","param.1","param.2","param.3"]},"":{"inject":["param.0","param.1","param.2","param.3"]},"cli":{"inject":["options.name","options.path","cwd","options"],"options":{"commandable":{"aliases":["c"],"needsValue":false},"stateless":{"aliases":["s"],"needsValue":false}},"usage":"map <name> <path>"}}},{"name":"name","config":{"fs":{"path":"dist/esm/commands/name.js","source":"src/commands/name.ts","inject":["param.0"]},"":{"inject":["param.0"]}}},{"name":"plugin.add","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/plugin/add.js","source":"src/commands/plugin/add.ts"},"":{"inject":["param.0"]},"cli":{"usage":"add <plugin>","inject":["options.plugin"],"options":{"plugin":{"normalize":true}}}}},{"name":"plugin.remove","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/plugin/remove.js","source":"src/commands/plugin/remove.ts"},"":{"inject":["param.0"]},"cli":{"usage":"remove <plugin>","inject":["options.plugin"],"options":{"plugin":{"normalize":true}}}}},{"name":"proxy","config":{"fs":{"path":"dist/esm/commands/proxy.js","source":"src/commands/proxy.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"ready","config":{"fs":{"path":"dist/esm/commands/ready.js","source":"src/commands/ready.ts","inject":["$container","ignore"]},"jsonrpc":{"inject":["$container","dummy","connectionAsContainer"]},"":{"inject":["$container","connectionAsContainer"]}}},{"name":"reload-metadata","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/reload-metadata.js","source":"src/commands/reload-metadata.ts"},"jsonrpc":{"inject":["connectionAsContainer"]},"":{"inject":["param.0"]}}},{"name":"restart","config":{"fs":{"path":"dist/esm/commands/restart.js","source":"src/commands/restart.ts","inject":["$container","param.0","param.1"]},"":{"inject":["$container","param.0","param.1"]},"cli":{"options":{"wait":{"aliases":["w"]},"inspect":{},"new":{},"name":{}},"inject":["$container","param.0","context"]}}},{"name":"start","config":{"fs":{"path":"dist/esm/commands/start.js","source":"src/commands/start.ts","inject":["$container","param.0","param.1","param.2"]},"":{"inject":["$container","param.0","param.1","param.2"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["$container","options.program","options","context"],"usage":"start <program>"}}},{"name":"status","config":{"fs":{"path":"dist/esm/commands/status.js","source":"src/commands/status.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"stop","config":{"fs":{"path":"dist/esm/commands/stop.js","source":"src/commands/stop.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["options.process","$container"],"options":{"process":{"doc":"process to stop. Stops all the processes otherwise (including pm)."}},"usage":"stop [process]"}}},{"name":"update","config":{"fs":{"path":"dist/esm/commands/update.js","source":"src/commands/update.ts","inject":["param.0","param.1","param.2"]},"cli":{"inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","param.2"]}}},{"name":"version","config":{"fs":{"path":"dist/esm/commands/version.js","source":"src/commands/version.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["param.0","param.1"]}}}]} as Metadata.Container;
|
58
58
|
|
59
59
|
export function connect(processor?:ICommandProcessor) {
|
60
60
|
const container = new Container<void>("commands", void 0);
|
package/src/fork.ts
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
import sms from 'source-map-support'
|
3
3
|
sms.install();
|
4
4
|
import * as path from 'path'
|
5
|
-
import * as ac from '@akala/commands';
|
6
5
|
import { lstat } from 'fs/promises';
|
7
6
|
import pmDef from './container.js';
|
8
7
|
import { IpcAdapter } from "./ipc-adapter.js";
|
9
8
|
import { logger, Logger, module as coreModule, MiddlewareCompositeAsync } from '@akala/core';
|
10
9
|
import { program, buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware } from '@akala/cli';
|
11
10
|
import { Stats } from 'fs';
|
12
|
-
import { registerCommands, SelfDefinedCommand, parseMetadata, StructuredParameters } from '@akala/commands';
|
11
|
+
import { Processors, Triggers, ServeMetadata, Cli, registerCommands, SelfDefinedCommand, parseMetadata, StructuredParameters, Container, CommandProcessor, serveMetadata, connectByPreference, Metadata, ServeMetadataWithSignal } from '@akala/commands';
|
13
12
|
import { fileURLToPath } from 'url';
|
14
13
|
import commands from './container.js';
|
15
14
|
|
@@ -17,20 +16,20 @@ var isPm = false;
|
|
17
16
|
|
18
17
|
program.option('help')
|
19
18
|
let folderOrFile: Stats;
|
20
|
-
let cliContainer:
|
21
|
-
let processor:
|
19
|
+
let cliContainer: Container<unknown>;
|
20
|
+
let processor: CommandProcessor;
|
22
21
|
let log: Logger;
|
23
22
|
const logMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null).option<string, 'verbose'>('verbose', { aliases: ['v',] });
|
24
23
|
logMiddleware.preAction(async c =>
|
25
24
|
{
|
26
25
|
if (c.options.verbose)
|
27
|
-
processor = new
|
26
|
+
processor = new Processors.LogProcessor((_c, cmd, params) =>
|
28
27
|
{
|
29
28
|
log.verbose({ cmd, params });
|
30
29
|
return undefined;
|
31
30
|
});
|
32
31
|
|
33
|
-
await
|
32
|
+
await Processors.FileSystem.discoverCommands(c.options.program, cliContainer, { processor: processor, isDirectory: folderOrFile.isDirectory() });
|
34
33
|
});
|
35
34
|
let initMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null);
|
36
35
|
const controller = new AbortController();
|
@@ -70,12 +69,12 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
70
69
|
|
71
70
|
log = logger(c.options.name);
|
72
71
|
|
73
|
-
cliContainer = new
|
72
|
+
cliContainer = new Container('cli', {});
|
74
73
|
|
75
74
|
if (folderOrFile.isFile())
|
76
|
-
processor = new
|
75
|
+
processor = new Processors.FileSystem(path.dirname(c.options.program));
|
77
76
|
else
|
78
|
-
processor = new
|
77
|
+
processor = new Processors.FileSystem(c.options.program);
|
79
78
|
}).
|
80
79
|
useMiddleware(null, MiddlewareCompositeAsync.new(logMiddleware,
|
81
80
|
{
|
@@ -91,7 +90,7 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
91
90
|
initMiddleware = initMiddleware.command(init.config.cli.usage, init.config?.doc?.description)
|
92
91
|
c.args.unshift('$init');
|
93
92
|
}
|
94
|
-
|
93
|
+
Triggers.addCliOptions(init, initMiddleware);
|
95
94
|
}
|
96
95
|
|
97
96
|
process.on('unhandledRejection', (x) =>
|
@@ -108,8 +107,8 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
108
107
|
|
109
108
|
initMiddleware.option<string, 'pmSocket'>('pmSocket', { aliases: ['pm-socket', 'pm-sock'], needsValue: true }).action(async c =>
|
110
109
|
{
|
111
|
-
let pm:
|
112
|
-
let pmConnectInfo:
|
110
|
+
let pm: Container<unknown> & pmDef.container;
|
111
|
+
let pmConnectInfo: ServeMetadata;
|
113
112
|
|
114
113
|
if (!isPm)
|
115
114
|
{
|
@@ -117,7 +116,7 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
117
116
|
const pmMeta = commands.meta;
|
118
117
|
if (process.connected)
|
119
118
|
{
|
120
|
-
pm = new
|
119
|
+
pm = new Container('pm', null, new Processors.JsonRpc(Processors.JsonRpc.getConnection(new IpcAdapter(process), cliContainer))) as Container<unknown> & pmDef.container;
|
121
120
|
registerCommands(pmMeta.commands, null, pm);
|
122
121
|
}
|
123
122
|
else
|
@@ -125,9 +124,10 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
125
124
|
if (c.options.pmSocket)
|
126
125
|
pmConnectInfo = parseMetadata(c.options.pmSocket, c.options.tls);
|
127
126
|
else
|
128
|
-
pmConnectInfo =
|
129
|
-
const x = await
|
130
|
-
|
127
|
+
pmConnectInfo = serveMetadata({ args: ['local'], options: { socketName: 'pm' } })
|
128
|
+
const x = await connectByPreference(pmConnectInfo, { metadata: pmMeta, container: cliContainer });
|
129
|
+
controller.signal.addEventListener('abort', () => x.processor)
|
130
|
+
pm = x.container as Container<unknown> & pmDef.container;
|
131
131
|
pm.processor.useMiddleware(20, x.processor);
|
132
132
|
const connect = pm.resolve('connect');
|
133
133
|
pm.unregister('connect');
|
@@ -142,11 +142,11 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
142
142
|
]));
|
143
143
|
}
|
144
144
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
145
|
-
pm.unregister(
|
146
|
-
pm.register(
|
145
|
+
pm.unregister(Cli.Metadata.name);
|
146
|
+
pm.register(Metadata.extractCommandMetadata(Cli.Metadata));
|
147
147
|
}
|
148
148
|
else
|
149
|
-
pm = cliContainer as pmDef.container &
|
149
|
+
pm = cliContainer as pmDef.container & Container<unknown>;
|
150
150
|
|
151
151
|
coreModule('@akala/pm').register('container', pm);
|
152
152
|
|
@@ -154,11 +154,11 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
154
154
|
{
|
155
155
|
if (!pmConnectInfo)
|
156
156
|
pmConnectInfo = await pm.dispatch('connect', 'pm');
|
157
|
-
var pm2 = await
|
157
|
+
var pm2 = await connectByPreference(pmConnectInfo, { container: cliContainer, metadata: await cliContainer.dispatch('$metadata') });
|
158
158
|
pm2.container.processor.useMiddleware(20, pm2.processor);
|
159
|
-
pm2.container.unregister(
|
160
|
-
pm2.container.register(
|
161
|
-
pm2.container.register(
|
159
|
+
pm2.container.unregister(Cli.Metadata.name);
|
160
|
+
pm2.container.register(Metadata.extractCommandMetadata(Cli.Metadata));
|
161
|
+
pm2.container.register(Metadata.extractCommandMetadata(pm.resolve('bridge')));
|
162
162
|
if (await pm2.container.dispatch('bridge', connectionId))
|
163
163
|
throw undefined;
|
164
164
|
}, '$bridge'));
|
@@ -171,7 +171,7 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
|
|
171
171
|
|
172
172
|
try
|
173
173
|
{
|
174
|
-
const serveArgs:
|
174
|
+
const serveArgs: ServeMetadataWithSignal = await pm.dispatch('connect', c.options.name);
|
175
175
|
// console.log(serveArgs)
|
176
176
|
serveArgs.signal = controller.signal;
|
177
177
|
await cliContainer.dispatch('$serve', serveArgs);
|