uni-run 1.1.2 → 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 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: 'Something',
91
+ name: 'Name',
91
92
  exts: ['ext'],
92
93
  getRuntime(args, options, config) {
93
94
  return {
94
- run: ['YOUR_BIN', ...args],
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
- #### `addExecutor(options: ExecutorOptions)`:
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.addExecutor({
115
+ uniRun.addExecutorBefore({
113
116
  name: 'Name',
114
- exts: ['something'],
117
+ exts: ['ext'],
115
118
  getRuntime(args, options, config) {
116
- return ['something-binary', ...args]
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.addExecutor({
142
+ uniRun.addExecutorBefore({
138
143
  name: 'Name',
139
- exts: ['something'],
144
+ exts: ['ext'],
140
145
  getRuntime(args, options, config) {
141
- return ['something-binary', ...args]
146
+ return {
147
+ start: ['YOUR_BIN', ...args],
148
+ }
142
149
  },
143
150
  })
144
151
 
package/dist/app.js CHANGED
@@ -59,7 +59,7 @@ arg.app.on((_a, flags_1) => __awaiter(void 0, [_a, flags_1], void 0, function* (
59
59
  const executionOptions = (0, argHelper_1.mapFlagsToOptions)(flags);
60
60
  const runtime = scriptExecutor.getRuntime([script, ...listArs, ...trailingArgs], executionOptions, executionConfig);
61
61
  (0, checkRuntime_1.default)(runtime);
62
- execution_1.default.start(runtime.run, Object.assign(Object.assign({}, executionOptions), { watchExtensions: executionOptions.watchExtensions.length
62
+ execution_1.default.start(runtime.start, Object.assign(Object.assign({}, executionOptions), { watchExtensions: executionOptions.watchExtensions.length
63
63
  ? executionOptions.watchExtensions
64
64
  : [...scriptExecutor.exts, ...((_b = runtime.watchExts) !== null && _b !== void 0 ? _b : [])] }));
65
65
  }));
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
- addExecutor(executor: ScriptExecutorOptions): void;
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
- addExecutor(executor) {
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
  },
@@ -8,23 +8,24 @@ const colors_1 = __importDefault(require("../lib/colors"));
8
8
  const confirm_1 = __importDefault(require("@inquirer/confirm"));
9
9
  const cross_spawn_1 = require("cross-spawn");
10
10
  function default_1(runtime) {
11
- var _a, _b, _c;
12
- if (!((_a = runtime.isInstalled) === null || _a === void 0 ? void 0 : _a.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))
13
13
  return;
14
- const [command, ...args] = runtime.isInstalled;
14
+ const [command, ...args] = runtime.install.check;
15
15
  const result = (0, cross_spawn_1.sync)(command, args, { stdio: 'ignore' });
16
16
  if (result.status === 0)
17
17
  return;
18
- if ((_b = runtime.installHints) === null || _b === void 0 ? void 0 : _b.length) {
19
- console.error(`${runtime.run[0]} is not installed.`);
18
+ if ((_c = runtime.install.hints) === null || _c === void 0 ? void 0 : _c.length) {
19
+ console.error(`${runtime.start[0]} is not installed.`);
20
20
  console.log(colors_1.default.bold('How to install:'));
21
- runtime.installHints.forEach((hint) => console.log(hint));
21
+ runtime.install.hints.forEach((hint) => console.log(hint));
22
22
  }
23
- if ((_c = runtime.install) === null || _c === void 0 ? void 0 : _c.length) {
23
+ if ((_d = runtime.install.command) === null || _d === void 0 ? void 0 : _d.length) {
24
24
  (0, confirm_1.default)({ message: 'Do you want to install it?' }).then((ans) => {
25
+ var _a;
25
26
  if (!ans)
26
27
  return;
27
- const [command, ...args] = runtime.install;
28
+ const [command, ...args] = (_a = runtime.install) === null || _a === void 0 ? void 0 : _a.command;
28
29
  (0, cross_spawn_1.sync)(command, args, { stdio: 'inherit' });
29
30
  });
30
31
  }
@@ -23,9 +23,11 @@ exports.default = (0, as_1.default)([
23
23
  break;
24
24
  }
25
25
  return {
26
- run: [runtime, ...args],
27
- isInstalled: [runtime, '--version'],
28
- installHints,
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
- run: [runtime, ...args],
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
- run: ['python', ...args],
70
- isInstalled: ['python', '--version'],
71
- installHints: ['Please install Python from https://www.python.org'],
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
- run: ['java', ...args],
81
- isInstalled: ['java', '--version'],
82
- installHints: ['Please install Java from https://www.oracle.com/java'],
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
- run: ['powershell', '-File', ...args],
92
- isInstalled: ['powershell', '-command', 'echo ok'],
93
- installHints: [
94
- 'Please install Powershell from https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell',
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
- run: ['cmd', '/c', ...args],
105
- isInstalled: ['cmd', '/c', 'echo ok'],
106
- installHints: ['Please install Command Prompt from Windows'],
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
- run: ['bash', ...args],
116
- isInstalled: ['bash', '--version'],
117
- installHints: [
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
- run: ['fish', ...args],
129
- isInstalled: ['fish', '--version'],
130
- installHints: ['Please install Fish from https://fishshell.com'],
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
- run: ['lua', ...args],
140
- isInstalled: ['lua', '-v'],
141
- installHints: ['Please install Lua from https://www.lua.org'],
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
- run: ['sass', ...args],
151
- isInstalled: ['sass', '--version'],
152
- installHints: ['Please install SASS from https://sass-lang.com'],
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
- run: ['http-server', ...args],
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
- run: string[];
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,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-run",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Universal Runner for many language",
5
5
  "type": "commonjs",
6
6
  "scripts": {
@@ -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
- }