@akala/pm 3.6.0 → 3.7.1
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 -2
- package/commands.json +175 -136
- package/dist/cli.js +6 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/restart.d.ts +18 -0
- package/dist/commands/restart.js +8 -0
- package/dist/commands/restart.js.map +1 -0
- package/dist/container.d.ts +2 -0
- package/dist/fork.js +17 -22
- package/dist/fork.js.map +1 -1
- package/package.json +5 -5
- package/src/cli.ts +7 -7
- package/src/commands/restart.json +27 -0
- package/src/commands/restart.ts +9 -0
- package/src/container.ts +2 -0
- package/src/fork.ts +98 -102
- package/tsconfig.tsbuildinfo +1 -1
package/dist/fork.js
CHANGED
@@ -37,7 +37,7 @@ const core_1 = require("@akala/core");
|
|
37
37
|
const cli_1 = __importStar(require("@akala/cli"));
|
38
38
|
const commands_1 = require("@akala/commands");
|
39
39
|
var isPm = false;
|
40
|
-
cli_1.default.useMiddleware({
|
40
|
+
cli_1.default.option('help').useMiddleware(null, {
|
41
41
|
handle: async (c) => {
|
42
42
|
isPm = c.options.program == 'pm';
|
43
43
|
if (isPm)
|
@@ -59,32 +59,25 @@ logMiddleware.preAction(async (c) => {
|
|
59
59
|
});
|
60
60
|
const initMiddleware = new cli_1.NamespaceMiddleware(null);
|
61
61
|
cli_1.default.option('program', { needsValue: true }).option('name', { needsValue: true }).option('tls', { needsValue: false }).
|
62
|
-
|
62
|
+
preAction(async (c) => //If pure js file
|
63
63
|
{
|
64
64
|
folderOrFile = await (0, promises_1.lstat)(c.options.program);
|
65
|
-
if (
|
66
|
-
|
67
|
-
|
65
|
+
if (folderOrFile.isFile() && path.extname(c.options.program) === '.js')
|
66
|
+
return require(c.options.program);
|
67
|
+
log = (0, core_1.logger)(c.options.name);
|
68
|
+
cliContainer = new ac.Container('cli', {});
|
69
|
+
if (folderOrFile.isFile())
|
70
|
+
processor = new ac.Processors.FileSystem(path.dirname(c.options.program));
|
71
|
+
else
|
72
|
+
processor = new ac.Processors.FileSystem(c.options.program);
|
68
73
|
}).
|
69
|
-
useMiddleware({
|
70
|
-
handle: async (c) => //if commandable
|
71
|
-
{
|
72
|
-
log = (0, core_1.logger)(c.options.name);
|
73
|
-
cliContainer = new ac.Container('cli', {});
|
74
|
-
if (folderOrFile.isFile())
|
75
|
-
processor = new ac.Processors.FileSystem(path.dirname(c.options.program));
|
76
|
-
else
|
77
|
-
processor = new ac.Processors.FileSystem(c.options.program);
|
78
|
-
}
|
79
|
-
}).
|
80
|
-
useMiddleware(logMiddleware).
|
81
|
-
useMiddleware({
|
74
|
+
useMiddleware(null, core_1.MiddlewareComposite.new(logMiddleware, {
|
82
75
|
handle: async (c) => {
|
83
76
|
cliContainer.name = c.options.name;
|
84
77
|
const init = cliContainer.resolve('$init');
|
85
78
|
if (init && init.config && init.config.cli && init.config.cli.options)
|
86
79
|
ac.Triggers.addCliOptions(init, initMiddleware);
|
87
|
-
initMiddleware.option('pmSocket', { aliases: ['pm-socket', 'pm-sock'] }).action(async (c) => {
|
80
|
+
initMiddleware.option('pmSocket', { aliases: ['pm-socket', 'pm-sock'], needsValue: true }).action(async (c) => {
|
88
81
|
let pm;
|
89
82
|
let pmConnectInfo;
|
90
83
|
if (!isPm) {
|
@@ -150,11 +143,13 @@ cli_1.default.option('program', { needsValue: true }).option('name', { needsValu
|
|
150
143
|
process.on('SIGINT', () => process.exit());
|
151
144
|
});
|
152
145
|
}
|
153
|
-
})
|
154
|
-
.useMiddleware(initMiddleware);
|
146
|
+
}, initMiddleware));
|
155
147
|
if (require.main == module)
|
156
148
|
cli_1.default.process((0, cli_1.buildCliContextFromProcess)()).catch(e => {
|
157
|
-
|
149
|
+
if (e instanceof cli_1.ErrorMessage)
|
150
|
+
console.error(e.message);
|
151
|
+
else
|
152
|
+
console.error(e);
|
158
153
|
process.exit(1);
|
159
154
|
});
|
160
155
|
//# sourceMappingURL=fork.js.map
|
package/dist/fork.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fork.js","sourceRoot":"","sources":["../src/fork.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAoC;AACpC,4BAAG,CAAC,OAAO,EAAE,CAAC;AACd,2CAA4B;AAC5B,oDAAsC;AACtC,0CAAoC;AACpC,+CAA2C;AAC3C,
|
1
|
+
{"version":3,"file":"fork.js","sourceRoot":"","sources":["../src/fork.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAoC;AACpC,4BAAG,CAAC,OAAO,EAAE,CAAC;AACd,2CAA4B;AAC5B,oDAAsC;AACtC,0CAAoC;AACpC,+CAA2C;AAC3C,sCAAwF;AACxF,kDAAoG;AAEpG,8CAA4G;AAE5G,IAAI,IAAI,GAAG,KAAK,CAAC;AAEjB,aAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;QAEd,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;QACjC,IAAI,IAAI;YACJ,CAAC,CAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACxE,CAAC;CACJ,CAAC,CAAC;AACH,IAAI,YAAmB,CAAC;AACxB,IAAI,YAAmC,CAAC;AACxC,IAAI,SAA8B,CAAC;AACnC,IAAI,GAAW,CAAC;AAChB,MAAM,aAAa,GAAG,IAAI,yBAAmB,CAAkD,IAAI,CAAC,CAAC,MAAM,CAAoB,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC/J,aAAa,CAAC,SAAS,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IAE9B,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO;QACjB,SAAS,GAAG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,GAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAEpD,IAAI,CAAC,YAAY,kBAAY;YACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;;YAEzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"pm": "dist/cli.js",
|
5
5
|
"pm-fork": "dist/fork.js"
|
6
6
|
},
|
7
|
-
"version": "3.
|
7
|
+
"version": "3.7.1",
|
8
8
|
"scripts": {
|
9
9
|
"test": "echo 1",
|
10
10
|
"generate": "ac generate dist/commands commands.json",
|
@@ -19,10 +19,10 @@
|
|
19
19
|
},
|
20
20
|
"homepage": "https://akala.js.org/pm",
|
21
21
|
"dependencies": {
|
22
|
-
"@akala/cli": "^2.
|
23
|
-
"@akala/commands": "^3.
|
24
|
-
"@akala/config": "^1.2.
|
25
|
-
"@akala/core": "^9.
|
22
|
+
"@akala/cli": "^2.3.1",
|
23
|
+
"@akala/commands": "^3.7.1",
|
24
|
+
"@akala/config": "^1.2.2",
|
25
|
+
"@akala/core": "^9.2.0",
|
26
26
|
"@akala/json-rpc-ws": "^9.6.0",
|
27
27
|
"reflect-metadata": "^0.1.13",
|
28
28
|
"source-map-support": "^0.5.21"
|
package/src/cli.ts
CHANGED
@@ -32,14 +32,14 @@ const tableChars = {
|
|
32
32
|
}
|
33
33
|
const truncate = '…';
|
34
34
|
|
35
|
-
type CliOptions = { output: string, verbose: boolean, pmSock: string | number, tls: boolean };
|
35
|
+
type CliOptions = { output: string, verbose: boolean, pmSock: string | number, tls: boolean, help: boolean };
|
36
36
|
|
37
|
-
const cli = program.options<CliOptions>({ output: { aliases: ['o'], needsValue: true }, verbose: { aliases: ['v'] }, tls: {}, pmSock: { aliases: ['pm-sock'], needsValue: true } });
|
37
|
+
const cli = program.options<CliOptions>({ output: { aliases: ['o'], needsValue: true, doc: 'output as `table` if array otherwise falls back to standard node output' }, verbose: { aliases: ['v'] }, tls: { doc: "enables tls connection to the `pmSock`" }, pmSock: { aliases: ['pm-sock'], needsValue: true, doc: "path to the unix socket or destination in the form host:port" }, help: { doc: "displays this help message" } });
|
38
38
|
cli.command<{ program?: string }>('start [program]')
|
39
|
-
.option('inspect')
|
40
|
-
.option('wait', { aliases: ['w'] })
|
39
|
+
.option('inspect', { doc: "starts the process with --inspect-brk parameter to help debugging" })
|
40
|
+
.option('wait', { aliases: ['w'], doc: "waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon" })
|
41
41
|
.option('new', { needsValue: false })
|
42
|
-
.option('name', { needsValue: true })
|
42
|
+
.option('name', { needsValue: true, doc: "name the process as per the given value" })
|
43
43
|
.action(c =>
|
44
44
|
{
|
45
45
|
if (typeof c.options.program == 'undefined')
|
@@ -119,7 +119,7 @@ cli.command(null).preAction(async c =>
|
|
119
119
|
console.error('pm is not started');
|
120
120
|
});
|
121
121
|
}
|
122
|
-
else
|
122
|
+
else if (!c.options.help)
|
123
123
|
reject(e);
|
124
124
|
})
|
125
125
|
});
|
@@ -139,7 +139,7 @@ cli.command(null).preAction(async c =>
|
|
139
139
|
await container.attach(Triggers.cli, handle);
|
140
140
|
}
|
141
141
|
}).
|
142
|
-
useMiddleware(handle).
|
142
|
+
useMiddleware(null, handle).
|
143
143
|
useError(async (err: InteractError, args) =>
|
144
144
|
{
|
145
145
|
if (err.code === 'INTERACT')
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://raw.githubusercontent.com/npenin/akala/master/packages/commands/command-schema.json",
|
3
|
+
"": {
|
4
|
+
"inject": [
|
5
|
+
"$container",
|
6
|
+
"param.0",
|
7
|
+
"param.1"
|
8
|
+
]
|
9
|
+
},
|
10
|
+
"cli": {
|
11
|
+
"options": {
|
12
|
+
"wait": {
|
13
|
+
"aliases": [
|
14
|
+
"w"
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"inspect": {},
|
18
|
+
"new": {},
|
19
|
+
"name": {}
|
20
|
+
},
|
21
|
+
"inject": [
|
22
|
+
"$container",
|
23
|
+
"param.0",
|
24
|
+
"context"
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { StdioOptions } from "child_process";
|
2
|
+
import pmContainer from '../container';
|
3
|
+
import { CliContext } from "@akala/cli";
|
4
|
+
|
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
|
+
{
|
7
|
+
await pm.dispatch('stop', name);
|
8
|
+
await pm.dispatch('start', name, context);
|
9
|
+
}
|
package/src/container.ts
CHANGED
@@ -19,6 +19,7 @@ namespace commands
|
|
19
19
|
dispatch (cmd:'proxy', ...args: [Argument0<typeof import('./commands/proxy').default>, Argument1<typeof import('./commands/proxy').default>]): ReturnType<typeof import('./commands/proxy').default>
|
20
20
|
dispatch (cmd:'ready', ...args: []): ReturnType<typeof import('./commands/ready').default>
|
21
21
|
dispatch (cmd:'reload-metadata', ...args: [Argument0<typeof import('./commands/reload-metadata').default>]): ReturnType<typeof import('./commands/reload-metadata').default>
|
22
|
+
dispatch (cmd:'restart', ...args: [Argument1<typeof import('./commands/restart').default>, Argument2<typeof import('./commands/restart').default>]): ReturnType<typeof import('./commands/restart').default>
|
22
23
|
dispatch (cmd:'start', ...args: [Argument1<typeof import('./commands/start').default>, Argument2<typeof import('./commands/start').default>]): ReturnType<typeof import('./commands/start').default>
|
23
24
|
dispatch (cmd:'status', ...args: [Argument0<typeof import('./commands/status').default>]): ReturnType<typeof import('./commands/status').default>
|
24
25
|
dispatch (cmd:'stop', ...args: [Argument0<typeof import('./commands/stop').default>]): ReturnType<typeof import('./commands/stop').default>
|
@@ -41,6 +42,7 @@ namespace commands
|
|
41
42
|
'proxy'(...args: [Argument0<typeof import('./commands/proxy').default>, Argument1<typeof import('./commands/proxy').default>]): ReturnType<typeof import('./commands/proxy').default>
|
42
43
|
'ready'(...args: []): ReturnType<typeof import('./commands/ready').default>
|
43
44
|
'reload-metadata'(...args: [Argument0<typeof import('./commands/reload-metadata').default>]): ReturnType<typeof import('./commands/reload-metadata').default>
|
45
|
+
'restart'(...args: [Argument1<typeof import('./commands/restart').default>, Argument2<typeof import('./commands/restart').default>]): ReturnType<typeof import('./commands/restart').default>
|
44
46
|
'start'(...args: [Argument1<typeof import('./commands/start').default>, Argument2<typeof import('./commands/start').default>]): ReturnType<typeof import('./commands/start').default>
|
45
47
|
'status'(...args: [Argument0<typeof import('./commands/status').default>]): ReturnType<typeof import('./commands/status').default>
|
46
48
|
'stop'(...args: [Argument0<typeof import('./commands/stop').default>]): ReturnType<typeof import('./commands/stop').default>
|
package/src/fork.ts
CHANGED
@@ -5,14 +5,14 @@ import * as path from 'path'
|
|
5
5
|
import * as ac from '@akala/commands';
|
6
6
|
import { lstat } from 'fs/promises';
|
7
7
|
import { IpcAdapter } from "./ipc-adapter";
|
8
|
-
import { logger, Logger, module as coreModule } from '@akala/core';
|
9
|
-
import program, { buildCliContextFromProcess, NamespaceMiddleware } from '@akala/cli';
|
8
|
+
import { logger, Logger, MiddlewareComposite, module as coreModule } from '@akala/core';
|
9
|
+
import program, { buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware } from '@akala/cli';
|
10
10
|
import { Stats } from 'fs';
|
11
11
|
import { registerCommands, SelfDefinedCommand, parseMetadata, StructuredParameters } from '@akala/commands';
|
12
12
|
|
13
13
|
var isPm = false;
|
14
14
|
|
15
|
-
program.useMiddleware({
|
15
|
+
program.option('help').useMiddleware(null, {
|
16
16
|
handle: async c =>
|
17
17
|
{
|
18
18
|
isPm = c.options.program == 'pm';
|
@@ -38,125 +38,121 @@ logMiddleware.preAction(async c =>
|
|
38
38
|
});
|
39
39
|
const initMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null);
|
40
40
|
program.option<string, 'program'>('program', { needsValue: true }).option<string, 'name'>('name', { needsValue: true }).option<boolean, 'tls'>('tls', { needsValue: false }).
|
41
|
-
|
41
|
+
preAction(async c => //If pure js file
|
42
42
|
{
|
43
43
|
folderOrFile = await lstat(c.options.program);
|
44
|
-
if (
|
45
|
-
|
44
|
+
if (folderOrFile.isFile() && path.extname(c.options.program) === '.js')
|
45
|
+
return require(c.options.program);
|
46
46
|
|
47
|
-
|
48
|
-
}).
|
49
|
-
useMiddleware({
|
50
|
-
handle: async c => //if commandable
|
51
|
-
{
|
52
|
-
log = logger(c.options.name);
|
47
|
+
log = logger(c.options.name);
|
53
48
|
|
54
|
-
|
49
|
+
cliContainer = new ac.Container('cli', {});
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
51
|
+
if (folderOrFile.isFile())
|
52
|
+
processor = new ac.Processors.FileSystem(path.dirname(c.options.program));
|
53
|
+
else
|
54
|
+
processor = new ac.Processors.FileSystem(c.options.program);
|
61
55
|
}).
|
62
|
-
useMiddleware(logMiddleware
|
63
|
-
useMiddleware({
|
64
|
-
handle: async c =>
|
56
|
+
useMiddleware(null, MiddlewareComposite.new(logMiddleware,
|
65
57
|
{
|
66
|
-
|
67
|
-
const init = cliContainer.resolve('$init');
|
68
|
-
if (init && init.config && init.config.cli && init.config.cli.options)
|
69
|
-
ac.Triggers.addCliOptions(init, initMiddleware);
|
70
|
-
|
71
|
-
initMiddleware.option<string, 'pmSocket'>('pmSocket', { aliases: ['pm-socket', 'pm-sock'] }).action(async c =>
|
58
|
+
handle: async c =>
|
72
59
|
{
|
60
|
+
cliContainer.name = c.options.name;
|
61
|
+
const init = cliContainer.resolve('$init');
|
62
|
+
if (init && init.config && init.config.cli && init.config.cli.options)
|
63
|
+
ac.Triggers.addCliOptions(init, initMiddleware);
|
73
64
|
|
74
|
-
|
75
|
-
let pmConnectInfo: ac.ServeMetadata;
|
76
|
-
|
77
|
-
if (!isPm)
|
65
|
+
initMiddleware.option<string, 'pmSocket'>('pmSocket', { aliases: ['pm-socket', 'pm-sock'], needsValue: true }).action(async c =>
|
78
66
|
{
|
79
|
-
|
80
|
-
|
81
|
-
|
67
|
+
let pm: ac.Container<unknown>;
|
68
|
+
let pmConnectInfo: ac.ServeMetadata;
|
69
|
+
|
70
|
+
if (!isPm)
|
82
71
|
{
|
83
|
-
|
84
|
-
|
72
|
+
//eslint-disable-next-line @typescript-eslint/no-var-requires
|
73
|
+
const pmMeta = require('../commands.json');
|
74
|
+
if (process.connected)
|
75
|
+
{
|
76
|
+
pm = new ac.Container('pm', null, new ac.Processors.JsonRpc(ac.Processors.JsonRpc.getConnection(new IpcAdapter(process), cliContainer), true));
|
77
|
+
registerCommands(pmMeta.commands, null, pm);
|
78
|
+
}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
if (c.options.pmSocket)
|
82
|
+
pmConnectInfo = parseMetadata(c.options.pmSocket, c.options.tls);
|
83
|
+
else
|
84
|
+
pmConnectInfo = ac.serveMetadata('pm', { args: ['local'], options: {} })
|
85
|
+
const x = await ac.connectByPreference(pmConnectInfo, { metadata: pmMeta, container: cliContainer });
|
86
|
+
pm = x.container;
|
87
|
+
pm.processor.useMiddleware(20, x.processor);
|
88
|
+
const connect = pm.resolve('connect');
|
89
|
+
pm.unregister('connect');
|
90
|
+
pm.register(new SelfDefinedCommand((name: string, param: StructuredParameters<unknown[]>) =>
|
91
|
+
{
|
92
|
+
if (name == 'pm')
|
93
|
+
return pmConnectInfo;
|
94
|
+
return x.processor.handle(pm, connect, param).then(e => { throw e }, r => r);
|
95
|
+
}, 'connect', [
|
96
|
+
"param.0",
|
97
|
+
"$param"
|
98
|
+
]));
|
99
|
+
}
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
101
|
+
pm.unregister(ac.Cli.Metadata.name);
|
102
|
+
pm.register(ac.Metadata.extractCommandMetadata(ac.Cli.Metadata));
|
85
103
|
}
|
86
104
|
else
|
105
|
+
pm = cliContainer;
|
106
|
+
|
107
|
+
coreModule('@akala/pm').register('container', pm);
|
108
|
+
|
109
|
+
cliContainer.register(new SelfDefinedCommand(async (connectionId: string) =>
|
87
110
|
{
|
88
|
-
if (
|
89
|
-
pmConnectInfo =
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
111
|
+
if (!pmConnectInfo)
|
112
|
+
pmConnectInfo = await pm.dispatch('connect', 'pm');
|
113
|
+
var pm2 = await ac.connectByPreference(pmConnectInfo, { container: cliContainer });
|
114
|
+
pm2.container.processor.useMiddleware(20, pm2.processor);
|
115
|
+
pm2.container.unregister(ac.Cli.Metadata.name);
|
116
|
+
pm2.container.register(ac.Metadata.extractCommandMetadata(ac.Cli.Metadata));
|
117
|
+
pm2.container.register(ac.Metadata.extractCommandMetadata(pm.resolve('bridge')));
|
118
|
+
if (await pm2.container.dispatch('bridge', connectionId))
|
119
|
+
throw undefined;
|
120
|
+
}, '$bridge'));
|
121
|
+
|
122
|
+
|
123
|
+
if (init)
|
124
|
+
await cliContainer.dispatch(init, { options: c.options, param: c.args, _trigger: 'cli', pm: pm, context: c });
|
125
|
+
|
126
|
+
let stop: (...args: unknown[]) => Promise<void>;
|
127
|
+
try
|
128
|
+
{
|
129
|
+
const serveArgs: ac.ServeMetadata = await pm.dispatch('connect', c.options.name);
|
130
|
+
stop = await cliContainer.dispatch('$serve', serveArgs) as (...args: unknown[]) => Promise<void>;
|
131
|
+
}
|
132
|
+
catch (e)
|
133
|
+
{
|
134
|
+
if (!e || e.statusCode !== 404)
|
135
|
+
throw e;
|
136
|
+
console.warn(e.message);
|
106
137
|
}
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
108
|
-
pm.unregister(ac.Cli.Metadata.name);
|
109
|
-
pm.register(ac.Metadata.extractCommandMetadata(ac.Cli.Metadata));
|
110
|
-
}
|
111
|
-
else
|
112
|
-
pm = cliContainer;
|
113
138
|
|
114
|
-
|
139
|
+
if (pm !== cliContainer)
|
140
|
+
await pm.dispatch('ready')
|
115
141
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
pm2.container.register(ac.Metadata.extractCommandMetadata(ac.Cli.Metadata));
|
124
|
-
pm2.container.register(ac.Metadata.extractCommandMetadata(pm.resolve('bridge')));
|
125
|
-
if (await pm2.container.dispatch('bridge', connectionId))
|
126
|
-
throw undefined;
|
127
|
-
}, '$bridge'));
|
128
|
-
|
129
|
-
|
130
|
-
if (init)
|
131
|
-
await cliContainer.dispatch(init, { options: c.options, param: c.args, _trigger: 'cli', pm: pm, context: c });
|
132
|
-
|
133
|
-
let stop: (...args: unknown[]) => Promise<void>;
|
134
|
-
try
|
135
|
-
{
|
136
|
-
const serveArgs: ac.ServeMetadata = await pm.dispatch('connect', c.options.name);
|
137
|
-
stop = await cliContainer.dispatch('$serve', serveArgs) as (...args: unknown[]) => Promise<void>;
|
138
|
-
}
|
139
|
-
catch (e)
|
140
|
-
{
|
141
|
-
if (!e || e.statusCode !== 404)
|
142
|
-
throw e;
|
143
|
-
console.warn(e.message);
|
144
|
-
}
|
145
|
-
|
146
|
-
if (pm !== cliContainer)
|
147
|
-
await pm.dispatch('ready')
|
148
|
-
|
149
|
-
if (stop && typeof stop == 'function')
|
150
|
-
process.on('SIGINT', stop);
|
151
|
-
process.on('SIGINT', () => process.exit());
|
152
|
-
});
|
153
|
-
}
|
154
|
-
})
|
155
|
-
.useMiddleware(initMiddleware);
|
142
|
+
if (stop && typeof stop == 'function')
|
143
|
+
process.on('SIGINT', stop);
|
144
|
+
process.on('SIGINT', () => process.exit());
|
145
|
+
});
|
146
|
+
}
|
147
|
+
},
|
148
|
+
initMiddleware));
|
156
149
|
|
157
150
|
if (require.main == module)
|
158
151
|
program.process(buildCliContextFromProcess()).catch(e =>
|
159
152
|
{
|
160
|
-
|
153
|
+
if (e instanceof ErrorMessage)
|
154
|
+
console.error(e.message);
|
155
|
+
else
|
156
|
+
console.error(e);
|
161
157
|
process.exit(1);
|
162
158
|
});
|