@deot/dev-test 1.1.0 → 2.0.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/dist/index.cjs.js +122 -108
- package/dist/index.es.js +103 -91
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,124 +1,138 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const devShared = require('@deot/dev-shared');
|
|
6
|
+
const childProcess = require('child_process');
|
|
5
7
|
|
|
6
8
|
function _interopNamespaceDefault(e) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
const childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
|
|
24
26
|
|
|
25
27
|
const { LOCAL_COMMAND_MAP } = devShared.Shell;
|
|
26
28
|
const KEY_MAP = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
DOWN: "\x1B[B",
|
|
30
|
+
UP: "\x1B[A",
|
|
31
|
+
ENTER: "\r",
|
|
32
|
+
// return;
|
|
33
|
+
SPACE: ""
|
|
31
34
|
};
|
|
32
35
|
class Command {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
_handleEnd(fn) {
|
|
60
|
-
return (e) => {
|
|
61
|
-
this.isClose = true;
|
|
62
|
-
const { code, error } = e;
|
|
63
|
-
this.code = code;
|
|
64
|
-
this.error = error;
|
|
65
|
-
fn({
|
|
66
|
-
...e,
|
|
67
|
-
stdout: this.stdout,
|
|
68
|
-
stderr: this.stderr
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
start(command, args) {
|
|
73
|
-
const SPACE = ' ';
|
|
74
|
-
const [command$, ...args$] = (command + SPACE + args.join(SPACE))
|
|
75
|
-
.replace(/\s+/g, SPACE)
|
|
76
|
-
.split(SPACE)
|
|
77
|
-
.filter(i => !!i)
|
|
78
|
-
.map(i => LOCAL_COMMAND_MAP[i] || i);
|
|
79
|
-
const emitter = childProcess__namespace.spawn(command$, args$, {
|
|
80
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
81
|
-
});
|
|
82
|
-
emitter.on('close', (code) => {
|
|
83
|
-
if (code !== 0) {
|
|
84
|
-
this.reject({ code });
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.resolve({ code });
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
emitter.on('error', (error) => {
|
|
91
|
-
!process.exitCode && (process.exitCode = 1);
|
|
92
|
-
this.reject({ code: process.exitCode, error });
|
|
93
|
-
});
|
|
94
|
-
emitter.stdout.on('data', e => {
|
|
95
|
-
this.stdout += e.toString();
|
|
96
|
-
this.schedule.complete();
|
|
97
|
-
});
|
|
98
|
-
emitter.stderr.on('data', e => this.stderr += e.toString());
|
|
99
|
-
return emitter;
|
|
100
|
-
}
|
|
101
|
-
async stop() {
|
|
102
|
-
await this.schedule.target;
|
|
103
|
-
if (!this.isClose) {
|
|
104
|
-
this.emitter.stdin.end();
|
|
105
|
-
this.isClose = true;
|
|
36
|
+
target;
|
|
37
|
+
code;
|
|
38
|
+
error;
|
|
39
|
+
resolve;
|
|
40
|
+
reject;
|
|
41
|
+
stdout;
|
|
42
|
+
stderr;
|
|
43
|
+
emitter;
|
|
44
|
+
isClose;
|
|
45
|
+
schedule;
|
|
46
|
+
constructor(command, args) {
|
|
47
|
+
this.target = new Promise((resolve, reject) => {
|
|
48
|
+
this.resolve = this._handleEnd(resolve);
|
|
49
|
+
this.reject = this._handleEnd(reject);
|
|
50
|
+
});
|
|
51
|
+
this.code = null;
|
|
52
|
+
this.error = null;
|
|
53
|
+
this.stdout = "";
|
|
54
|
+
this.stderr = "";
|
|
55
|
+
this.emitter = this.start(command, args);
|
|
56
|
+
this.isClose = false;
|
|
57
|
+
this.schedule = {
|
|
58
|
+
target: Promise.resolve(),
|
|
59
|
+
complete: (
|
|
60
|
+
/* istanbul ignore next */
|
|
61
|
+
() => {
|
|
106
62
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
63
|
+
)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
_handleEnd(fn) {
|
|
67
|
+
return (e) => {
|
|
68
|
+
this.isClose = true;
|
|
69
|
+
const { code, error } = e;
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.error = error;
|
|
72
|
+
fn({
|
|
73
|
+
...e,
|
|
74
|
+
stdout: this.stdout,
|
|
75
|
+
stderr: this.stderr
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
start(command, args) {
|
|
80
|
+
const SPACE = " ";
|
|
81
|
+
const [command$, ...args$] = (command + SPACE + args.join(SPACE)).replace(/\s+/g, SPACE).split(SPACE).filter((i) => !!i).map((i) => LOCAL_COMMAND_MAP[i] || i);
|
|
82
|
+
const emitter = childProcess__namespace.spawn(command$, args$, {
|
|
83
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
84
|
+
});
|
|
85
|
+
emitter.on("close", (code) => {
|
|
86
|
+
if (code !== 0) {
|
|
87
|
+
this.reject({ code });
|
|
88
|
+
} else {
|
|
89
|
+
this.resolve({ code });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
emitter.on(
|
|
93
|
+
"error",
|
|
94
|
+
/* istanbul ignore next */
|
|
95
|
+
(error) => {
|
|
96
|
+
!process.exitCode && (process.exitCode = 1);
|
|
97
|
+
this.reject({ code: process.exitCode, error });
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
emitter.stdout.on("data", (e) => {
|
|
101
|
+
this.stdout += e.toString();
|
|
102
|
+
this.schedule.complete();
|
|
103
|
+
});
|
|
104
|
+
emitter.stderr.on(
|
|
105
|
+
"data",
|
|
106
|
+
/* istanbul ignore next */
|
|
107
|
+
(e) => this.stderr += e.toString()
|
|
108
|
+
);
|
|
109
|
+
return emitter;
|
|
110
|
+
}
|
|
111
|
+
async stop() {
|
|
112
|
+
await this.schedule.target;
|
|
113
|
+
if (!this.isClose) {
|
|
114
|
+
this.emitter.stdin.end();
|
|
115
|
+
this.isClose = true;
|
|
121
116
|
}
|
|
117
|
+
const response = await this.target;
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
async press(key, timeout = 200) {
|
|
121
|
+
if (!key || this.isClose)
|
|
122
|
+
return;
|
|
123
|
+
await this.schedule.target;
|
|
124
|
+
this.schedule.target = new Promise((resolve) => {
|
|
125
|
+
this.schedule.complete = resolve;
|
|
126
|
+
});
|
|
127
|
+
await new Promise((resolve) => {
|
|
128
|
+
this.emitter.stdin.write(
|
|
129
|
+
KEY_MAP[key.toUpperCase()] || key,
|
|
130
|
+
"utf8",
|
|
131
|
+
resolve
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
await new Promise((_) => setTimeout(_, timeout));
|
|
135
|
+
}
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
exports.Command = Command;
|
package/dist/index.es.js
CHANGED
|
@@ -3,101 +3,113 @@ import * as childProcess from 'child_process';
|
|
|
3
3
|
|
|
4
4
|
const { LOCAL_COMMAND_MAP } = Shell;
|
|
5
5
|
const KEY_MAP = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
DOWN: "\x1B[B",
|
|
7
|
+
UP: "\x1B[A",
|
|
8
|
+
ENTER: "\r",
|
|
9
|
+
// return;
|
|
10
|
+
SPACE: ""
|
|
10
11
|
};
|
|
11
12
|
class Command {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_handleEnd(fn) {
|
|
39
|
-
return (e) => {
|
|
40
|
-
this.isClose = true;
|
|
41
|
-
const { code, error } = e;
|
|
42
|
-
this.code = code;
|
|
43
|
-
this.error = error;
|
|
44
|
-
fn({
|
|
45
|
-
...e,
|
|
46
|
-
stdout: this.stdout,
|
|
47
|
-
stderr: this.stderr
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
start(command, args) {
|
|
52
|
-
const SPACE = ' ';
|
|
53
|
-
const [command$, ...args$] = (command + SPACE + args.join(SPACE))
|
|
54
|
-
.replace(/\s+/g, SPACE)
|
|
55
|
-
.split(SPACE)
|
|
56
|
-
.filter(i => !!i)
|
|
57
|
-
.map(i => LOCAL_COMMAND_MAP[i] || i);
|
|
58
|
-
const emitter = childProcess.spawn(command$, args$, {
|
|
59
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
60
|
-
});
|
|
61
|
-
emitter.on('close', (code) => {
|
|
62
|
-
if (code !== 0) {
|
|
63
|
-
this.reject({ code });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.resolve({ code });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
emitter.on('error', (error) => {
|
|
70
|
-
!process.exitCode && (process.exitCode = 1);
|
|
71
|
-
this.reject({ code: process.exitCode, error });
|
|
72
|
-
});
|
|
73
|
-
emitter.stdout.on('data', e => {
|
|
74
|
-
this.stdout += e.toString();
|
|
75
|
-
this.schedule.complete();
|
|
76
|
-
});
|
|
77
|
-
emitter.stderr.on('data', e => this.stderr += e.toString());
|
|
78
|
-
return emitter;
|
|
79
|
-
}
|
|
80
|
-
async stop() {
|
|
81
|
-
await this.schedule.target;
|
|
82
|
-
if (!this.isClose) {
|
|
83
|
-
this.emitter.stdin.end();
|
|
84
|
-
this.isClose = true;
|
|
13
|
+
target;
|
|
14
|
+
code;
|
|
15
|
+
error;
|
|
16
|
+
resolve;
|
|
17
|
+
reject;
|
|
18
|
+
stdout;
|
|
19
|
+
stderr;
|
|
20
|
+
emitter;
|
|
21
|
+
isClose;
|
|
22
|
+
schedule;
|
|
23
|
+
constructor(command, args) {
|
|
24
|
+
this.target = new Promise((resolve, reject) => {
|
|
25
|
+
this.resolve = this._handleEnd(resolve);
|
|
26
|
+
this.reject = this._handleEnd(reject);
|
|
27
|
+
});
|
|
28
|
+
this.code = null;
|
|
29
|
+
this.error = null;
|
|
30
|
+
this.stdout = "";
|
|
31
|
+
this.stderr = "";
|
|
32
|
+
this.emitter = this.start(command, args);
|
|
33
|
+
this.isClose = false;
|
|
34
|
+
this.schedule = {
|
|
35
|
+
target: Promise.resolve(),
|
|
36
|
+
complete: (
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
() => {
|
|
85
39
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
40
|
+
)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
_handleEnd(fn) {
|
|
44
|
+
return (e) => {
|
|
45
|
+
this.isClose = true;
|
|
46
|
+
const { code, error } = e;
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.error = error;
|
|
49
|
+
fn({
|
|
50
|
+
...e,
|
|
51
|
+
stdout: this.stdout,
|
|
52
|
+
stderr: this.stderr
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
start(command, args) {
|
|
57
|
+
const SPACE = " ";
|
|
58
|
+
const [command$, ...args$] = (command + SPACE + args.join(SPACE)).replace(/\s+/g, SPACE).split(SPACE).filter((i) => !!i).map((i) => LOCAL_COMMAND_MAP[i] || i);
|
|
59
|
+
const emitter = childProcess.spawn(command$, args$, {
|
|
60
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
61
|
+
});
|
|
62
|
+
emitter.on("close", (code) => {
|
|
63
|
+
if (code !== 0) {
|
|
64
|
+
this.reject({ code });
|
|
65
|
+
} else {
|
|
66
|
+
this.resolve({ code });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
emitter.on(
|
|
70
|
+
"error",
|
|
71
|
+
/* istanbul ignore next */
|
|
72
|
+
(error) => {
|
|
73
|
+
!process.exitCode && (process.exitCode = 1);
|
|
74
|
+
this.reject({ code: process.exitCode, error });
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
emitter.stdout.on("data", (e) => {
|
|
78
|
+
this.stdout += e.toString();
|
|
79
|
+
this.schedule.complete();
|
|
80
|
+
});
|
|
81
|
+
emitter.stderr.on(
|
|
82
|
+
"data",
|
|
83
|
+
/* istanbul ignore next */
|
|
84
|
+
(e) => this.stderr += e.toString()
|
|
85
|
+
);
|
|
86
|
+
return emitter;
|
|
87
|
+
}
|
|
88
|
+
async stop() {
|
|
89
|
+
await this.schedule.target;
|
|
90
|
+
if (!this.isClose) {
|
|
91
|
+
this.emitter.stdin.end();
|
|
92
|
+
this.isClose = true;
|
|
100
93
|
}
|
|
94
|
+
const response = await this.target;
|
|
95
|
+
return response;
|
|
96
|
+
}
|
|
97
|
+
async press(key, timeout = 200) {
|
|
98
|
+
if (!key || this.isClose)
|
|
99
|
+
return;
|
|
100
|
+
await this.schedule.target;
|
|
101
|
+
this.schedule.target = new Promise((resolve) => {
|
|
102
|
+
this.schedule.complete = resolve;
|
|
103
|
+
});
|
|
104
|
+
await new Promise((resolve) => {
|
|
105
|
+
this.emitter.stdin.write(
|
|
106
|
+
KEY_MAP[key.toUpperCase()] || key,
|
|
107
|
+
"utf8",
|
|
108
|
+
resolve
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
await new Promise((_) => setTimeout(_, timeout));
|
|
112
|
+
}
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
export { Command };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.es.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@deot/dev-shared": "^
|
|
15
|
+
"@deot/dev-shared": "^2.0.0"
|
|
16
16
|
}
|
|
17
17
|
}
|