uni-run 1.0.5 → 1.0.6
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 +122 -0
- package/dist/app.cjs +60 -0
- package/dist/app.d.mts +1 -0
- package/dist/{index.js → app.mjs} +8 -10
- package/dist/{arg-helper.js → arg-helper.cjs} +43 -32
- package/dist/{arg-helper.d.ts → arg-helper.d.cts} +51 -45
- package/dist/arg-helper.d.mts +121 -0
- package/dist/arg-helper.mjs +93 -0
- package/dist/{arg.js → arg.cjs} +5 -2
- package/dist/{arg.d.ts → arg.d.cts} +95 -83
- package/dist/arg.d.mts +243 -0
- package/dist/arg.mjs +9 -0
- package/dist/{bin.js → bin.cjs} +2 -2
- package/dist/{bin.d.ts → bin.d.cts} +1 -1
- package/dist/bin.d.mts +2 -0
- package/dist/bin.mjs +4 -0
- package/dist/builtin-bin/{Executor.js → Executor.cjs} +5 -2
- package/dist/builtin-bin/{Executor.d.ts → Executor.d.cts} +1 -1
- package/dist/builtin-bin/Executor.d.mts +21 -0
- package/dist/builtin-bin/Executor.mjs +61 -0
- package/dist/builtin-bin/{index.js → index.cjs} +4 -1
- package/dist/builtin-bin/{index.d.ts → index.d.cts} +1 -1
- package/dist/builtin-bin/index.d.mts +3 -0
- package/dist/builtin-bin/index.mjs +94 -0
- package/dist/execution/gitignore.cjs +40 -0
- package/dist/execution/gitignore.d.mts +1 -0
- package/dist/execution/gitignore.mjs +11 -0
- package/dist/execution/{index.js → index.cjs} +32 -6
- package/dist/execution/{index.d.ts → index.d.cts} +1 -1
- package/dist/execution/index.d.mts +15 -0
- package/dist/execution/index.mjs +103 -0
- package/dist/execution/kill-process.cjs +50 -0
- package/dist/execution/{kill-process.d.ts → kill-process.d.cts} +1 -1
- package/dist/execution/kill-process.d.mts +2 -0
- package/dist/execution/{kill-process.js → kill-process.mjs} +4 -7
- package/dist/execution/watcher.cjs +64 -0
- package/dist/execution/watcher.d.mts +6 -0
- package/dist/execution/{watcher.js → watcher.mjs} +7 -10
- package/dist/index.cjs +19 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +13 -0
- package/dist/lib/colors.cjs +32 -0
- package/dist/lib/colors.d.cts +3 -0
- package/dist/lib/colors.d.mts +3 -0
- package/dist/lib/colors.mjs +4 -0
- package/dist/lib/currentModule.cjs +19 -0
- package/dist/lib/currentModule.d.cts +5 -0
- package/dist/lib/currentModule.d.mts +5 -0
- package/dist/lib/currentModule.mjs +17 -0
- package/dist/utils/debounce.d.mts +1 -0
- package/dist/utils/debounce.mjs +7 -0
- package/package.json +12 -8
- package/dist/execution/gitignore.js +0 -14
- package/dist/lib/colors.d.ts +0 -2
- package/dist/lib/colors.js +0 -4
- /package/dist/{index.d.ts → app.d.cts} +0 -0
- /package/dist/execution/{gitignore.d.ts → gitignore.d.cts} +0 -0
- /package/dist/execution/{watcher.d.ts → watcher.d.cts} +0 -0
- /package/dist/utils/{debounce.js → debounce.cjs} +0 -0
- /package/dist/utils/{debounce.d.ts → debounce.d.cts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# uni-run
|
|
2
|
+
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Watch Mode**: Automatically re-run scripts when files change.
|
|
8
|
+
- **Benchmarking**: Measure and display the execution time of scripts.
|
|
9
|
+
- **Environment Variables**: Set environment variables for the script execution.
|
|
10
|
+
- **Shell Execution**: Run scripts in a shell for more control.
|
|
11
|
+
- **Console Clearing**: Clear the console before running the script.
|
|
12
|
+
- **Reload Key**: Enable reloading the script with a specific key combination.
|
|
13
|
+
- **Information Display**: Show detailed information about the script execution.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
To install `uni-run`, use npm:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install -g uni-run
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## CLI Usage
|
|
24
|
+
|
|
25
|
+
### Basic Command
|
|
26
|
+
|
|
27
|
+
To run a script, use the following command:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
run script.ext [options] -- [args for internal bin]
|
|
31
|
+
uni-run script.ext [options] -- [args for internal bin]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Examples
|
|
35
|
+
|
|
36
|
+
#### Running a JavaScript File
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
run ./scripts/main.js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Running a TypeScript File
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
run ./scripts/main.ts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Running a Python File
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
run ./scripts/main.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Running a Java File
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
run ./scripts/Main.java
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Running with script argv
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
run ./scripts/main.js -- --some someValue
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Here `--some someValue` will be passed to `node` and will be ignored by uni-run.
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
The `uni-run` package provides a simple API to manage and execute scripts.
|
|
71
|
+
|
|
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.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import uniRun, { Executor } from 'uni-run'
|
|
79
|
+
|
|
80
|
+
const executor = new Executor('Name', {
|
|
81
|
+
extensions: ['something'],
|
|
82
|
+
run(args, options) {
|
|
83
|
+
return ['something-binary', ...args]
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
uniRun.addBin(executor)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### `start(args?: string[])`:
|
|
91
|
+
|
|
92
|
+
Starts the application with the provided arguments.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import uniRun from 'uni-run'
|
|
96
|
+
|
|
97
|
+
uniRun.start(['arg1', 'arg2'])
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Example Usage
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import uniRun, { Executor } from 'uni-run'
|
|
104
|
+
|
|
105
|
+
// Create a new Executor instance
|
|
106
|
+
const executor = new Executor('Name', {
|
|
107
|
+
extensions: ['some'],
|
|
108
|
+
run(args, options) {
|
|
109
|
+
return ['something-binary', ...args]
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Add the Executor to uni-run
|
|
114
|
+
uniRun.addBin(executor)
|
|
115
|
+
|
|
116
|
+
// Start the application with arguments
|
|
117
|
+
uniRun.start(['arg1.some'])
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
This project is licensed under the MIT License.
|
package/dist/app.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const arg = __importStar(require("./arg.cjs"));
|
|
30
|
+
const execution_1 = __importDefault(require("./execution/index.cjs"));
|
|
31
|
+
const builtin_bin_1 = __importDefault(require("./builtin-bin/index.cjs"));
|
|
32
|
+
const arg_helper_1 = require("./arg-helper.cjs");
|
|
33
|
+
arg.app.on(([script, listArs, trailingArgs], flags) => {
|
|
34
|
+
const bin = builtin_bin_1.default.find((bin) => bin.isSupported(script));
|
|
35
|
+
if (!bin) {
|
|
36
|
+
console.log('Unsupported script:', script);
|
|
37
|
+
return console.log('You may try "ur exec bin script.ext - --flags"');
|
|
38
|
+
}
|
|
39
|
+
const executionOptions = (0, arg_helper_1.mapFlagsToOptions)(flags, bin);
|
|
40
|
+
bin.start(executionOptions, [script, ...listArs, ...trailingArgs]);
|
|
41
|
+
});
|
|
42
|
+
arg.exec.on(([listArs, trailingArgs], flags) => {
|
|
43
|
+
execution_1.default.start([...listArs, ...trailingArgs], (0, arg_helper_1.mapFlagsToOptions)(flags));
|
|
44
|
+
});
|
|
45
|
+
arg.list.on(() => {
|
|
46
|
+
console.log('Supported scripts:');
|
|
47
|
+
builtin_bin_1.default
|
|
48
|
+
.sort((a, b) => {
|
|
49
|
+
const aName = a.getName();
|
|
50
|
+
const bName = b.getName();
|
|
51
|
+
if (aName < bName)
|
|
52
|
+
return -1;
|
|
53
|
+
if (aName > bName)
|
|
54
|
+
return 1;
|
|
55
|
+
return 0;
|
|
56
|
+
})
|
|
57
|
+
.forEach((bin) => {
|
|
58
|
+
console.log(`- ${bin.getName()}`);
|
|
59
|
+
});
|
|
60
|
+
});
|
package/dist/app.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const builtin_bin_1 = require("./builtin-bin");
|
|
6
|
-
const arg_helper_1 = require("./arg-helper");
|
|
1
|
+
import * as arg from "./arg.mjs";
|
|
2
|
+
import Execution from "./execution/index.mjs";
|
|
3
|
+
import builtinBin from "./builtin-bin/index.mjs";
|
|
4
|
+
import { mapFlagsToOptions } from "./arg-helper.mjs";
|
|
7
5
|
arg.app.on(([script, listArs, trailingArgs], flags) => {
|
|
8
|
-
const bin =
|
|
6
|
+
const bin = builtinBin.find((bin) => bin.isSupported(script));
|
|
9
7
|
if (!bin) {
|
|
10
8
|
console.log('Unsupported script:', script);
|
|
11
9
|
return console.log('You may try "ur exec bin script.ext - --flags"');
|
|
12
10
|
}
|
|
13
|
-
const executionOptions =
|
|
11
|
+
const executionOptions = mapFlagsToOptions(flags, bin);
|
|
14
12
|
bin.start(executionOptions, [script, ...listArs, ...trailingArgs]);
|
|
15
13
|
});
|
|
16
14
|
arg.exec.on(([listArs, trailingArgs], flags) => {
|
|
17
|
-
|
|
15
|
+
Execution.start([...listArs, ...trailingArgs], mapFlagsToOptions(flags));
|
|
18
16
|
});
|
|
19
17
|
arg.list.on(() => {
|
|
20
18
|
console.log('Supported scripts:');
|
|
21
|
-
|
|
19
|
+
builtinBin
|
|
22
20
|
.sort((a, b) => {
|
|
23
21
|
const aName = a.getName();
|
|
24
22
|
const bName = b.getName();
|
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.executionConfig = void 0;
|
|
4
7
|
exports.mapFlagsToOptions = mapFlagsToOptions;
|
|
5
|
-
const noarg_1 = require("noarg");
|
|
8
|
+
const noarg_1 = __importDefault(require("noarg"));
|
|
6
9
|
exports.executionConfig = noarg_1.default.defineConfig({
|
|
7
10
|
flags: {
|
|
11
|
+
reloadKey: noarg_1.default.boolean()
|
|
12
|
+
.aliases('rk')
|
|
13
|
+
.default(true)
|
|
14
|
+
.description("Reload the page when pressing 'Ctrl+R' or 'F5'"),
|
|
15
|
+
watch: noarg_1.default.boolean()
|
|
16
|
+
.aliases('w')
|
|
17
|
+
.default(true)
|
|
18
|
+
.description('Watch for changes'),
|
|
19
|
+
noWatch: noarg_1.default.boolean()
|
|
20
|
+
.default(false)
|
|
21
|
+
.description('Disable `watch` and `reloadKey` features'),
|
|
22
|
+
clear: noarg_1.default.boolean()
|
|
23
|
+
.aliases('c')
|
|
24
|
+
.default(true)
|
|
25
|
+
.description('Clear the console before running the script'),
|
|
26
|
+
delay: noarg_1.default.number()
|
|
27
|
+
.aliases('d')
|
|
28
|
+
.default(100)
|
|
29
|
+
.description('The delay to wait for the watcher to trigger'),
|
|
30
|
+
ext: noarg_1.default.array(noarg_1.default.string())
|
|
31
|
+
.aliases('e')
|
|
32
|
+
.default([])
|
|
33
|
+
.description('Looks for changes only of the given extensions'),
|
|
34
|
+
ignore: noarg_1.default.array(noarg_1.default.string())
|
|
35
|
+
.aliases('ig')
|
|
36
|
+
.default([])
|
|
37
|
+
.description('Ignore the given folders/files'),
|
|
38
|
+
bench: noarg_1.default.boolean()
|
|
39
|
+
.aliases('b')
|
|
40
|
+
.description('Calculate the execution time'),
|
|
41
|
+
benchPrefix: noarg_1.default.string()
|
|
42
|
+
.aliases('bp')
|
|
43
|
+
.minLength(1)
|
|
44
|
+
.description('The prefix to show before the execution time'),
|
|
8
45
|
cwd: noarg_1.default.string()
|
|
9
46
|
.default(process.cwd())
|
|
10
47
|
.description('Current working directory'),
|
|
@@ -17,37 +54,10 @@ exports.executionConfig = noarg_1.default.defineConfig({
|
|
|
17
54
|
time: noarg_1.default.boolean()
|
|
18
55
|
.default(false)
|
|
19
56
|
.description('Show the execution time at the start'),
|
|
20
|
-
bench: noarg_1.default.boolean()
|
|
21
|
-
.default(false)
|
|
22
|
-
.description('Show the execution time'),
|
|
23
|
-
benchPrefix: noarg_1.default.string().description('The prefix for the benchmark to show at the start of the line'),
|
|
24
|
-
clear: noarg_1.default.boolean()
|
|
25
|
-
.default(true)
|
|
26
|
-
.description('Clear the console before running the script')
|
|
27
|
-
.aliases('c'),
|
|
28
|
-
reloadKey: noarg_1.default.boolean()
|
|
29
|
-
.default(true)
|
|
30
|
-
.description("Reload the page when pressing 'Ctrl+R' or 'F5'")
|
|
31
|
-
.aliases('rk'),
|
|
32
|
-
watch: noarg_1.default.boolean()
|
|
33
|
-
.default(true)
|
|
34
|
-
.description('Watch for changes')
|
|
35
|
-
.aliases('w'),
|
|
36
|
-
delay: noarg_1.default.number()
|
|
37
|
-
.default(100)
|
|
38
|
-
.description('The delay to wait for the watcher to trigger')
|
|
39
|
-
.aliases('d'),
|
|
40
|
-
ext: noarg_1.default.array(noarg_1.default.string())
|
|
41
|
-
.default([])
|
|
42
|
-
.description('Looks for changes only of the given extensions')
|
|
43
|
-
.aliases('e'),
|
|
44
|
-
ignore: noarg_1.default.array(noarg_1.default.string())
|
|
45
|
-
.default([])
|
|
46
|
-
.description('Ignore the given folders/files')
|
|
47
|
-
.aliases('ig'),
|
|
48
57
|
env: noarg_1.default.array(noarg_1.default.string())
|
|
49
58
|
.default([])
|
|
50
59
|
.description('Environment variables'),
|
|
60
|
+
// Extra flags
|
|
51
61
|
nodeDev: noarg_1.default.boolean()
|
|
52
62
|
.default(false)
|
|
53
63
|
.description('Set NODE_ENV to "development"'),
|
|
@@ -66,16 +76,17 @@ exports.executionConfig = noarg_1.default.defineConfig({
|
|
|
66
76
|
},
|
|
67
77
|
});
|
|
68
78
|
function mapFlagsToOptions(flags, bin) {
|
|
79
|
+
var _a;
|
|
69
80
|
return {
|
|
70
81
|
cwd: flags.cwd,
|
|
71
82
|
shell: flags.shell,
|
|
72
83
|
showInfo: flags.info,
|
|
73
84
|
showTime: flags.time,
|
|
74
|
-
benchmark: flags.bench,
|
|
85
|
+
benchmark: (_a = flags.bench) !== null && _a !== void 0 ? _a : Boolean(flags.benchPrefix),
|
|
75
86
|
benchmarkPrefix: flags.benchPrefix,
|
|
76
87
|
clearOnReload: flags.clear,
|
|
77
|
-
|
|
78
|
-
watch: flags.watch,
|
|
88
|
+
keystrokeReload: flags.noWatch ? false : flags.reloadKey,
|
|
89
|
+
watch: flags.noWatch ? false : flags.watch,
|
|
79
90
|
watchDelay: flags.delay,
|
|
80
91
|
watchIgnore: flags.ignore,
|
|
81
92
|
watchExtensions: (flags.ext.length ? flags.ext : bin === null || bin === void 0 ? void 0 : bin.getRelatedExts()) || [],
|
|
@@ -1,73 +1,79 @@
|
|
|
1
|
-
import NoArg from
|
|
2
|
-
import type { app } from
|
|
3
|
-
import Executor from
|
|
1
|
+
import NoArg from "noarg";
|
|
2
|
+
import type { app } from "./arg.cjs";
|
|
3
|
+
import Executor from "./builtin-bin/Executor.cjs";
|
|
4
4
|
export declare const executionConfig: {
|
|
5
5
|
readonly flags: {
|
|
6
|
-
readonly
|
|
7
|
-
|
|
8
|
-
default: string;
|
|
9
|
-
description: "Current working directory";
|
|
10
|
-
}>;
|
|
11
|
-
readonly shell: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
12
|
-
required: true;
|
|
13
|
-
default: false;
|
|
14
|
-
description: "Run the script in a shell for more low-level control";
|
|
15
|
-
}>;
|
|
16
|
-
readonly info: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
6
|
+
readonly reloadKey: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
7
|
+
aliases: ["rk"];
|
|
17
8
|
required: true;
|
|
18
|
-
default:
|
|
19
|
-
description: "
|
|
9
|
+
default: true;
|
|
10
|
+
description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
|
|
20
11
|
}>;
|
|
21
|
-
readonly
|
|
12
|
+
readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
13
|
+
aliases: ["w"];
|
|
22
14
|
required: true;
|
|
23
|
-
default:
|
|
24
|
-
description: "
|
|
15
|
+
default: true;
|
|
16
|
+
description: "Watch for changes";
|
|
25
17
|
}>;
|
|
26
|
-
readonly
|
|
18
|
+
readonly noWatch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
27
19
|
required: true;
|
|
28
20
|
default: false;
|
|
29
|
-
description: "
|
|
30
|
-
}>;
|
|
31
|
-
readonly benchPrefix: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
32
|
-
description: "The prefix for the benchmark to show at the start of the line";
|
|
21
|
+
description: "Disable `watch` and `reloadKey` features";
|
|
33
22
|
}>;
|
|
34
23
|
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
35
|
-
|
|
24
|
+
aliases: ["c"];
|
|
36
25
|
required: true;
|
|
37
26
|
default: true;
|
|
38
|
-
|
|
39
|
-
}>;
|
|
40
|
-
readonly reloadKey: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
41
|
-
description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
|
|
42
|
-
required: true;
|
|
43
|
-
default: true;
|
|
44
|
-
aliases: [string];
|
|
45
|
-
}>;
|
|
46
|
-
readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
47
|
-
description: "Watch for changes";
|
|
48
|
-
required: true;
|
|
49
|
-
default: true;
|
|
50
|
-
aliases: [string];
|
|
27
|
+
description: "Clear the console before running the script";
|
|
51
28
|
}>;
|
|
52
29
|
readonly delay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
|
|
53
|
-
|
|
30
|
+
aliases: ["d"];
|
|
54
31
|
required: true;
|
|
55
32
|
default: 100;
|
|
56
|
-
|
|
33
|
+
description: "The delay to wait for the watcher to trigger";
|
|
57
34
|
}>;
|
|
58
35
|
readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
59
|
-
|
|
36
|
+
aliases: ["e"];
|
|
60
37
|
required: true;
|
|
61
38
|
default: never[];
|
|
62
39
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
63
|
-
|
|
40
|
+
description: "Looks for changes only of the given extensions";
|
|
64
41
|
}>;
|
|
65
42
|
readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
66
|
-
|
|
43
|
+
aliases: ["ig"];
|
|
67
44
|
required: true;
|
|
68
45
|
default: never[];
|
|
69
46
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
70
|
-
|
|
47
|
+
description: "Ignore the given folders/files";
|
|
48
|
+
}>;
|
|
49
|
+
readonly bench: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
50
|
+
aliases: ["b"];
|
|
51
|
+
description: "Calculate the execution time";
|
|
52
|
+
}>;
|
|
53
|
+
readonly benchPrefix: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
54
|
+
aliases: ["bp"];
|
|
55
|
+
minLength: 1;
|
|
56
|
+
description: "The prefix to show before the execution time";
|
|
57
|
+
}>;
|
|
58
|
+
readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
59
|
+
required: true;
|
|
60
|
+
default: string;
|
|
61
|
+
description: "Current working directory";
|
|
62
|
+
}>;
|
|
63
|
+
readonly shell: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
64
|
+
required: true;
|
|
65
|
+
default: false;
|
|
66
|
+
description: "Run the script in a shell for more low-level control";
|
|
67
|
+
}>;
|
|
68
|
+
readonly info: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
69
|
+
required: true;
|
|
70
|
+
default: false;
|
|
71
|
+
description: "Show information about the script";
|
|
72
|
+
}>;
|
|
73
|
+
readonly time: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
74
|
+
required: true;
|
|
75
|
+
default: false;
|
|
76
|
+
description: "Show the execution time at the start";
|
|
71
77
|
}>;
|
|
72
78
|
readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
73
79
|
required: true;
|
|
@@ -105,7 +111,7 @@ export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>, b
|
|
|
105
111
|
benchmark: boolean;
|
|
106
112
|
benchmarkPrefix: string | undefined;
|
|
107
113
|
clearOnReload: boolean;
|
|
108
|
-
|
|
114
|
+
keystrokeReload: boolean;
|
|
109
115
|
watch: boolean;
|
|
110
116
|
watchDelay: number;
|
|
111
117
|
watchIgnore: string[];
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import NoArg from "noarg";
|
|
2
|
+
import type { app } from "./arg.mjs";
|
|
3
|
+
import Executor from "./builtin-bin/Executor.mjs";
|
|
4
|
+
export declare const executionConfig: {
|
|
5
|
+
readonly flags: {
|
|
6
|
+
readonly reloadKey: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
7
|
+
aliases: ["rk"];
|
|
8
|
+
required: true;
|
|
9
|
+
default: true;
|
|
10
|
+
description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
|
|
11
|
+
}>;
|
|
12
|
+
readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
13
|
+
aliases: ["w"];
|
|
14
|
+
required: true;
|
|
15
|
+
default: true;
|
|
16
|
+
description: "Watch for changes";
|
|
17
|
+
}>;
|
|
18
|
+
readonly noWatch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
19
|
+
required: true;
|
|
20
|
+
default: false;
|
|
21
|
+
description: "Disable `watch` and `reloadKey` features";
|
|
22
|
+
}>;
|
|
23
|
+
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
24
|
+
aliases: ["c"];
|
|
25
|
+
required: true;
|
|
26
|
+
default: true;
|
|
27
|
+
description: "Clear the console before running the script";
|
|
28
|
+
}>;
|
|
29
|
+
readonly delay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
|
|
30
|
+
aliases: ["d"];
|
|
31
|
+
required: true;
|
|
32
|
+
default: 100;
|
|
33
|
+
description: "The delay to wait for the watcher to trigger";
|
|
34
|
+
}>;
|
|
35
|
+
readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
36
|
+
aliases: ["e"];
|
|
37
|
+
required: true;
|
|
38
|
+
default: never[];
|
|
39
|
+
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
40
|
+
description: "Looks for changes only of the given extensions";
|
|
41
|
+
}>;
|
|
42
|
+
readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
43
|
+
aliases: ["ig"];
|
|
44
|
+
required: true;
|
|
45
|
+
default: never[];
|
|
46
|
+
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
47
|
+
description: "Ignore the given folders/files";
|
|
48
|
+
}>;
|
|
49
|
+
readonly bench: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
50
|
+
aliases: ["b"];
|
|
51
|
+
description: "Calculate the execution time";
|
|
52
|
+
}>;
|
|
53
|
+
readonly benchPrefix: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
54
|
+
aliases: ["bp"];
|
|
55
|
+
minLength: 1;
|
|
56
|
+
description: "The prefix to show before the execution time";
|
|
57
|
+
}>;
|
|
58
|
+
readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
59
|
+
required: true;
|
|
60
|
+
default: string;
|
|
61
|
+
description: "Current working directory";
|
|
62
|
+
}>;
|
|
63
|
+
readonly shell: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
64
|
+
required: true;
|
|
65
|
+
default: false;
|
|
66
|
+
description: "Run the script in a shell for more low-level control";
|
|
67
|
+
}>;
|
|
68
|
+
readonly info: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
69
|
+
required: true;
|
|
70
|
+
default: false;
|
|
71
|
+
description: "Show information about the script";
|
|
72
|
+
}>;
|
|
73
|
+
readonly time: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
74
|
+
required: true;
|
|
75
|
+
default: false;
|
|
76
|
+
description: "Show the execution time at the start";
|
|
77
|
+
}>;
|
|
78
|
+
readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
79
|
+
required: true;
|
|
80
|
+
default: never[];
|
|
81
|
+
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
82
|
+
description: "Environment variables";
|
|
83
|
+
}>;
|
|
84
|
+
readonly nodeDev: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
85
|
+
required: true;
|
|
86
|
+
default: false;
|
|
87
|
+
description: "Set NODE_ENV to \"development\"";
|
|
88
|
+
}>;
|
|
89
|
+
readonly tsn: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
90
|
+
required: true;
|
|
91
|
+
default: false;
|
|
92
|
+
description: "Run the script with ts-node";
|
|
93
|
+
}>;
|
|
94
|
+
};
|
|
95
|
+
readonly listArgument: {
|
|
96
|
+
readonly name: "args for script";
|
|
97
|
+
readonly description: "The arguments to pass to the script";
|
|
98
|
+
readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
99
|
+
};
|
|
100
|
+
readonly trailingArguments: "--";
|
|
101
|
+
readonly customRenderHelp: {
|
|
102
|
+
readonly helpUsageTrailingArgsLabel: "...[args/flags for script]";
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export type ExecuteOptions = ReturnType<typeof mapFlagsToOptions>;
|
|
106
|
+
export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>, bin?: Executor): {
|
|
107
|
+
cwd: string;
|
|
108
|
+
shell: boolean;
|
|
109
|
+
showInfo: boolean;
|
|
110
|
+
showTime: boolean;
|
|
111
|
+
benchmark: boolean;
|
|
112
|
+
benchmarkPrefix: string | undefined;
|
|
113
|
+
clearOnReload: boolean;
|
|
114
|
+
keystrokeReload: boolean;
|
|
115
|
+
watch: boolean;
|
|
116
|
+
watchDelay: number;
|
|
117
|
+
watchIgnore: string[];
|
|
118
|
+
watchExtensions: string[];
|
|
119
|
+
tsNode: boolean;
|
|
120
|
+
env: NodeJS.ProcessEnv;
|
|
121
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import NoArg from "noarg";
|
|
2
|
+
export const executionConfig = NoArg.defineConfig({
|
|
3
|
+
flags: {
|
|
4
|
+
reloadKey: NoArg.boolean()
|
|
5
|
+
.aliases('rk')
|
|
6
|
+
.default(true)
|
|
7
|
+
.description("Reload the page when pressing 'Ctrl+R' or 'F5'"),
|
|
8
|
+
watch: NoArg.boolean()
|
|
9
|
+
.aliases('w')
|
|
10
|
+
.default(true)
|
|
11
|
+
.description('Watch for changes'),
|
|
12
|
+
noWatch: NoArg.boolean()
|
|
13
|
+
.default(false)
|
|
14
|
+
.description('Disable `watch` and `reloadKey` features'),
|
|
15
|
+
clear: NoArg.boolean()
|
|
16
|
+
.aliases('c')
|
|
17
|
+
.default(true)
|
|
18
|
+
.description('Clear the console before running the script'),
|
|
19
|
+
delay: NoArg.number()
|
|
20
|
+
.aliases('d')
|
|
21
|
+
.default(100)
|
|
22
|
+
.description('The delay to wait for the watcher to trigger'),
|
|
23
|
+
ext: NoArg.array(NoArg.string())
|
|
24
|
+
.aliases('e')
|
|
25
|
+
.default([])
|
|
26
|
+
.description('Looks for changes only of the given extensions'),
|
|
27
|
+
ignore: NoArg.array(NoArg.string())
|
|
28
|
+
.aliases('ig')
|
|
29
|
+
.default([])
|
|
30
|
+
.description('Ignore the given folders/files'),
|
|
31
|
+
bench: NoArg.boolean()
|
|
32
|
+
.aliases('b')
|
|
33
|
+
.description('Calculate the execution time'),
|
|
34
|
+
benchPrefix: NoArg.string()
|
|
35
|
+
.aliases('bp')
|
|
36
|
+
.minLength(1)
|
|
37
|
+
.description('The prefix to show before the execution time'),
|
|
38
|
+
cwd: NoArg.string()
|
|
39
|
+
.default(process.cwd())
|
|
40
|
+
.description('Current working directory'),
|
|
41
|
+
shell: NoArg.boolean()
|
|
42
|
+
.default(false)
|
|
43
|
+
.description('Run the script in a shell for more low-level control'),
|
|
44
|
+
info: NoArg.boolean()
|
|
45
|
+
.default(false)
|
|
46
|
+
.description('Show information about the script'),
|
|
47
|
+
time: NoArg.boolean()
|
|
48
|
+
.default(false)
|
|
49
|
+
.description('Show the execution time at the start'),
|
|
50
|
+
env: NoArg.array(NoArg.string())
|
|
51
|
+
.default([])
|
|
52
|
+
.description('Environment variables'),
|
|
53
|
+
// Extra flags
|
|
54
|
+
nodeDev: NoArg.boolean()
|
|
55
|
+
.default(false)
|
|
56
|
+
.description('Set NODE_ENV to "development"'),
|
|
57
|
+
tsn: NoArg.boolean()
|
|
58
|
+
.default(false)
|
|
59
|
+
.description('Run the script with ts-node'),
|
|
60
|
+
},
|
|
61
|
+
listArgument: {
|
|
62
|
+
name: 'args for script',
|
|
63
|
+
description: 'The arguments to pass to the script',
|
|
64
|
+
type: NoArg.string(),
|
|
65
|
+
},
|
|
66
|
+
trailingArguments: '--',
|
|
67
|
+
customRenderHelp: {
|
|
68
|
+
helpUsageTrailingArgsLabel: '...[args/flags for script]',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
export function mapFlagsToOptions(flags, bin) {
|
|
72
|
+
var _a;
|
|
73
|
+
return {
|
|
74
|
+
cwd: flags.cwd,
|
|
75
|
+
shell: flags.shell,
|
|
76
|
+
showInfo: flags.info,
|
|
77
|
+
showTime: flags.time,
|
|
78
|
+
benchmark: (_a = flags.bench) !== null && _a !== void 0 ? _a : Boolean(flags.benchPrefix),
|
|
79
|
+
benchmarkPrefix: flags.benchPrefix,
|
|
80
|
+
clearOnReload: flags.clear,
|
|
81
|
+
keystrokeReload: flags.noWatch ? false : flags.reloadKey,
|
|
82
|
+
watch: flags.noWatch ? false : flags.watch,
|
|
83
|
+
watchDelay: flags.delay,
|
|
84
|
+
watchIgnore: flags.ignore,
|
|
85
|
+
watchExtensions: (flags.ext.length ? flags.ext : bin === null || bin === void 0 ? void 0 : bin.getRelatedExts()) || [],
|
|
86
|
+
tsNode: flags['tsn'],
|
|
87
|
+
env: Object.assign(Object.assign({}, flags.env.reduce((acc, env) => {
|
|
88
|
+
const [key, value] = env.split('=');
|
|
89
|
+
acc[key] = value;
|
|
90
|
+
return acc;
|
|
91
|
+
}, {})), (flags.nodeDev ? { NODE_ENV: 'development' } : {})),
|
|
92
|
+
};
|
|
93
|
+
}
|