uni-run 1.1.1 → 1.1.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/README.md +16 -9
- package/dist/app.js +7 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/scriptExecutors/checkRuntime.d.ts +1 -1
- package/dist/scriptExecutors/checkRuntime.js +21 -31
- package/dist/scriptExecutors/index.js +85 -39
- package/dist/scriptExecutors/types.t.d.ts +6 -4
- package/package.json +1 -1
- package/dist/helpers/get-config.d.ts +0 -1
- package/dist/helpers/get-config.js +0 -30
package/README.md
CHANGED
|
@@ -83,15 +83,16 @@ Now you can run your script with `run script.js` or `run script.ts` with your ow
|
|
|
83
83
|
## Setup Custom Executors
|
|
84
84
|
|
|
85
85
|
Create `.uni-run.cjs` file in your user home directory or current working directory.
|
|
86
|
+
NOTE: Your custom executors will have more priority than the default executors.
|
|
86
87
|
|
|
87
88
|
```js
|
|
88
89
|
module.exports = [
|
|
89
90
|
{
|
|
90
|
-
name: '
|
|
91
|
+
name: 'Name',
|
|
91
92
|
exts: ['ext'],
|
|
92
93
|
getRuntime(args, options, config) {
|
|
93
94
|
return {
|
|
94
|
-
|
|
95
|
+
start: ['YOUR_BIN', ...args],
|
|
95
96
|
}
|
|
96
97
|
},
|
|
97
98
|
},
|
|
@@ -104,16 +105,20 @@ Now you can run your script with `run script.ext`.
|
|
|
104
105
|
|
|
105
106
|
The `uni-run` package provides a simple API to manage and execute scripts.
|
|
106
107
|
|
|
107
|
-
#### `
|
|
108
|
+
#### `addExecutorBefore(options: ExecutorOptions)` or `addExecutorAfter(options: ExecutorOptions)`:
|
|
109
|
+
|
|
110
|
+
Both methods add an executor to the list of executors. The `addExecutorBefore` method adds the executor before the default executors, while the `addExecutorAfter` method adds the executor after the default executors. This means that the executor will be used before or after checking the default executors.
|
|
108
111
|
|
|
109
112
|
```typescript
|
|
110
113
|
import uniRun from 'uni-run'
|
|
111
114
|
|
|
112
|
-
uniRun.
|
|
115
|
+
uniRun.addExecutorBefore({
|
|
113
116
|
name: 'Name',
|
|
114
|
-
exts: ['
|
|
117
|
+
exts: ['ext'],
|
|
115
118
|
getRuntime(args, options, config) {
|
|
116
|
-
return
|
|
119
|
+
return {
|
|
120
|
+
start: ['YOUR_BIN', ...args],
|
|
121
|
+
}
|
|
117
122
|
},
|
|
118
123
|
})
|
|
119
124
|
```
|
|
@@ -134,11 +139,13 @@ uniRun.start(['arg1', 'arg2'])
|
|
|
134
139
|
import uniRun from 'uni-run'
|
|
135
140
|
|
|
136
141
|
// Add the Executor to uni-run
|
|
137
|
-
uniRun.
|
|
142
|
+
uniRun.addExecutorBefore({
|
|
138
143
|
name: 'Name',
|
|
139
|
-
exts: ['
|
|
144
|
+
exts: ['ext'],
|
|
140
145
|
getRuntime(args, options, config) {
|
|
141
|
-
return
|
|
146
|
+
return {
|
|
147
|
+
start: ['YOUR_BIN', ...args],
|
|
148
|
+
}
|
|
142
149
|
},
|
|
143
150
|
})
|
|
144
151
|
|
package/dist/app.js
CHANGED
|
@@ -42,6 +42,7 @@ const argHelper_1 = require("./argHelper");
|
|
|
42
42
|
const scriptExecutors_1 = __importDefault(require("./scriptExecutors"));
|
|
43
43
|
const checkRuntime_1 = __importDefault(require("./scriptExecutors/checkRuntime"));
|
|
44
44
|
const getUserExecutors_1 = __importDefault(require("./helpers/getUserExecutors"));
|
|
45
|
+
const colors_1 = __importDefault(require("./lib/colors"));
|
|
45
46
|
arg.app.on((_a, flags_1) => __awaiter(void 0, [_a, flags_1], void 0, function* ([script, listArs, trailingArgs], flags) {
|
|
46
47
|
var _b;
|
|
47
48
|
const userExecutors = (0, getUserExecutors_1.default)(flags.cwd);
|
|
@@ -52,13 +53,13 @@ arg.app.on((_a, flags_1) => __awaiter(void 0, [_a, flags_1], void 0, function* (
|
|
|
52
53
|
];
|
|
53
54
|
const scriptExecutor = totalExecutors.find((executor) => executor.exts.includes(script.split('.').pop()));
|
|
54
55
|
if (!scriptExecutor) {
|
|
55
|
-
console.
|
|
56
|
+
console.error('Unsupported script:', script);
|
|
56
57
|
return console.log('You may try "run exec YOUR_BIN script.ext -- --flags"');
|
|
57
58
|
}
|
|
58
59
|
const executionOptions = (0, argHelper_1.mapFlagsToOptions)(flags);
|
|
59
60
|
const runtime = scriptExecutor.getRuntime([script, ...listArs, ...trailingArgs], executionOptions, executionConfig);
|
|
60
61
|
(0, checkRuntime_1.default)(runtime);
|
|
61
|
-
execution_1.default.start(runtime.
|
|
62
|
+
execution_1.default.start(runtime.start, Object.assign(Object.assign({}, executionOptions), { watchExtensions: executionOptions.watchExtensions.length
|
|
62
63
|
? executionOptions.watchExtensions
|
|
63
64
|
: [...scriptExecutor.exts, ...((_b = runtime.watchExts) !== null && _b !== void 0 ? _b : [])] }));
|
|
64
65
|
}));
|
|
@@ -71,14 +72,8 @@ arg.list.on(() => {
|
|
|
71
72
|
...(Array.isArray(userExecutors) ? userExecutors : []),
|
|
72
73
|
...scriptExecutors_1.default,
|
|
73
74
|
];
|
|
74
|
-
console.log('Supported scripts:');
|
|
75
|
-
totalExecutors
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
return -1;
|
|
79
|
-
if (a.name > b.name)
|
|
80
|
-
return 1;
|
|
81
|
-
return 0;
|
|
82
|
-
})
|
|
83
|
-
.forEach(({ name }) => console.log(`- ${name}`));
|
|
75
|
+
console.log(colors_1.default.bold('Supported scripts:'));
|
|
76
|
+
totalExecutors.forEach(({ name, exts }) => {
|
|
77
|
+
console.log(`- ${colors_1.default.magenta(name)}`, `[${exts.map((e) => '.' + colors_1.default.green(e)).join(', ')}]`);
|
|
78
|
+
});
|
|
84
79
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import './app';
|
|
2
2
|
import { ScriptExecutorOptions } from './scriptExecutors/types.t';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
|
|
4
|
+
addExecutorBefore(executor: ScriptExecutorOptions): void;
|
|
5
|
+
addExecutorAfter(executor: ScriptExecutorOptions): void;
|
|
5
6
|
start(args?: string[]): void;
|
|
6
7
|
};
|
|
7
8
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,12 @@ require("./app");
|
|
|
7
7
|
const arg_1 = require("./arg");
|
|
8
8
|
const scriptExecutors_1 = __importDefault(require("./scriptExecutors"));
|
|
9
9
|
exports.default = {
|
|
10
|
-
|
|
10
|
+
addExecutorBefore(executor) {
|
|
11
11
|
scriptExecutors_1.default.unshift(executor);
|
|
12
12
|
},
|
|
13
|
+
addExecutorAfter(executor) {
|
|
14
|
+
scriptExecutors_1.default.push(executor);
|
|
15
|
+
},
|
|
13
16
|
start(args) {
|
|
14
17
|
arg_1.app.start(args);
|
|
15
18
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RuntimeOptions } from './types.t';
|
|
2
|
-
export default function (runtime: RuntimeOptions):
|
|
2
|
+
export default function (runtime: RuntimeOptions): void;
|
|
@@ -4,39 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = default_1;
|
|
7
|
+
const colors_1 = __importDefault(require("../lib/colors"));
|
|
7
8
|
const confirm_1 = __importDefault(require("@inquirer/confirm"));
|
|
8
9
|
const cross_spawn_1 = require("cross-spawn");
|
|
9
10
|
function default_1(runtime) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return canBeInstalled(runtime.install);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function isInstalled(commands) {
|
|
16
|
-
if (!(commands === null || commands === void 0 ? void 0 : commands.length))
|
|
17
|
-
return true;
|
|
18
|
-
const [command, ...args] = commands;
|
|
19
|
-
const result = (0, cross_spawn_1.sync)(command, args, {
|
|
20
|
-
stdio: 'ignore',
|
|
21
|
-
});
|
|
22
|
-
if (result.status === 1)
|
|
23
|
-
return false;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
function renderHowToInstall(name, hints) {
|
|
27
|
-
if (!(hints === null || hints === void 0 ? void 0 : hints.length))
|
|
11
|
+
var _a, _b, _c, _d;
|
|
12
|
+
if (!((_b = (_a = runtime.install) === null || _a === void 0 ? void 0 : _a.check) === null || _b === void 0 ? void 0 : _b.length))
|
|
28
13
|
return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
const [command, ...args] = runtime.install.check;
|
|
15
|
+
const result = (0, cross_spawn_1.sync)(command, args, { stdio: 'ignore' });
|
|
16
|
+
if (result.status === 0)
|
|
17
|
+
return;
|
|
18
|
+
if ((_c = runtime.install.hints) === null || _c === void 0 ? void 0 : _c.length) {
|
|
19
|
+
console.error(`${runtime.start[0]} is not installed.`);
|
|
20
|
+
console.log(colors_1.default.bold('How to install:'));
|
|
21
|
+
runtime.install.hints.forEach((hint) => console.log(hint));
|
|
22
|
+
}
|
|
23
|
+
if ((_d = runtime.install.command) === null || _d === void 0 ? void 0 : _d.length) {
|
|
24
|
+
(0, confirm_1.default)({ message: 'Do you want to install it?' }).then((ans) => {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!ans)
|
|
27
|
+
return;
|
|
28
|
+
const [command, ...args] = (_a = runtime.install) === null || _a === void 0 ? void 0 : _a.command;
|
|
29
|
+
(0, cross_spawn_1.sync)(command, args, { stdio: 'inherit' });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
42
32
|
}
|
|
@@ -23,9 +23,11 @@ exports.default = (0, as_1.default)([
|
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
start: [runtime, ...args],
|
|
27
|
+
install: {
|
|
28
|
+
check: [runtime, '--version'],
|
|
29
|
+
hints: installHints,
|
|
30
|
+
},
|
|
29
31
|
};
|
|
30
32
|
},
|
|
31
33
|
},
|
|
@@ -54,10 +56,12 @@ exports.default = (0, as_1.default)([
|
|
|
54
56
|
break;
|
|
55
57
|
}
|
|
56
58
|
return {
|
|
57
|
-
|
|
58
|
-
isInstalled: [runtime, '--version'],
|
|
59
|
-
installHints,
|
|
59
|
+
start: [runtime, ...args],
|
|
60
60
|
watchExts: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
|
|
61
|
+
install: {
|
|
62
|
+
check: [runtime, '--version'],
|
|
63
|
+
hints: installHints,
|
|
64
|
+
},
|
|
61
65
|
};
|
|
62
66
|
},
|
|
63
67
|
},
|
|
@@ -66,9 +70,11 @@ exports.default = (0, as_1.default)([
|
|
|
66
70
|
exts: ['py'],
|
|
67
71
|
getRuntime(args, options, config) {
|
|
68
72
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
start: ['python', ...args],
|
|
74
|
+
install: {
|
|
75
|
+
check: ['python', '--version'],
|
|
76
|
+
hints: ['Please install Python from https://www.python.org'],
|
|
77
|
+
},
|
|
72
78
|
};
|
|
73
79
|
},
|
|
74
80
|
},
|
|
@@ -77,9 +83,11 @@ exports.default = (0, as_1.default)([
|
|
|
77
83
|
exts: ['java'],
|
|
78
84
|
getRuntime(args, options, config) {
|
|
79
85
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
start: ['java', ...args],
|
|
87
|
+
install: {
|
|
88
|
+
check: ['java', '--version'],
|
|
89
|
+
hints: ['Please install Java from https://www.oracle.com/java'],
|
|
90
|
+
},
|
|
83
91
|
};
|
|
84
92
|
},
|
|
85
93
|
},
|
|
@@ -88,11 +96,13 @@ exports.default = (0, as_1.default)([
|
|
|
88
96
|
exts: ['ps1'],
|
|
89
97
|
getRuntime(args, options, config) {
|
|
90
98
|
return {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
start: ['powershell', '-File', ...args],
|
|
100
|
+
install: {
|
|
101
|
+
check: ['powershell', '-command', 'echo ok'],
|
|
102
|
+
hints: [
|
|
103
|
+
'Please install Powershell from https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell',
|
|
104
|
+
],
|
|
105
|
+
},
|
|
96
106
|
};
|
|
97
107
|
},
|
|
98
108
|
},
|
|
@@ -101,9 +111,11 @@ exports.default = (0, as_1.default)([
|
|
|
101
111
|
exts: ['cmd', 'bat'],
|
|
102
112
|
getRuntime(args, options, config) {
|
|
103
113
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
start: ['cmd', '/c', ...args],
|
|
115
|
+
install: {
|
|
116
|
+
check: ['cmd', '/c', 'echo ok'],
|
|
117
|
+
hints: ['Please install Command Prompt from Windows'],
|
|
118
|
+
},
|
|
107
119
|
};
|
|
108
120
|
},
|
|
109
121
|
},
|
|
@@ -112,11 +124,11 @@ exports.default = (0, as_1.default)([
|
|
|
112
124
|
exts: ['sh'],
|
|
113
125
|
getRuntime(args, options, config) {
|
|
114
126
|
return {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
'Please install Bash from https://www.gnu.org/software/bash',
|
|
119
|
-
|
|
127
|
+
start: ['bash', ...args],
|
|
128
|
+
install: {
|
|
129
|
+
check: ['bash', '--version'],
|
|
130
|
+
hints: ['Please install Bash from https://www.gnu.org/software/bash'],
|
|
131
|
+
},
|
|
120
132
|
};
|
|
121
133
|
},
|
|
122
134
|
},
|
|
@@ -125,9 +137,11 @@ exports.default = (0, as_1.default)([
|
|
|
125
137
|
exts: ['fish'],
|
|
126
138
|
getRuntime(args, options, config) {
|
|
127
139
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
start: ['fish', ...args],
|
|
141
|
+
install: {
|
|
142
|
+
check: ['fish', '--version'],
|
|
143
|
+
hints: ['Please install Fish from https://fishshell.com'],
|
|
144
|
+
},
|
|
131
145
|
};
|
|
132
146
|
},
|
|
133
147
|
},
|
|
@@ -136,9 +150,37 @@ exports.default = (0, as_1.default)([
|
|
|
136
150
|
exts: ['lua'],
|
|
137
151
|
getRuntime(args, options, config) {
|
|
138
152
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
start: ['lua', ...args],
|
|
154
|
+
install: {
|
|
155
|
+
check: ['lua', '-v'],
|
|
156
|
+
hints: ['Please install Lua from https://www.lua.org'],
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'Ruby',
|
|
163
|
+
exts: ['rb'],
|
|
164
|
+
getRuntime(args, options, config) {
|
|
165
|
+
return {
|
|
166
|
+
start: ['ruby', ...args],
|
|
167
|
+
install: {
|
|
168
|
+
check: ['ruby', '-v'],
|
|
169
|
+
hints: ['Please install Ruby from https://www.ruby-lang.org'],
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'Go',
|
|
176
|
+
exts: ['go'],
|
|
177
|
+
getRuntime(args, options, config) {
|
|
178
|
+
return {
|
|
179
|
+
start: ['go', 'run', ...args],
|
|
180
|
+
install: {
|
|
181
|
+
check: ['go', '-v'],
|
|
182
|
+
hints: ['Please install Ruby from https://www.ruby-lang.org'],
|
|
183
|
+
},
|
|
142
184
|
};
|
|
143
185
|
},
|
|
144
186
|
},
|
|
@@ -147,9 +189,11 @@ exports.default = (0, as_1.default)([
|
|
|
147
189
|
exts: ['sass', 'scss'],
|
|
148
190
|
getRuntime(args, options, config) {
|
|
149
191
|
return {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
192
|
+
start: ['sass', ...args],
|
|
193
|
+
install: {
|
|
194
|
+
check: ['sass', '--version'],
|
|
195
|
+
hints: ['Please install SASS from https://sass-lang.com'],
|
|
196
|
+
},
|
|
153
197
|
};
|
|
154
198
|
},
|
|
155
199
|
},
|
|
@@ -158,12 +202,14 @@ exports.default = (0, as_1.default)([
|
|
|
158
202
|
exts: ['html', 'htm'],
|
|
159
203
|
getRuntime(args, options, config) {
|
|
160
204
|
return {
|
|
161
|
-
|
|
162
|
-
isInstalled: ['http-server', '--version'],
|
|
163
|
-
installHints: [
|
|
164
|
-
'Please install http-server from https://www.npmjs.com/package/http-server',
|
|
165
|
-
],
|
|
205
|
+
start: ['http-server', ...args],
|
|
166
206
|
watchExts: ['css', 'js', 'javascript', 'json'],
|
|
207
|
+
install: {
|
|
208
|
+
check: ['http-server', '--version'],
|
|
209
|
+
hints: [
|
|
210
|
+
'Please install http-server from https://www.npmjs.com/package/http-server',
|
|
211
|
+
],
|
|
212
|
+
},
|
|
167
213
|
};
|
|
168
214
|
},
|
|
169
215
|
},
|
|
@@ -4,11 +4,13 @@ export type ExecutorConfig = Partial<{
|
|
|
4
4
|
'typescript-runtime': string;
|
|
5
5
|
}>;
|
|
6
6
|
export type RuntimeOptions = {
|
|
7
|
-
|
|
8
|
-
install?: string[];
|
|
9
|
-
installHints?: string[];
|
|
10
|
-
isInstalled?: string[];
|
|
7
|
+
start: string[];
|
|
11
8
|
watchExts?: string[];
|
|
9
|
+
install?: {
|
|
10
|
+
check?: string[];
|
|
11
|
+
hints?: string[];
|
|
12
|
+
command?: string[];
|
|
13
|
+
};
|
|
12
14
|
};
|
|
13
15
|
export type ScriptExecutorOptions = {
|
|
14
16
|
name: string;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (...extraDirs: string[]): any;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = default_1;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
function getExistedFile(...files) {
|
|
10
|
-
for (const file of files) {
|
|
11
|
-
if (node_fs_1.default.existsSync(file))
|
|
12
|
-
return file;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function default_1(...extraDirs) {
|
|
16
|
-
var _a;
|
|
17
|
-
const userPath = (_a = process.env.HOME) !== null && _a !== void 0 ? _a : process.env.USERPROFILE;
|
|
18
|
-
if (!userPath)
|
|
19
|
-
return;
|
|
20
|
-
const configFile = getExistedFile(...extraDirs.map((dir) => node_path_1.default.join(dir, '/.uni-run.json')), node_path_1.default.join(process.cwd(), '/.uni-run.json'), node_path_1.default.join(userPath, '/.uni-run.json'));
|
|
21
|
-
if (!configFile)
|
|
22
|
-
return;
|
|
23
|
-
try {
|
|
24
|
-
const config = node_fs_1.default.readFileSync(configFile, 'utf-8');
|
|
25
|
-
return JSON.parse(config);
|
|
26
|
-
}
|
|
27
|
-
catch (_b) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
}
|