uni-run 1.1.0 → 1.1.2

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
@@ -69,7 +69,7 @@ Here `--some someValue` will be passed to `node` and will be ignored by `uni-run
69
69
 
70
70
  ## Define Custom Configuration
71
71
 
72
- Create `.uni-run.json` file in your user home directory.
72
+ Create `.uni-run.json` file in your user home directory or current working directory.
73
73
 
74
74
  ```json
75
75
  {
@@ -82,7 +82,7 @@ Now you can run your script with `run script.js` or `run script.ts` with your ow
82
82
 
83
83
  ## Setup Custom Executors
84
84
 
85
- Create `.uni-run.cjs` file in your user home directory.
85
+ Create `.uni-run.cjs` file in your user home directory or current working directory.
86
86
 
87
87
  ```js
88
88
  module.exports = [
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,7 +53,7 @@ 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.log('Unsupported script:', script);
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);
@@ -66,14 +67,13 @@ arg.exec.on(([listArs, trailingArgs], flags) => {
66
67
  execution_1.default.start([...listArs, ...trailingArgs], (0, argHelper_1.mapFlagsToOptions)(flags));
67
68
  });
68
69
  arg.list.on(() => {
69
- console.log('Supported scripts:');
70
- scriptExecutors_1.default
71
- .sort((a, b) => {
72
- if (a.name < b.name)
73
- return -1;
74
- if (a.name > b.name)
75
- return 1;
76
- return 0;
77
- })
78
- .forEach(({ name }) => console.log(`- ${name}`));
70
+ const userExecutors = (0, getUserExecutors_1.default)();
71
+ const totalExecutors = [
72
+ ...(Array.isArray(userExecutors) ? userExecutors : []),
73
+ ...scriptExecutors_1.default,
74
+ ];
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
+ });
79
79
  });
@@ -1,2 +1,2 @@
1
1
  import { RuntimeOptions } from './types.t';
2
- export default function (runtime: RuntimeOptions): false | undefined;
2
+ export default function (runtime: RuntimeOptions): void;
@@ -4,39 +4,28 @@ 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
- if (!isInstalled(runtime.isInstalled)) {
11
- renderHowToInstall(runtime.run[0], runtime.installHints);
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;
12
+ if (!((_a = runtime.isInstalled) === null || _a === void 0 ? void 0 : _a.length))
28
13
  return;
29
- console.error(`${name} is not installed.`);
30
- console.log('How to install:');
31
- hints.forEach((hint) => console.log(hint));
32
- }
33
- function canBeInstalled(installCommands) {
34
- if (!(installCommands === null || installCommands === void 0 ? void 0 : installCommands.length))
35
- return false;
36
- (0, confirm_1.default)({ message: 'Do you want to install it?' }).then((ans) => {
37
- if (!ans)
38
- return;
39
- const [command, ...args] = installCommands;
40
- (0, cross_spawn_1.sync)(command, args, { stdio: 'inherit' });
41
- });
14
+ const [command, ...args] = runtime.isInstalled;
15
+ const result = (0, cross_spawn_1.sync)(command, args, { stdio: 'ignore' });
16
+ if (result.status === 0)
17
+ return;
18
+ if ((_b = runtime.installHints) === null || _b === void 0 ? void 0 : _b.length) {
19
+ console.error(`${runtime.run[0]} is not installed.`);
20
+ console.log(colors_1.default.bold('How to install:'));
21
+ runtime.installHints.forEach((hint) => console.log(hint));
22
+ }
23
+ if ((_c = runtime.install) === null || _c === void 0 ? void 0 : _c.length) {
24
+ (0, confirm_1.default)({ message: 'Do you want to install it?' }).then((ans) => {
25
+ if (!ans)
26
+ return;
27
+ const [command, ...args] = runtime.install;
28
+ (0, cross_spawn_1.sync)(command, args, { stdio: 'inherit' });
29
+ });
30
+ }
42
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-run",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Universal Runner for many language",
5
5
  "type": "commonjs",
6
6
  "scripts": {