@akala/pm 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +14 -1
- package/commands.json +22 -22
- package/dist/cli.js +0 -0
- package/dist/commands/plugin/add.d.ts +1 -1
- package/dist/commands/plugin/remove.d.ts +1 -1
- package/dist/{cli-helper.d.ts → esm/cli-helper.d.ts} +0 -0
- package/dist/esm/cli-helper.js +17 -0
- package/dist/esm/cli-helper.js.map +1 -0
- package/dist/{cli.d.ts → esm/cli.d.ts} +0 -0
- package/dist/esm/cli.js +423 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/{commands → esm/commands}/$init.d.ts +0 -0
- package/dist/esm/commands/$init.js +113 -0
- package/dist/esm/commands/$init.js.map +1 -0
- package/dist/{commands → esm/commands}/bridge.d.ts +0 -0
- package/dist/esm/commands/bridge.js +11 -0
- package/dist/esm/commands/bridge.js.map +1 -0
- package/dist/{commands → esm/commands}/config.d.ts +0 -0
- package/dist/esm/commands/config.js +20 -0
- package/dist/esm/commands/config.js.map +1 -0
- package/dist/{commands → esm/commands}/connect.d.ts +0 -0
- package/dist/esm/commands/connect.js +26 -0
- package/dist/esm/commands/connect.js.map +1 -0
- package/dist/{commands → esm/commands}/discover.d.ts +0 -0
- package/dist/esm/commands/discover.js +72 -0
- package/dist/esm/commands/discover.js.map +1 -0
- package/dist/{commands → esm/commands}/install.d.ts +0 -0
- package/dist/esm/commands/install.js +13 -0
- package/dist/esm/commands/install.js.map +1 -0
- package/dist/{commands → esm/commands}/link.d.ts +0 -0
- package/dist/esm/commands/link.js +11 -0
- package/dist/esm/commands/link.js.map +1 -0
- package/dist/{commands → esm/commands}/log.d.ts +0 -0
- package/dist/esm/commands/log.js +15 -0
- package/dist/esm/commands/log.js.map +1 -0
- package/dist/{commands → esm/commands}/ls.d.ts +0 -0
- package/dist/esm/commands/ls.js +4 -0
- package/dist/esm/commands/ls.js.map +1 -0
- package/dist/{commands → esm/commands}/map.d.ts +0 -0
- package/dist/esm/commands/map.js +9 -0
- package/dist/esm/commands/map.js.map +1 -0
- package/dist/{commands → esm/commands}/name.d.ts +0 -0
- package/dist/esm/commands/name.js +604 -0
- package/dist/esm/commands/name.js.map +1 -0
- package/dist/esm/commands/plugin/add.d.ts +2 -0
- package/dist/esm/commands/plugin/add.js +5 -0
- package/dist/esm/commands/plugin/add.js.map +1 -0
- package/dist/esm/commands/plugin/remove.d.ts +2 -0
- package/dist/esm/commands/plugin/remove.js +7 -0
- package/dist/esm/commands/plugin/remove.js.map +1 -0
- package/dist/{commands → esm/commands}/proxy.d.ts +0 -0
- package/dist/esm/commands/proxy.js +19 -0
- package/dist/esm/commands/proxy.js.map +1 -0
- package/dist/{commands → esm/commands}/ready.d.ts +0 -0
- package/dist/esm/commands/ready.js +22 -0
- package/dist/esm/commands/ready.js.map +1 -0
- package/dist/{commands → esm/commands}/reload-metadata.d.ts +0 -0
- package/dist/esm/commands/reload-metadata.js +7 -0
- package/dist/esm/commands/reload-metadata.js.map +1 -0
- package/dist/{commands → esm/commands}/restart.d.ts +0 -0
- package/dist/esm/commands/restart.js +5 -0
- package/dist/esm/commands/restart.js.map +1 -0
- package/dist/{commands → esm/commands}/start.d.ts +0 -0
- package/dist/esm/commands/start.js +139 -0
- package/dist/esm/commands/start.js.map +1 -0
- package/dist/{commands → esm/commands}/status.d.ts +0 -0
- package/dist/esm/commands/status.js +7 -0
- package/dist/esm/commands/status.js.map +1 -0
- package/dist/{commands → esm/commands}/stop.d.ts +0 -0
- package/dist/esm/commands/stop.js +33 -0
- package/dist/esm/commands/stop.js.map +1 -0
- package/dist/{commands → esm/commands}/update.d.ts +0 -0
- package/dist/esm/commands/update.js +15 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/{commands → esm/commands}/version.d.ts +0 -0
- package/dist/esm/commands/version.js +14 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/{container.d.ts → esm/container.d.ts} +0 -0
- package/dist/esm/container.js +2 -0
- package/dist/esm/container.js.map +1 -0
- package/dist/{fork.d.ts → esm/fork.d.ts} +0 -0
- package/dist/esm/fork.js +146 -0
- package/dist/esm/fork.js.map +1 -0
- package/dist/{index.d.ts → esm/index.d.ts} +0 -0
- package/dist/esm/index.js +43 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{ipc-adapter.d.ts → esm/ipc-adapter.d.ts} +0 -0
- package/dist/esm/ipc-adapter.js +60 -0
- package/dist/esm/ipc-adapter.js.map +1 -0
- package/dist/{new-line-prefixer.d.ts → esm/new-line-prefixer.d.ts} +0 -0
- package/dist/esm/new-line-prefixer.js +39 -0
- package/dist/esm/new-line-prefixer.js.map +1 -0
- package/dist/{npm-helper.d.ts → esm/npm-helper.d.ts} +0 -0
- package/dist/esm/npm-helper.js +20 -0
- package/dist/esm/npm-helper.js.map +1 -0
- package/dist/{sidecar.d.ts → esm/sidecar.d.ts} +0 -0
- package/dist/esm/sidecar.js +45 -0
- package/dist/esm/sidecar.js.map +1 -0
- package/dist/{standalone.d.ts → esm/standalone.d.ts} +0 -0
- package/dist/esm/standalone.js +80 -0
- package/dist/esm/standalone.js.map +1 -0
- package/dist/{state.d.ts → esm/state.d.ts} +0 -0
- package/dist/esm/state.js +2 -0
- package/dist/esm/state.js.map +1 -0
- package/dist/{test → esm/test}/pwet.d.ts +0 -0
- package/dist/esm/test/pwet.js +7 -0
- package/dist/esm/test/pwet.js.map +1 -0
- package/dist/{yarn-helper.d.ts → esm/yarn-helper.d.ts} +0 -0
- package/dist/esm/yarn-helper.js +26 -0
- package/dist/esm/yarn-helper.js.map +1 -0
- package/dist/fork.js +0 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +23 -12
- package/tsconfig.cjs.json +22 -0
- package/tsconfig.esm.json +22 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/yarn-error.log +11177 -0
package/changelog.md
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
# (2023-02-
|
1
|
+
# (2023-02-02)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add-script and yamlloader 7dd85c7
|
7
|
+
* fix generate and tsconfig files b44bd4c
|
8
|
+
* normalized modules to work in esm and cjs 88ffcca
|
9
|
+
* path to bins 11cfa04
|
10
|
+
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
* have both CJS and ESM at once cecd11a
|
2
15
|
|
3
16
|
|
4
17
|
|
package/commands.json
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
"name": "$init",
|
6
6
|
"config": {
|
7
7
|
"fs": {
|
8
|
-
"path": "dist/commands/$init.js",
|
8
|
+
"path": "dist/esm/commands/$init.js",
|
9
9
|
"source": "src/commands/$init.ts",
|
10
10
|
"inject": [
|
11
11
|
"$container",
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"inject": [
|
46
46
|
"param.0"
|
47
47
|
],
|
48
|
-
"path": "dist/commands/plugin/add.js",
|
48
|
+
"path": "dist/esm/commands/plugin/add.js",
|
49
49
|
"source": "src/commands/plugin/add.ts"
|
50
50
|
},
|
51
51
|
"": {
|
@@ -74,7 +74,7 @@
|
|
74
74
|
"param.0",
|
75
75
|
"param.1"
|
76
76
|
],
|
77
|
-
"path": "dist/commands/bridge.js",
|
77
|
+
"path": "dist/esm/commands/bridge.js",
|
78
78
|
"source": "src/commands/bridge.ts"
|
79
79
|
},
|
80
80
|
"jsonrpc": {
|
@@ -92,7 +92,7 @@
|
|
92
92
|
"name": "config",
|
93
93
|
"config": {
|
94
94
|
"fs": {
|
95
|
-
"path": "dist/commands/config.js",
|
95
|
+
"path": "dist/esm/commands/config.js",
|
96
96
|
"source": "src/commands/config.ts",
|
97
97
|
"inject": [
|
98
98
|
"param.0",
|
@@ -117,7 +117,7 @@
|
|
117
117
|
"name": "connect",
|
118
118
|
"config": {
|
119
119
|
"fs": {
|
120
|
-
"path": "dist/commands/connect.js",
|
120
|
+
"path": "dist/esm/commands/connect.js",
|
121
121
|
"source": "src/commands/connect.ts",
|
122
122
|
"inject": [
|
123
123
|
"param.0",
|
@@ -160,7 +160,7 @@
|
|
160
160
|
"name": "discover",
|
161
161
|
"config": {
|
162
162
|
"fs": {
|
163
|
-
"path": "dist/commands/discover.js",
|
163
|
+
"path": "dist/esm/commands/discover.js",
|
164
164
|
"source": "src/commands/discover.ts",
|
165
165
|
"inject": [
|
166
166
|
"param.0",
|
@@ -194,7 +194,7 @@
|
|
194
194
|
"name": "install",
|
195
195
|
"config": {
|
196
196
|
"fs": {
|
197
|
-
"path": "dist/commands/install.js",
|
197
|
+
"path": "dist/esm/commands/install.js",
|
198
198
|
"source": "src/commands/install.ts",
|
199
199
|
"inject": [
|
200
200
|
"param.0",
|
@@ -219,7 +219,7 @@
|
|
219
219
|
"name": "link",
|
220
220
|
"config": {
|
221
221
|
"fs": {
|
222
|
-
"path": "dist/commands/link.js",
|
222
|
+
"path": "dist/esm/commands/link.js",
|
223
223
|
"source": "src/commands/link.ts",
|
224
224
|
"inject": [
|
225
225
|
"param.0",
|
@@ -247,7 +247,7 @@
|
|
247
247
|
"name": "log",
|
248
248
|
"config": {
|
249
249
|
"fs": {
|
250
|
-
"path": "dist/commands/log.js",
|
250
|
+
"path": "dist/esm/commands/log.js",
|
251
251
|
"source": "src/commands/log.ts",
|
252
252
|
"inject": [
|
253
253
|
"param.0"
|
@@ -269,7 +269,7 @@
|
|
269
269
|
"name": "ls",
|
270
270
|
"config": {
|
271
271
|
"fs": {
|
272
|
-
"path": "dist/commands/ls.js",
|
272
|
+
"path": "dist/esm/commands/ls.js",
|
273
273
|
"source": "src/commands/ls.ts",
|
274
274
|
"inject": []
|
275
275
|
},
|
@@ -285,7 +285,7 @@
|
|
285
285
|
"name": "map",
|
286
286
|
"config": {
|
287
287
|
"fs": {
|
288
|
-
"path": "dist/commands/map.js",
|
288
|
+
"path": "dist/esm/commands/map.js",
|
289
289
|
"source": "src/commands/map.ts",
|
290
290
|
"inject": [
|
291
291
|
"param.0",
|
@@ -331,7 +331,7 @@
|
|
331
331
|
"name": "name",
|
332
332
|
"config": {
|
333
333
|
"fs": {
|
334
|
-
"path": "dist/commands/name.js",
|
334
|
+
"path": "dist/esm/commands/name.js",
|
335
335
|
"source": "src/commands/name.ts",
|
336
336
|
"inject": [
|
337
337
|
"param.0"
|
@@ -348,7 +348,7 @@
|
|
348
348
|
"name": "proxy",
|
349
349
|
"config": {
|
350
350
|
"fs": {
|
351
|
-
"path": "dist/commands/proxy.js",
|
351
|
+
"path": "dist/esm/commands/proxy.js",
|
352
352
|
"source": "src/commands/proxy.ts",
|
353
353
|
"inject": [
|
354
354
|
"param.0",
|
@@ -373,7 +373,7 @@
|
|
373
373
|
"name": "ready",
|
374
374
|
"config": {
|
375
375
|
"fs": {
|
376
|
-
"path": "dist/commands/ready.js",
|
376
|
+
"path": "dist/esm/commands/ready.js",
|
377
377
|
"source": "src/commands/ready.ts",
|
378
378
|
"inject": [
|
379
379
|
"$container",
|
@@ -402,7 +402,7 @@
|
|
402
402
|
"inject": [
|
403
403
|
"param.0"
|
404
404
|
],
|
405
|
-
"path": "dist/commands/reload-metadata.js",
|
405
|
+
"path": "dist/esm/commands/reload-metadata.js",
|
406
406
|
"source": "src/commands/reload-metadata.ts"
|
407
407
|
},
|
408
408
|
"jsonrpc": {
|
@@ -424,7 +424,7 @@
|
|
424
424
|
"inject": [
|
425
425
|
"param.0"
|
426
426
|
],
|
427
|
-
"path": "dist/commands/plugin/remove.js",
|
427
|
+
"path": "dist/esm/commands/plugin/remove.js",
|
428
428
|
"source": "src/commands/plugin/remove.ts"
|
429
429
|
},
|
430
430
|
"": {
|
@@ -449,7 +449,7 @@
|
|
449
449
|
"name": "restart",
|
450
450
|
"config": {
|
451
451
|
"fs": {
|
452
|
-
"path": "dist/commands/restart.js",
|
452
|
+
"path": "dist/esm/commands/restart.js",
|
453
453
|
"source": "src/commands/restart.ts",
|
454
454
|
"inject": [
|
455
455
|
"$container",
|
@@ -487,7 +487,7 @@
|
|
487
487
|
"name": "start",
|
488
488
|
"config": {
|
489
489
|
"fs": {
|
490
|
-
"path": "dist/commands/start.js",
|
490
|
+
"path": "dist/esm/commands/start.js",
|
491
491
|
"source": "src/commands/start.ts",
|
492
492
|
"inject": [
|
493
493
|
"$container",
|
@@ -539,7 +539,7 @@
|
|
539
539
|
"name": "status",
|
540
540
|
"config": {
|
541
541
|
"fs": {
|
542
|
-
"path": "dist/commands/status.js",
|
542
|
+
"path": "dist/esm/commands/status.js",
|
543
543
|
"source": "src/commands/status.ts",
|
544
544
|
"inject": [
|
545
545
|
"param.0"
|
@@ -561,7 +561,7 @@
|
|
561
561
|
"name": "stop",
|
562
562
|
"config": {
|
563
563
|
"fs": {
|
564
|
-
"path": "dist/commands/stop.js",
|
564
|
+
"path": "dist/esm/commands/stop.js",
|
565
565
|
"source": "src/commands/stop.ts",
|
566
566
|
"inject": [
|
567
567
|
"param.0",
|
@@ -592,7 +592,7 @@
|
|
592
592
|
"name": "update",
|
593
593
|
"config": {
|
594
594
|
"fs": {
|
595
|
-
"path": "dist/commands/update.js",
|
595
|
+
"path": "dist/esm/commands/update.js",
|
596
596
|
"source": "src/commands/update.ts",
|
597
597
|
"inject": [
|
598
598
|
"param.0",
|
@@ -615,7 +615,7 @@
|
|
615
615
|
"name": "version",
|
616
616
|
"config": {
|
617
617
|
"fs": {
|
618
|
-
"path": "dist/commands/version.js",
|
618
|
+
"path": "dist/esm/commands/version.js",
|
619
619
|
"source": "src/commands/version.ts",
|
620
620
|
"inject": [
|
621
621
|
"param.0",
|
package/dist/cli.js
CHANGED
File without changes
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import State from "../../state.js";
|
2
|
-
export default function (this: State, plugin: string):
|
2
|
+
export default function (this: State, plugin: string): any;
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import State from "../../state.js";
|
2
|
-
export default function (this: State, plugin: string):
|
2
|
+
export default function (this: State, plugin: string): any;
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as cp from 'child_process';
|
2
|
+
export function spawnAsync(program, options, ...args) {
|
3
|
+
options = Object.assign({ stdio: ['ignore', 'ignore', 'pipe'], shell: false, windowsHide: true }, options);
|
4
|
+
return new Promise((resolve, reject) => {
|
5
|
+
let err = '';
|
6
|
+
cp
|
7
|
+
.spawn(program, args, options)
|
8
|
+
.on('error', reject).on('exit', (code) => {
|
9
|
+
if (code == 0)
|
10
|
+
resolve();
|
11
|
+
reject(new Error('yarn exited with error code ' + code + '\n' + err));
|
12
|
+
}).stderr.on('data', (chunk) => {
|
13
|
+
err += chunk;
|
14
|
+
});
|
15
|
+
});
|
16
|
+
}
|
17
|
+
//# sourceMappingURL=cli-helper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cli-helper.js","sourceRoot":"","sources":["../../src/cli-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AAEnC,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,OAAwB,EAAE,GAAG,IAAc;IAEnF,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAE3G,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAEzC,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,EAAE;aACG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;aAC7B,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAErC,IAAI,IAAI,IAAI,CAAC;gBACT,OAAO,EAAE,CAAA;YACb,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAA;QACzE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAE3B,GAAG,IAAI,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;IACX,CAAC,CAAC,CAAA;AACN,CAAC"}
|
File without changes
|
package/dist/esm/cli.js
ADDED
@@ -0,0 +1,423 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import * as path from 'path';
|
3
|
+
import { Processors, NetSocketAdapter, Metadata, Container, proxy, Triggers, Cli } from '@akala/commands';
|
4
|
+
import { Socket } from 'net';
|
5
|
+
import { TLSSocket } from 'tls';
|
6
|
+
import { platform, homedir } from 'os';
|
7
|
+
import start from './commands/start.js';
|
8
|
+
import { Readable } from 'stream';
|
9
|
+
import { spawnAsync } from './cli-helper.js';
|
10
|
+
import program, { buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware, unparse } from '@akala/cli';
|
11
|
+
import { Binding } from '@akala/core';
|
12
|
+
const tableChars = {
|
13
|
+
'top': '─',
|
14
|
+
'top-mid': '┬',
|
15
|
+
'top-left': '┌',
|
16
|
+
'top-right': '┐',
|
17
|
+
'bottom': '─',
|
18
|
+
'bottom-mid': '┴',
|
19
|
+
'bottom-left': '└',
|
20
|
+
'bottom-right': '┘',
|
21
|
+
'left': '│',
|
22
|
+
'left-mid': '├',
|
23
|
+
'mid': '─',
|
24
|
+
'mid-mid': '┼',
|
25
|
+
'right': '│',
|
26
|
+
'right-mid': '┤',
|
27
|
+
'middle': '│'
|
28
|
+
};
|
29
|
+
const truncate = '…';
|
30
|
+
const cli = program.options({ 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" } });
|
31
|
+
const startpm = cli.command('start pm')
|
32
|
+
.option('inspect', { doc: "starts the process with --inspect-brk parameter to help debugging" })
|
33
|
+
.option('keepAttached', { doc: "keeps the process attached" })
|
34
|
+
.action(c => {
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36
|
+
c.options['name'] = 'pm';
|
37
|
+
c.options['program'] = require.resolve('../commands.json');
|
38
|
+
return start.call({}, null, 'pm', c);
|
39
|
+
});
|
40
|
+
let socket;
|
41
|
+
let processor;
|
42
|
+
let metaContainer;
|
43
|
+
let container;
|
44
|
+
const handle = new NamespaceMiddleware(null);
|
45
|
+
cli.preAction(async (c) => {
|
46
|
+
process.stdin.pause();
|
47
|
+
process.stdin.setEncoding('utf8');
|
48
|
+
if (!socket) {
|
49
|
+
const netsocket = socket = new Socket();
|
50
|
+
if (c.options.tls) {
|
51
|
+
socket = new TLSSocket(socket, {});
|
52
|
+
}
|
53
|
+
await new Promise((resolve, reject) => {
|
54
|
+
if (c.options.pmSock) {
|
55
|
+
if (typeof (c.options.pmSock) == 'string') {
|
56
|
+
const indexOfColon = c.options.pmSock.indexOf(':');
|
57
|
+
if (indexOfColon > -1)
|
58
|
+
netsocket.connect(Number(c.options.pmSock.substring(indexOfColon + 1)), c.options.pmSock.substring(0, indexOfColon));
|
59
|
+
else
|
60
|
+
netsocket.connect(c.options.pmSock);
|
61
|
+
}
|
62
|
+
else
|
63
|
+
netsocket.connect(c.options.pmSock);
|
64
|
+
}
|
65
|
+
else if (platform() == 'win32')
|
66
|
+
netsocket.connect('\\\\?\\pipe\\pm');
|
67
|
+
else {
|
68
|
+
try {
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
70
|
+
const config = require(path.join(homedir(), './.pm.config.json'));
|
71
|
+
netsocket.connect(config.mapping.pm.connect.socket[0]);
|
72
|
+
}
|
73
|
+
catch (e) {
|
74
|
+
if (e.code != 'MODULE_NOT_FOUND')
|
75
|
+
reject(e);
|
76
|
+
else {
|
77
|
+
e.code = 'ENOENT';
|
78
|
+
socket.destroy(e);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
if (c.options.tls) {
|
83
|
+
// socket.on('data', function (e) { console.log(e) });
|
84
|
+
socket.connect({});
|
85
|
+
netsocket.on('error', function (e) {
|
86
|
+
console.log(e);
|
87
|
+
});
|
88
|
+
socket.on('error', function (e) {
|
89
|
+
console.log(e);
|
90
|
+
});
|
91
|
+
}
|
92
|
+
socket.on('connect', async function () {
|
93
|
+
resolve();
|
94
|
+
socket.setEncoding('utf-8');
|
95
|
+
});
|
96
|
+
socket.on('error', async (e) => {
|
97
|
+
if (c.options.help)
|
98
|
+
resolve();
|
99
|
+
else {
|
100
|
+
if (e.code === 'ENOENT') {
|
101
|
+
// return tryLocalProcessing(c).catch(() =>
|
102
|
+
// {
|
103
|
+
resolve();
|
104
|
+
// reject(new Error('pm is not started'));
|
105
|
+
// });
|
106
|
+
}
|
107
|
+
else
|
108
|
+
reject(e);
|
109
|
+
}
|
110
|
+
});
|
111
|
+
});
|
112
|
+
}
|
113
|
+
if (socket.readyState == 'open') {
|
114
|
+
if (!processor)
|
115
|
+
processor = new Processors.JsonRpc(Processors.JsonRpc.getConnection(new NetSocketAdapter(socket)));
|
116
|
+
if (!metaContainer)
|
117
|
+
metaContainer = require('../commands.json');
|
118
|
+
if (!container) {
|
119
|
+
container = proxy(metaContainer, processor);
|
120
|
+
container.unregister(Cli.Metadata.name);
|
121
|
+
container.register(Metadata.extractCommandMetadata(Cli.Metadata));
|
122
|
+
await container.attach(Triggers.cli, cli);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}).
|
126
|
+
// cli.
|
127
|
+
// useMiddleware(null, handle).
|
128
|
+
useError(async (err, args) => {
|
129
|
+
if (err.code === 'INTERACT') {
|
130
|
+
console.log(err.message);
|
131
|
+
const value = await readLine();
|
132
|
+
if (typeof err.as == 'string') {
|
133
|
+
const indexOfDot = err.as.indexOf('.');
|
134
|
+
if (indexOfDot > 0) {
|
135
|
+
Binding.getSetter(args.options, err.as)(value);
|
136
|
+
}
|
137
|
+
args.options[err.as] = value;
|
138
|
+
}
|
139
|
+
else
|
140
|
+
args.args.push(value);
|
141
|
+
return await cli.process(args);
|
142
|
+
}
|
143
|
+
throw err;
|
144
|
+
});
|
145
|
+
// handle.action(async args =>
|
146
|
+
// {
|
147
|
+
// try
|
148
|
+
// {
|
149
|
+
// const cmdName = args.args[0].toString();
|
150
|
+
// if (cmdName == '$metadata')
|
151
|
+
// return formatResult(metaContainer, args.options.output);
|
152
|
+
// else
|
153
|
+
// {
|
154
|
+
// const cmd = metaContainer.commands.find(c => c.name === cmdName);
|
155
|
+
// await tryRun(processor, cmd, args, false);
|
156
|
+
// }
|
157
|
+
// await new Promise<void>((resolve) => socket.end(resolve));
|
158
|
+
// }
|
159
|
+
// catch (e)
|
160
|
+
// {
|
161
|
+
// if (e.code == 'INTERACT')
|
162
|
+
// {
|
163
|
+
// console.log(e.message);
|
164
|
+
// const value = await readLine();
|
165
|
+
// if (e.as)
|
166
|
+
// args.options[e] = value;
|
167
|
+
// else
|
168
|
+
// args.args.push(value);
|
169
|
+
// return handle.handle(args).then(e => { if (e) throw e }, res => res);
|
170
|
+
// }
|
171
|
+
// if (args.options.verbose)
|
172
|
+
// console.log(e);
|
173
|
+
// else
|
174
|
+
// console.log(e.message)
|
175
|
+
// await new Promise<void>((resolve) => socket.end(resolve));
|
176
|
+
// }
|
177
|
+
// });
|
178
|
+
cli.format((result, context) => formatResult(result, context.options.output));
|
179
|
+
program.useError((err, context) => {
|
180
|
+
if (context.options.verbose)
|
181
|
+
console.error(err);
|
182
|
+
else if (err instanceof ErrorMessage)
|
183
|
+
console.log(err.message);
|
184
|
+
else
|
185
|
+
console.error('Error: ' + err.message);
|
186
|
+
return Promise.reject(err);
|
187
|
+
});
|
188
|
+
program.process(buildCliContextFromProcess()).then(result => {
|
189
|
+
if (result instanceof Readable) {
|
190
|
+
result.pipe(process.stdout);
|
191
|
+
return;
|
192
|
+
}
|
193
|
+
if (socket)
|
194
|
+
socket.end();
|
195
|
+
}, err => {
|
196
|
+
if (err && !(err instanceof ErrorMessage))
|
197
|
+
console.error(err);
|
198
|
+
process.exit(err && err.statusCode || 50);
|
199
|
+
});
|
200
|
+
function formatResult(result, outputFormat) {
|
201
|
+
if (typeof result == 'undefined')
|
202
|
+
return;
|
203
|
+
if (result instanceof Readable) {
|
204
|
+
return result;
|
205
|
+
}
|
206
|
+
switch (outputFormat) {
|
207
|
+
case 'table':
|
208
|
+
{
|
209
|
+
const columnNames = [];
|
210
|
+
const columns = {};
|
211
|
+
if (Array.isArray(result)) {
|
212
|
+
for (const r of result) {
|
213
|
+
Object.keys(r).forEach(k => {
|
214
|
+
if (columnNames.indexOf(k) == -1)
|
215
|
+
columnNames.push(k);
|
216
|
+
});
|
217
|
+
}
|
218
|
+
columnNames.forEach(c => {
|
219
|
+
columns[c] = { maxWidthContent: 0, maxWidth: c.length + 2, values: [] };
|
220
|
+
for (const r of result) {
|
221
|
+
if (typeof (r[c]) == 'undefined' || typeof r[c] == 'string' && r[c].length == 0)
|
222
|
+
columns[c].values.push('');
|
223
|
+
else if (r[c] == null) {
|
224
|
+
columns[c].values.push('-');
|
225
|
+
columns[c].maxWidthContent = Math.max(columns[c].maxWidthContent, 1);
|
226
|
+
}
|
227
|
+
else {
|
228
|
+
columns[c].values.push(r[c].toString());
|
229
|
+
columns[c].maxWidthContent = Math.max(columns[c].maxWidthContent, r[c].toString().length);
|
230
|
+
}
|
231
|
+
columns[c].maxWidth = Math.max(columns[c].maxWidthContent, columns[c].maxWidth);
|
232
|
+
}
|
233
|
+
});
|
234
|
+
let columnNamesForDisplay = columnNames.slice(0);
|
235
|
+
let width = columnNamesForDisplay.reduce((length, c, i) => columns[columnNames[i]].maxWidth + length, 0) + columnNamesForDisplay.length + 1;
|
236
|
+
if (process.stdout.columns < width) {
|
237
|
+
for (const c of columnNames) {
|
238
|
+
if (columns[c].maxWidthContent == 0)
|
239
|
+
columnNamesForDisplay = columnNamesForDisplay.splice(columnNamesForDisplay.indexOf(c), 1);
|
240
|
+
}
|
241
|
+
width = columnNamesForDisplay.reduce((length, c, i) => columns[columnNames[i]].maxWidth + length, 0) + columnNamesForDisplay.length + 1;
|
242
|
+
}
|
243
|
+
if (process.stdout.columns < width) {
|
244
|
+
columnNamesForDisplay = columnNamesForDisplay.map(c => {
|
245
|
+
if (c.length > 8 + truncate.length) {
|
246
|
+
const newName = c.substring(0, 8) + truncate;
|
247
|
+
columns[c].maxWidth = Math.max(columns[c].maxWidthContent, newName.length);
|
248
|
+
return newName;
|
249
|
+
}
|
250
|
+
return c;
|
251
|
+
});
|
252
|
+
width = columnNamesForDisplay.reduce((length, c, i) => columns[columnNames[i]].maxWidth + length, 0) + columnNamesForDisplay.length + 1;
|
253
|
+
}
|
254
|
+
if (process.stdout.columns < width) {
|
255
|
+
columnNamesForDisplay.forEach(c => {
|
256
|
+
columns[c].maxWidth = Math.max(columns[c].maxWidthContent, c.length);
|
257
|
+
});
|
258
|
+
width = columnNamesForDisplay.reduce((length, c, i) => columns[columnNames[i]].maxWidth + length, 0) + columnNamesForDisplay.length + 1;
|
259
|
+
}
|
260
|
+
if (process.stdout.columns >= width) {
|
261
|
+
process.stdout.write(tableChars["top-left"]);
|
262
|
+
columnNamesForDisplay.forEach((c, i) => {
|
263
|
+
for (let j = 0; j < columns[columnNames[i]].maxWidth; j++)
|
264
|
+
process.stdout.write(tableChars["top"]);
|
265
|
+
if (i == columnNames.length - 1)
|
266
|
+
process.stdout.write(tableChars["top-right"]);
|
267
|
+
else
|
268
|
+
process.stdout.write(tableChars["top-mid"]);
|
269
|
+
});
|
270
|
+
process.stdout.write('\n');
|
271
|
+
process.stdout.write(tableChars["left"]);
|
272
|
+
columnNamesForDisplay.forEach((c, i) => {
|
273
|
+
let pad;
|
274
|
+
for (pad = 0; pad < (columns[columnNames[i]].maxWidth - c.length) / 2; pad++)
|
275
|
+
process.stdout.write(' ');
|
276
|
+
process.stdout.write(c);
|
277
|
+
for (pad += c.length; pad < columns[columnNames[i]].maxWidth; pad++)
|
278
|
+
process.stdout.write(' ');
|
279
|
+
if (i == columnNames.length - 1)
|
280
|
+
process.stdout.write(tableChars["right"]);
|
281
|
+
else
|
282
|
+
process.stdout.write(tableChars["middle"]);
|
283
|
+
});
|
284
|
+
process.stdout.write('\n');
|
285
|
+
process.stdout.write(tableChars["left-mid"]);
|
286
|
+
columnNamesForDisplay.forEach((c, i) => {
|
287
|
+
for (let j = 0; j < columns[columnNames[i]].maxWidth; j++)
|
288
|
+
process.stdout.write(tableChars["mid"]);
|
289
|
+
if (i == columnNames.length - 1)
|
290
|
+
process.stdout.write(tableChars["right-mid"]);
|
291
|
+
else
|
292
|
+
process.stdout.write(tableChars["mid-mid"]);
|
293
|
+
});
|
294
|
+
process.stdout.write('\n');
|
295
|
+
for (let r = 0; r < result.length; r++) {
|
296
|
+
process.stdout.write(tableChars["left"]);
|
297
|
+
columnNamesForDisplay.forEach((c, i) => {
|
298
|
+
const value = columns[columnNames[i]].values[r];
|
299
|
+
let pad;
|
300
|
+
for (pad = 0; pad < Math.floor((columns[columnNames[i]].maxWidth - value.length) / 2); pad++)
|
301
|
+
process.stdout.write(' ');
|
302
|
+
process.stdout.write(value);
|
303
|
+
for (pad += value.length; pad < columns[columnNames[i]].maxWidth; pad++)
|
304
|
+
process.stdout.write(' ');
|
305
|
+
if (i == columnNames.length - 1)
|
306
|
+
process.stdout.write(tableChars["right"]);
|
307
|
+
else
|
308
|
+
process.stdout.write(tableChars["middle"]);
|
309
|
+
});
|
310
|
+
process.stdout.write('\n');
|
311
|
+
}
|
312
|
+
process.stdout.write(tableChars["bottom-left"]);
|
313
|
+
columnNamesForDisplay.forEach((c, i) => {
|
314
|
+
for (let j = 0; j < columns[columnNames[i]].maxWidth; j++)
|
315
|
+
process.stdout.write(tableChars["bottom"]);
|
316
|
+
if (i == columnNames.length - 1)
|
317
|
+
process.stdout.write(tableChars["bottom-right"]);
|
318
|
+
else
|
319
|
+
process.stdout.write(tableChars["bottom-mid"]);
|
320
|
+
});
|
321
|
+
process.stdout.write('\n');
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
// eslint-disable-next-line no-fallthrough
|
327
|
+
default:
|
328
|
+
console.log(result);
|
329
|
+
break;
|
330
|
+
}
|
331
|
+
}
|
332
|
+
function prepareParam(cmd, args, standalone) {
|
333
|
+
if (!cmd)
|
334
|
+
return false;
|
335
|
+
if (!cmd.config || !cmd.config.cli || (standalone && !cmd.config.cli.standalone))
|
336
|
+
return false;
|
337
|
+
delete args.options.pmSock;
|
338
|
+
return {
|
339
|
+
options: args.options, param: args.args.slice(1), _trigger: 'cli', cwd: args.currentWorkingDirectory, context: args, get stdin() {
|
340
|
+
return new Promise((resolve) => {
|
341
|
+
const buffers = [];
|
342
|
+
process.stdin.on('data', data => buffers.push(data));
|
343
|
+
process.stdin.on('end', () => resolve(Buffer.concat(buffers).toString('utf8')));
|
344
|
+
});
|
345
|
+
}
|
346
|
+
};
|
347
|
+
}
|
348
|
+
async function tryRun(processor, cmd, args, localProcessing) {
|
349
|
+
const params = prepareParam(cmd, args, localProcessing);
|
350
|
+
if (!params)
|
351
|
+
throw new Error('Either command does not exist or it is not standalone');
|
352
|
+
try {
|
353
|
+
const result = await processor.handle(null, cmd, params).then(err => { throw err; }, res => res);
|
354
|
+
if (result instanceof Readable)
|
355
|
+
result.pipe(process.stdout);
|
356
|
+
else
|
357
|
+
formatResult(result, args.options.output);
|
358
|
+
}
|
359
|
+
catch (e) {
|
360
|
+
if (e.code == 'INTERACT') {
|
361
|
+
console.log(e.message);
|
362
|
+
let value = await readLine();
|
363
|
+
value = value.trim();
|
364
|
+
if (e.as)
|
365
|
+
args.options[e] = value;
|
366
|
+
else
|
367
|
+
args.args.push(value);
|
368
|
+
args.args.unshift(cmd.name);
|
369
|
+
return await tryRun(processor, cmd, args, localProcessing);
|
370
|
+
}
|
371
|
+
if (args.options.verbose)
|
372
|
+
console.log(e);
|
373
|
+
else
|
374
|
+
console.log(e.message);
|
375
|
+
}
|
376
|
+
}
|
377
|
+
async function tryLocalProcessing(args) {
|
378
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
379
|
+
const config = require(path.join(homedir(), './.pm.config.json'));
|
380
|
+
let cmdName = args.args.shift();
|
381
|
+
if (!cmdName)
|
382
|
+
throw undefined;
|
383
|
+
const indexOfDot = cmdName.indexOf('.');
|
384
|
+
if (indexOfDot > -1) {
|
385
|
+
const containerName = cmdName.substring(0, indexOfDot);
|
386
|
+
if (config.containers[containerName] && config.containers[containerName].commandable) {
|
387
|
+
cmdName = cmdName.substring(indexOfDot + 1);
|
388
|
+
const container = new Container('cli-temp', {});
|
389
|
+
const options = {};
|
390
|
+
await Processors.FileSystem.discoverCommands(config.containers[containerName].path, container, options);
|
391
|
+
const cmd = container.resolve(cmdName);
|
392
|
+
return tryRun(options.processor, cmd, args, true);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
else {
|
396
|
+
if (!config.containers[cmdName].commandable)
|
397
|
+
return spawnAsync(config.containers[cmdName].path, null, ...unparse(args));
|
398
|
+
}
|
399
|
+
}
|
400
|
+
let stdinBuffer = '';
|
401
|
+
function readLine() {
|
402
|
+
process.stdin.pause();
|
403
|
+
return new Promise((resolve) => {
|
404
|
+
process.stdin.on('data', function processChunk(chunk) {
|
405
|
+
const indexOfNewLine = stdinBuffer.length + chunk.indexOf('\n');
|
406
|
+
stdinBuffer += chunk;
|
407
|
+
if (indexOfNewLine > -1) {
|
408
|
+
process.stdin.pause();
|
409
|
+
process.stdin.removeListener('data', processChunk);
|
410
|
+
if (indexOfNewLine < stdinBuffer.length - 1) {
|
411
|
+
resolve(stdinBuffer.substr(0, indexOfNewLine));
|
412
|
+
stdinBuffer = stdinBuffer.substr(indexOfNewLine + 1);
|
413
|
+
}
|
414
|
+
else {
|
415
|
+
resolve(stdinBuffer);
|
416
|
+
stdinBuffer = '';
|
417
|
+
}
|
418
|
+
}
|
419
|
+
});
|
420
|
+
process.stdin.resume();
|
421
|
+
});
|
422
|
+
}
|
423
|
+
//# sourceMappingURL=cli.js.map
|