uni-run 1.0.4 → 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.
Files changed (61) hide show
  1. package/README.md +122 -0
  2. package/dist/app.cjs +60 -0
  3. package/dist/app.d.mts +1 -0
  4. package/dist/{index.js → app.mjs} +8 -10
  5. package/dist/{arg-helper.js → arg-helper.cjs} +44 -31
  6. package/dist/{arg-helper.d.ts → arg-helper.d.cts} +52 -42
  7. package/dist/arg-helper.d.mts +121 -0
  8. package/dist/arg-helper.mjs +93 -0
  9. package/dist/{arg.js → arg.cjs} +5 -2
  10. package/dist/{arg.d.ts → arg.d.cts} +95 -77
  11. package/dist/arg.d.mts +243 -0
  12. package/dist/arg.mjs +9 -0
  13. package/dist/{bin.js → bin.cjs} +2 -2
  14. package/dist/{bin.d.ts → bin.d.cts} +1 -1
  15. package/dist/bin.d.mts +2 -0
  16. package/dist/bin.mjs +4 -0
  17. package/dist/builtin-bin/{Executor.js → Executor.cjs} +5 -2
  18. package/dist/builtin-bin/{Executor.d.ts → Executor.d.cts} +1 -1
  19. package/dist/builtin-bin/Executor.d.mts +21 -0
  20. package/dist/builtin-bin/Executor.mjs +61 -0
  21. package/dist/builtin-bin/{index.js → index.cjs} +4 -1
  22. package/dist/builtin-bin/{index.d.ts → index.d.cts} +1 -1
  23. package/dist/builtin-bin/index.d.mts +3 -0
  24. package/dist/builtin-bin/index.mjs +94 -0
  25. package/dist/execution/gitignore.cjs +40 -0
  26. package/dist/execution/gitignore.d.mts +1 -0
  27. package/dist/execution/gitignore.mjs +11 -0
  28. package/dist/execution/{index.js → index.cjs} +47 -8
  29. package/dist/execution/{index.d.ts → index.d.cts} +3 -1
  30. package/dist/execution/index.d.mts +15 -0
  31. package/dist/execution/index.mjs +103 -0
  32. package/dist/execution/kill-process.cjs +50 -0
  33. package/dist/execution/{kill-process.d.ts → kill-process.d.cts} +1 -1
  34. package/dist/execution/kill-process.d.mts +2 -0
  35. package/dist/execution/{kill-process.js → kill-process.mjs} +4 -7
  36. package/dist/execution/watcher.cjs +64 -0
  37. package/dist/execution/watcher.d.mts +6 -0
  38. package/dist/execution/{watcher.js → watcher.mjs} +8 -11
  39. package/dist/index.cjs +19 -0
  40. package/dist/index.d.cts +8 -0
  41. package/dist/index.d.mts +8 -0
  42. package/dist/index.mjs +13 -0
  43. package/dist/lib/colors.cjs +32 -0
  44. package/dist/lib/colors.d.cts +3 -0
  45. package/dist/lib/colors.d.mts +3 -0
  46. package/dist/lib/colors.mjs +4 -0
  47. package/dist/lib/currentModule.cjs +19 -0
  48. package/dist/lib/currentModule.d.cts +5 -0
  49. package/dist/lib/currentModule.d.mts +5 -0
  50. package/dist/lib/currentModule.mjs +17 -0
  51. package/dist/utils/debounce.d.mts +1 -0
  52. package/dist/utils/debounce.mjs +7 -0
  53. package/package.json +14 -10
  54. package/dist/execution/gitignore.js +0 -14
  55. package/dist/lib/colors.d.ts +0 -2
  56. package/dist/lib/colors.js +0 -4
  57. /package/dist/{index.d.ts → app.d.cts} +0 -0
  58. /package/dist/execution/{gitignore.d.ts → gitignore.d.cts} +0 -0
  59. /package/dist/execution/{watcher.d.ts → watcher.d.cts} +0 -0
  60. /package/dist/utils/{debounce.js → debounce.cjs} +0 -0
  61. /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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const arg = require("./arg");
4
- const execution_1 = require("./execution");
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 = builtin_bin_1.default.find((bin) => bin.isSupported(script));
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 = (0, arg_helper_1.mapFlagsToOptions)(flags, bin);
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
- execution_1.default.start([...listArs, ...trailingArgs], (0, arg_helper_1.mapFlagsToOptions)(flags));
15
+ Execution.start([...listArs, ...trailingArgs], mapFlagsToOptions(flags));
18
16
  });
19
17
  arg.list.on(() => {
20
18
  console.log('Supported scripts:');
21
- builtin_bin_1.default
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,36 +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
- clear: noarg_1.default.boolean()
24
- .default(true)
25
- .description('Clear the console before running the script')
26
- .aliases('c'),
27
- reloadKey: noarg_1.default.boolean()
28
- .default(true)
29
- .description("Reload the page when pressing 'Ctrl+R' or 'F5'")
30
- .aliases('rk'),
31
- watch: noarg_1.default.boolean()
32
- .default(true)
33
- .description('Watch for changes')
34
- .aliases('w'),
35
- delay: noarg_1.default.number()
36
- .default(100)
37
- .description('The delay to wait for the watcher to trigger')
38
- .aliases('d'),
39
- ext: noarg_1.default.array(noarg_1.default.string())
40
- .default([])
41
- .description('Looks for changes only of the given extensions')
42
- .aliases('e'),
43
- ignore: noarg_1.default.array(noarg_1.default.string())
44
- .default([])
45
- .description('Ignore the given folders/files')
46
- .aliases('ig'),
47
57
  env: noarg_1.default.array(noarg_1.default.string())
48
58
  .default([])
49
59
  .description('Environment variables'),
60
+ // Extra flags
50
61
  nodeDev: noarg_1.default.boolean()
51
62
  .default(false)
52
63
  .description('Set NODE_ENV to "development"'),
@@ -65,15 +76,17 @@ exports.executionConfig = noarg_1.default.defineConfig({
65
76
  },
66
77
  });
67
78
  function mapFlagsToOptions(flags, bin) {
79
+ var _a;
68
80
  return {
69
81
  cwd: flags.cwd,
70
82
  shell: flags.shell,
71
83
  showInfo: flags.info,
72
84
  showTime: flags.time,
73
- benchmark: flags.bench,
85
+ benchmark: (_a = flags.bench) !== null && _a !== void 0 ? _a : Boolean(flags.benchPrefix),
86
+ benchmarkPrefix: flags.benchPrefix,
74
87
  clearOnReload: flags.clear,
75
- readlineReload: flags.reloadKey,
76
- watch: flags.watch,
88
+ keystrokeReload: flags.noWatch ? false : flags.reloadKey,
89
+ watch: flags.noWatch ? false : flags.watch,
77
90
  watchDelay: flags.delay,
78
91
  watchIgnore: flags.ignore,
79
92
  watchExtensions: (flags.ext.length ? flags.ext : bin === null || bin === void 0 ? void 0 : bin.getRelatedExts()) || [],
@@ -1,70 +1,79 @@
1
- import NoArg from 'noarg';
2
- import type { app } from './arg';
3
- import Executor from './builtin-bin/Executor';
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 cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
7
- required: true;
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: false;
19
- description: "Show information about the script";
9
+ default: true;
10
+ description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
20
11
  }>;
21
- readonly time: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
12
+ readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
13
+ aliases: ["w"];
22
14
  required: true;
23
- default: false;
24
- description: "Show the execution time at the start";
15
+ default: true;
16
+ description: "Watch for changes";
25
17
  }>;
26
- readonly bench: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
18
+ readonly noWatch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
27
19
  required: true;
28
20
  default: false;
29
- description: "Show the execution time";
21
+ description: "Disable `watch` and `reloadKey` features";
30
22
  }>;
31
23
  readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
32
- description: "Clear the console before running the script";
33
- required: true;
34
- default: true;
35
- aliases: [string];
36
- }>;
37
- readonly reloadKey: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
38
- description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
39
- required: true;
40
- default: true;
41
- aliases: [string];
42
- }>;
43
- readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
44
- description: "Watch for changes";
24
+ aliases: ["c"];
45
25
  required: true;
46
26
  default: true;
47
- aliases: [string];
27
+ description: "Clear the console before running the script";
48
28
  }>;
49
29
  readonly delay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
50
- description: "The delay to wait for the watcher to trigger";
30
+ aliases: ["d"];
51
31
  required: true;
52
32
  default: 100;
53
- aliases: [string];
33
+ description: "The delay to wait for the watcher to trigger";
54
34
  }>;
55
35
  readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
56
- description: "Looks for changes only of the given extensions";
36
+ aliases: ["e"];
57
37
  required: true;
58
38
  default: never[];
59
39
  schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
60
- aliases: [string];
40
+ description: "Looks for changes only of the given extensions";
61
41
  }>;
62
42
  readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
63
- description: "Ignore the given folders/files";
43
+ aliases: ["ig"];
64
44
  required: true;
65
45
  default: never[];
66
46
  schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
67
- aliases: [string];
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";
68
77
  }>;
69
78
  readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
70
79
  required: true;
@@ -100,8 +109,9 @@ export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>, b
100
109
  showInfo: boolean;
101
110
  showTime: boolean;
102
111
  benchmark: boolean;
112
+ benchmarkPrefix: string | undefined;
103
113
  clearOnReload: boolean;
104
- readlineReload: boolean;
114
+ keystrokeReload: boolean;
105
115
  watch: boolean;
106
116
  watchDelay: number;
107
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
+ }