uni-run 1.0.13 → 1.1.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.
Files changed (77) hide show
  1. package/README.md +53 -25
  2. package/dist/app.js +79 -0
  3. package/dist/{arg.d.cts → arg.d.ts} +1 -1
  4. package/dist/{arg.cjs → arg.js} +3 -3
  5. package/dist/{arg-helper.d.cts → argHelper.d.ts} +3 -4
  6. package/dist/{arg-helper.cjs → argHelper.js} +2 -2
  7. package/dist/{bin.d.cts → bin.d.ts} +1 -1
  8. package/dist/{bin.cjs → bin.js} +2 -2
  9. package/dist/execution/{index.d.mts → index.d.ts} +1 -1
  10. package/dist/execution/{index.cjs → index.js} +3 -3
  11. package/dist/execution/{kill-process.d.cts → kill-process.d.ts} +1 -1
  12. package/dist/execution/{watcher.cjs → watcher.js} +2 -2
  13. package/dist/helpers/as.d.ts +1 -0
  14. package/dist/helpers/as.js +6 -0
  15. package/dist/helpers/get-config.d.ts +1 -0
  16. package/dist/helpers/get-config.js +30 -0
  17. package/dist/helpers/getConfig.d.ts +1 -0
  18. package/dist/helpers/getConfig.js +24 -0
  19. package/dist/helpers/getUserExecutors.d.ts +2 -0
  20. package/dist/helpers/getUserExecutors.js +18 -0
  21. package/dist/helpers/utils.d.ts +2 -0
  22. package/dist/helpers/utils.js +18 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.js +16 -0
  25. package/dist/lib/{colors.d.cts → colors.d.ts} +1 -1
  26. package/dist/lib/{colors.cjs → colors.js} +1 -1
  27. package/dist/scriptExecutors/checkRuntime.d.ts +2 -0
  28. package/dist/scriptExecutors/checkRuntime.js +42 -0
  29. package/dist/scriptExecutors/index.d.ts +3 -0
  30. package/dist/scriptExecutors/index.js +170 -0
  31. package/dist/scriptExecutors/types.t.d.ts +17 -0
  32. package/dist/scriptExecutors/types.t.js +2 -0
  33. package/package.json +9 -12
  34. package/dist/app.cjs +0 -60
  35. package/dist/app.d.mts +0 -1
  36. package/dist/app.mjs +0 -32
  37. package/dist/arg-helper.d.mts +0 -141
  38. package/dist/arg-helper.mjs +0 -108
  39. package/dist/arg.d.mts +0 -277
  40. package/dist/arg.mjs +0 -9
  41. package/dist/bin.d.mts +0 -2
  42. package/dist/bin.mjs +0 -4
  43. package/dist/builtin-bin/Executor.cjs +0 -67
  44. package/dist/builtin-bin/Executor.d.cts +0 -21
  45. package/dist/builtin-bin/Executor.d.mts +0 -21
  46. package/dist/builtin-bin/Executor.mjs +0 -61
  47. package/dist/builtin-bin/index.cjs +0 -107
  48. package/dist/builtin-bin/index.d.cts +0 -3
  49. package/dist/builtin-bin/index.d.mts +0 -3
  50. package/dist/builtin-bin/index.mjs +0 -102
  51. package/dist/execution/gitignore.d.mts +0 -1
  52. package/dist/execution/gitignore.mjs +0 -11
  53. package/dist/execution/index.d.cts +0 -17
  54. package/dist/execution/index.mjs +0 -127
  55. package/dist/execution/kill-process.d.mts +0 -2
  56. package/dist/execution/kill-process.mjs +0 -24
  57. package/dist/execution/watcher.d.mts +0 -6
  58. package/dist/execution/watcher.mjs +0 -31
  59. package/dist/index.cjs +0 -19
  60. package/dist/index.d.cts +0 -8
  61. package/dist/index.d.mts +0 -8
  62. package/dist/index.mjs +0 -13
  63. package/dist/lib/colors.d.mts +0 -3
  64. package/dist/lib/colors.mjs +0 -4
  65. package/dist/lib/currentModule.d.mts +0 -5
  66. package/dist/lib/currentModule.mjs +0 -17
  67. package/dist/utils/debounce.d.mts +0 -1
  68. package/dist/utils/debounce.mjs +0 -7
  69. /package/dist/{app.d.cts → app.d.ts} +0 -0
  70. /package/dist/execution/{gitignore.d.cts → gitignore.d.ts} +0 -0
  71. /package/dist/execution/{gitignore.cjs → gitignore.js} +0 -0
  72. /package/dist/execution/{kill-process.cjs → kill-process.js} +0 -0
  73. /package/dist/execution/{watcher.d.cts → watcher.d.ts} +0 -0
  74. /package/dist/{utils/debounce.d.cts → helpers/debounce.d.ts} +0 -0
  75. /package/dist/{utils/debounce.cjs → helpers/debounce.js} +0 -0
  76. /package/dist/lib/{currentModule.d.cts → currentModule.d.ts} +0 -0
  77. /package/dist/lib/{currentModule.cjs → currentModule.js} +0 -0
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
+ Here is the corrected grammar for your document:
2
+
1
3
  # uni-run
2
4
 
3
- `uni-run` is a versatile CLI tool designed to run various types of scripts, including but not limited to JavaScript, TypeScript, Python, Java, HTML, SASS, Lua and more. It provides a unified interface to execute scripts with additional features like watching for file changes, benchmarking execution time, and more.
5
+ `uni-run` is a versatile CLI tool designed to run various types of scripts, including but not limited to JavaScript, TypeScript, Python, Java, HTML, SASS, Lua, and more. It provides a unified interface to execute scripts with additional features like watching for file changes, benchmarking execution time, and more.
4
6
 
5
7
  ## Features
6
8
 
7
9
  - **Watch Mode**: Automatically re-run scripts when files change.
8
10
  - **Benchmarking**: Measure and display the execution time of scripts.
9
- - **Environment Variables**: Set environment variables for the script execution.
11
+ - **Environment Variables**: Set environment variables for script execution.
10
12
  - **Shell Execution**: Run scripts in a shell for more control.
11
13
  - **Console Clearing**: Clear the console before running the script.
12
14
  - **Reload Key**: Enable reloading the script with a specific key combination.
@@ -63,28 +65,57 @@ run ./scripts/Main.java
63
65
  run ./scripts/main.js -- --some someValue
64
66
  ```
65
67
 
66
- Here `--some someValue` will be passed to `node` and will be ignored by uni-run.
68
+ Here `--some someValue` will be passed to `node` and will be ignored by `uni-run`.
69
+
70
+ ## Define Custom Configuration
71
+
72
+ Create `.uni-run.json` file in your user home directory.
73
+
74
+ ```json
75
+ {
76
+ "javascript-runtime": "bun",
77
+ "typescript-runtime": "deno"
78
+ }
79
+ ```
80
+
81
+ Now you can run your script with `run script.js` or `run script.ts` with your own runtime.
82
+
83
+ ## Setup Custom Executors
84
+
85
+ Create `.uni-run.cjs` file in your user home directory.
86
+
87
+ ```js
88
+ module.exports = [
89
+ {
90
+ name: 'Something',
91
+ exts: ['ext'],
92
+ getRuntime(args, options, config) {
93
+ return {
94
+ run: ['YOUR_BIN', ...args],
95
+ }
96
+ },
97
+ },
98
+ ]
99
+ ```
100
+
101
+ Now you can run your script with `run script.ext`.
67
102
 
68
103
  ## API
69
104
 
70
105
  The `uni-run` package provides a simple API to manage and execute scripts.
71
106
 
72
- #### `addBin(bin: Executor)`:
73
-
74
- The `Executor` class is imported from `uni-run` and is used to manage script execution.
75
- Adds a new `Executor` instance to the list of built-in binaries.
107
+ #### `addExecutor(options: ExecutorOptions)`:
76
108
 
77
109
  ```typescript
78
- import uniRun, { Executor } from 'uni-run'
110
+ import uniRun from 'uni-run'
79
111
 
80
- const executor = new Executor('Name', {
81
- extensions: ['something'],
82
- run(args, options) {
112
+ uniRun.addExecutor({
113
+ name: 'Name',
114
+ exts: ['something'],
115
+ getRuntime(args, options, config) {
83
116
  return ['something-binary', ...args]
84
117
  },
85
118
  })
86
-
87
- uniRun.addBin(executor)
88
119
  ```
89
120
 
90
121
  #### `start(args?: string[])`:
@@ -100,23 +131,20 @@ uniRun.start(['arg1', 'arg2'])
100
131
  ### Example Usage
101
132
 
102
133
  ```typescript
103
- import uniRun, { Executor } from 'uni-run'
134
+ import uniRun from 'uni-run'
104
135
 
105
- // Create a new Executor instance
106
- const executor = new Executor('Name', {
107
- extensions: ['some'],
108
- run(args, options) {
136
+ // Add the Executor to uni-run
137
+ uniRun.addExecutor({
138
+ name: 'Name',
139
+ exts: ['something'],
140
+ getRuntime(args, options, config) {
109
141
  return ['something-binary', ...args]
110
142
  },
111
143
  })
112
144
 
113
- // Add the Executor to uni-run
114
- uniRun.addBin(executor)
115
-
116
145
  // Start the application with arguments
117
146
  uniRun.start(['arg1.some'])
118
- ```
119
147
 
120
- ## License
121
-
122
- This project is licensed under the MIT License.
148
+ // Or inherit from CLI
149
+ uniRun.start()
150
+ ```
package/dist/app.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const arg = __importStar(require("./arg"));
39
+ const execution_1 = __importDefault(require("./execution"));
40
+ const getConfig_1 = __importDefault(require("./helpers/getConfig"));
41
+ const argHelper_1 = require("./argHelper");
42
+ const scriptExecutors_1 = __importDefault(require("./scriptExecutors"));
43
+ const checkRuntime_1 = __importDefault(require("./scriptExecutors/checkRuntime"));
44
+ const getUserExecutors_1 = __importDefault(require("./helpers/getUserExecutors"));
45
+ arg.app.on((_a, flags_1) => __awaiter(void 0, [_a, flags_1], void 0, function* ([script, listArs, trailingArgs], flags) {
46
+ var _b;
47
+ const userExecutors = (0, getUserExecutors_1.default)(flags.cwd);
48
+ const executionConfig = (0, getConfig_1.default)(flags.cwd);
49
+ const totalExecutors = [
50
+ ...(Array.isArray(userExecutors) ? userExecutors : []),
51
+ ...scriptExecutors_1.default,
52
+ ];
53
+ const scriptExecutor = totalExecutors.find((executor) => executor.exts.includes(script.split('.').pop()));
54
+ if (!scriptExecutor) {
55
+ console.log('Unsupported script:', script);
56
+ return console.log('You may try "run exec YOUR_BIN script.ext -- --flags"');
57
+ }
58
+ const executionOptions = (0, argHelper_1.mapFlagsToOptions)(flags);
59
+ const runtime = scriptExecutor.getRuntime([script, ...listArs, ...trailingArgs], executionOptions, executionConfig);
60
+ (0, checkRuntime_1.default)(runtime);
61
+ execution_1.default.start(runtime.run, Object.assign(Object.assign({}, executionOptions), { watchExtensions: executionOptions.watchExtensions.length
62
+ ? executionOptions.watchExtensions
63
+ : [...scriptExecutor.exts, ...((_b = runtime.watchExts) !== null && _b !== void 0 ? _b : [])] }));
64
+ }));
65
+ arg.exec.on(([listArs, trailingArgs], flags) => {
66
+ execution_1.default.start([...listArs, ...trailingArgs], (0, argHelper_1.mapFlagsToOptions)(flags));
67
+ });
68
+ 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}`));
79
+ });
@@ -1,4 +1,4 @@
1
- import NoArg from "noarg";
1
+ import NoArg from 'noarg';
2
2
  export declare const app: NoArg<"uni-run", {
3
3
  readonly allowEqualAssign: true;
4
4
  readonly booleanNotSyntaxEnding: "\\";
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.list = exports.exec = exports.app = void 0;
7
7
  const noarg_1 = __importDefault(require("noarg"));
8
- const arg_helper_1 = require("./arg-helper.cjs");
9
- exports.app = noarg_1.default.create('uni-run', Object.assign(Object.assign({}, arg_helper_1.executionConfig), { description: 'A universal runner for scripts', system: { splitListByComma: true }, arguments: [
8
+ const argHelper_1 = require("./argHelper");
9
+ exports.app = noarg_1.default.create('uni-run', Object.assign(Object.assign({}, argHelper_1.executionConfig), { description: 'A universal runner for scripts', system: { splitListByComma: true }, arguments: [
10
10
  { name: 'script', type: noarg_1.default.string(), description: 'Run a script' },
11
11
  ] }));
12
- exports.exec = exports.app.create('exec', Object.assign(Object.assign({}, arg_helper_1.executionConfig), { description: 'Execute a script with the given binary' }));
12
+ exports.exec = exports.app.create('exec', Object.assign(Object.assign({}, argHelper_1.executionConfig), { description: 'Execute a script with the given binary' }));
13
13
  exports.list = exports.app.create('list', {
14
14
  description: 'List supported scripts',
15
15
  });
@@ -1,6 +1,5 @@
1
- import NoArg from "noarg";
2
- import type { app } from "./arg.cjs";
3
- import Executor from "./builtin-bin/Executor.cjs";
1
+ import NoArg from 'noarg';
2
+ import type { app } from './arg';
4
3
  export declare const executionConfig: {
5
4
  readonly flags: {
6
5
  readonly 'key-reload': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
@@ -120,7 +119,7 @@ export declare const executionConfig: {
120
119
  };
121
120
  };
122
121
  export type ExecuteOptions = ReturnType<typeof mapFlagsToOptions>;
123
- export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>, bin?: Executor): {
122
+ export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>): {
124
123
  cwd: string;
125
124
  shell: boolean;
126
125
  silent: boolean;
@@ -87,7 +87,7 @@ exports.executionConfig = noarg_1.default.defineConfig({
87
87
  helpUsageTrailingArgsLabel: '...[args/flags for script]',
88
88
  },
89
89
  });
90
- function mapFlagsToOptions(flags, bin) {
90
+ function mapFlagsToOptions(flags) {
91
91
  var _a;
92
92
  return {
93
93
  cwd: flags.cwd,
@@ -104,7 +104,7 @@ function mapFlagsToOptions(flags, bin) {
104
104
  watchDelay: flags.delay,
105
105
  watchFocus: flags.focus.length ? flags.focus : [flags.cwd],
106
106
  watchIgnore: flags.ignore,
107
- watchExtensions: (flags.ext.length ? flags.ext : bin === null || bin === void 0 ? void 0 : bin.getRelatedExts()) || [],
107
+ watchExtensions: flags.ext,
108
108
  tsNode: flags['tsn'],
109
109
  env: Object.assign(Object.assign({}, flags.env.reduce((acc, env) => {
110
110
  const [key, value] = env.split('=');
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import "./app.cjs";
2
+ import './app';
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- require("./app.cjs");
5
- const arg_1 = require("./arg.cjs");
4
+ require("./app");
5
+ const arg_1 = require("./arg");
6
6
  arg_1.app.start();
@@ -1,4 +1,4 @@
1
- import { ExecuteOptions } from "../arg-helper.mjs";
1
+ import { ExecuteOptions } from '../argHelper';
2
2
  export default class Execution {
3
3
  private command;
4
4
  private args;
@@ -28,9 +28,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const cross_spawn_1 = require("cross-spawn");
30
30
  const readline = __importStar(require("readline"));
31
- const watcher_1 = __importDefault(require("./watcher.cjs"));
32
- const colors_1 = __importDefault(require("../lib/colors.cjs"));
33
- const kill_process_1 = __importDefault(require("./kill-process.cjs"));
31
+ const watcher_1 = __importDefault(require("./watcher"));
32
+ const colors_1 = __importDefault(require("../lib/colors"));
33
+ const kill_process_1 = __importDefault(require("./kill-process"));
34
34
  class Execution {
35
35
  static start([command, ...args], options) {
36
36
  return new Execution(command, args, options);
@@ -1,2 +1,2 @@
1
- import { ChildProcess } from "child_process";
1
+ import { ChildProcess } from 'child_process';
2
2
  export default function (child: ChildProcess): boolean;
@@ -28,9 +28,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.default = default_1;
30
30
  const path = __importStar(require("path"));
31
- const gitignore_1 = __importDefault(require("./gitignore.cjs"));
31
+ const gitignore_1 = __importDefault(require("./gitignore"));
32
32
  const chokidar = __importStar(require("chokidar"));
33
- const debounce_1 = require("../utils/debounce.cjs");
33
+ const debounce_1 = require("../helpers/debounce");
34
34
  function default_1(cwd, targets, callback, options) {
35
35
  const ig = (0, gitignore_1.default)(cwd, options.ignore);
36
36
  const debounce = (0, debounce_1.createDebounce)(options.debounceDelay);
@@ -0,0 +1 @@
1
+ export default function <const T>(arg: T): T;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ function default_1(arg) {
5
+ return arg;
6
+ }
@@ -0,0 +1 @@
1
+ export default function (...extraDirs: string[]): any;
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1 @@
1
+ export default function (...extraDirs: string[]): any;
@@ -0,0 +1,24 @@
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 fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_1 = require("./utils");
10
+ function default_1(...extraDirs) {
11
+ const userPath = (0, utils_1.getUserPath)();
12
+ if (!userPath)
13
+ return;
14
+ const configFile = (0, utils_1.getExistedFile)(...extraDirs.map((dir) => path_1.default.join(dir, '/.uni-run.json')), path_1.default.join(process.cwd(), '/.uni-run.json'), path_1.default.join(userPath, '/.uni-run.json'));
15
+ if (!configFile)
16
+ return;
17
+ try {
18
+ const config = fs_1.default.readFileSync(configFile, 'utf-8');
19
+ return JSON.parse(config);
20
+ }
21
+ catch (_a) {
22
+ return {};
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ import { ScriptExecutorOptions } from '../scriptExecutors/types.t';
2
+ export default function (...extraDirs: string[]): ScriptExecutorOptions[] | undefined;
@@ -0,0 +1,18 @@
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 path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("./utils");
9
+ const EXECUTOR_CONFIG_FILE = '.uni-run.cjs';
10
+ function default_1(...extraDirs) {
11
+ const userPath = (0, utils_1.getUserPath)();
12
+ if (!userPath)
13
+ return;
14
+ const configFile = (0, utils_1.getExistedFile)(...extraDirs.map((dir) => path_1.default.join(dir, EXECUTOR_CONFIG_FILE)), path_1.default.join(process.cwd(), EXECUTOR_CONFIG_FILE), path_1.default.join(userPath, EXECUTOR_CONFIG_FILE));
15
+ if (!configFile)
16
+ return;
17
+ return require(configFile);
18
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getExistedFile(...files: string[]): string | undefined;
2
+ export declare function getUserPath(): string | undefined;
@@ -0,0 +1,18 @@
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.getExistedFile = getExistedFile;
7
+ exports.getUserPath = getUserPath;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ function getExistedFile(...files) {
10
+ for (const file of files) {
11
+ if (fs_1.default.existsSync(file))
12
+ return file;
13
+ }
14
+ }
15
+ function getUserPath() {
16
+ var _a;
17
+ return (_a = process.env.HOME) !== null && _a !== void 0 ? _a : process.env.USERPROFILE;
18
+ }
@@ -0,0 +1,7 @@
1
+ import './app';
2
+ import { ScriptExecutorOptions } from './scriptExecutors/types.t';
3
+ declare const _default: {
4
+ addExecutor(executor: ScriptExecutorOptions): void;
5
+ start(args?: string[]): void;
6
+ };
7
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
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
+ require("./app");
7
+ const arg_1 = require("./arg");
8
+ const scriptExecutors_1 = __importDefault(require("./scriptExecutors"));
9
+ exports.default = {
10
+ addExecutor(executor) {
11
+ scriptExecutors_1.default.unshift(executor);
12
+ },
13
+ start(args) {
14
+ arg_1.app.start(args);
15
+ },
16
+ };
@@ -1,3 +1,3 @@
1
- import mjs from "ansi-colors";
1
+ import mjs from 'ansi-colors';
2
2
  declare const _default: typeof mjs;
3
3
  export default _default;
@@ -28,5 +28,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const ansi_colors_1 = __importDefault(require("ansi-colors"));
30
30
  const cjs = __importStar(require("ansi-colors"));
31
- const currentModule_1 = __importDefault(require("./currentModule.cjs"));
31
+ const currentModule_1 = __importDefault(require("./currentModule"));
32
32
  exports.default = currentModule_1.default.isCJS ? cjs : ansi_colors_1.default;
@@ -0,0 +1,2 @@
1
+ import { RuntimeOptions } from './types.t';
2
+ export default function (runtime: RuntimeOptions): false | undefined;
@@ -0,0 +1,42 @@
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 confirm_1 = __importDefault(require("@inquirer/confirm"));
8
+ const cross_spawn_1 = require("cross-spawn");
9
+ 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))
28
+ 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
+ });
42
+ }
@@ -0,0 +1,3 @@
1
+ import { ScriptExecutorOptions } from './types.t';
2
+ declare const _default: ScriptExecutorOptions[];
3
+ export default _default;