uni-run 1.0.13 → 1.1.1

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 +84 -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
@@ -1,102 +0,0 @@
1
- import Executor from "./Executor.mjs";
2
- export default [
3
- new Executor('Node.js', {
4
- extensions: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
5
- checkInstallation: ['node', '--version'],
6
- installMessage: 'Please install Node.js from https://nodejs.org',
7
- run(args) {
8
- return ['node', ...args];
9
- },
10
- }),
11
- new Executor('TypeScript', {
12
- extensions: ['ts', 'tsx', 'cts', 'ctsx', 'mts', 'mtsx'],
13
- watchExtensions: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
14
- checkInstallation(options) {
15
- return options.tsNode ? ['ts-node', '--version'] : ['tsx', '--version'];
16
- },
17
- installCommands(options) {
18
- return options.tsNode
19
- ? ['npm install -g ts-node']
20
- : ['npm install -g tsx'];
21
- },
22
- installMessage: 'Please install tsx. More: https://tsx.is',
23
- run(args, options) {
24
- return options.tsNode ? ['ts-node', ...args] : ['tsx', ...args];
25
- },
26
- }),
27
- new Executor('Python', {
28
- extensions: ['py'],
29
- checkInstallation: ['python', '--version'],
30
- installMessage: 'Please install Python from https://www.python.org',
31
- run(args) {
32
- return ['python', ...args];
33
- },
34
- }),
35
- new Executor('Java - Oracle', {
36
- extensions: ['java'],
37
- checkInstallation: ['java', '--version'],
38
- installMessage: 'Please install Java from https://www.oracle.com/java',
39
- run(args) {
40
- return ['java', ...args];
41
- },
42
- }),
43
- new Executor('Powershell', {
44
- extensions: ['ps1'],
45
- checkInstallation: ['powershell', '-command', 'echo ok'],
46
- installMessage: 'Please install Powershell from https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell',
47
- run(args) {
48
- return ['powershell', '-File', ...args];
49
- },
50
- }),
51
- new Executor('Command Prompt', {
52
- extensions: ['cmd', 'bat'],
53
- checkInstallation: ['cmd', '/c', 'echo ok'],
54
- installMessage: 'Please install Command Prompt from Windows',
55
- run(args) {
56
- return ['cmd', '/c', ...args];
57
- },
58
- }),
59
- new Executor('Shell', {
60
- extensions: ['sh'],
61
- checkInstallation: ['bash', '--version'],
62
- installMessage: 'Please install Bash from https://www.gnu.org/software/bash',
63
- run(args) {
64
- return ['bash', ...args];
65
- },
66
- }),
67
- new Executor('Fish Shell', {
68
- extensions: ['fish'],
69
- checkInstallation: ['fish', '--version'],
70
- installMessage: 'Please install Fish from https://fishshell.com',
71
- run(args) {
72
- return ['fish', ...args];
73
- },
74
- }),
75
- new Executor('Lua', {
76
- extensions: ['lua'],
77
- checkInstallation: ['lua', '-v'],
78
- installMessage: 'Please install Lua from https://www.lua.org',
79
- run(args) {
80
- return ['lua', ...args];
81
- },
82
- }),
83
- new Executor('SASS (CSS)', {
84
- extensions: ['sass', 'scss'],
85
- checkInstallation: ['sass', '--version'],
86
- installCommands: ['npm install -g sass'],
87
- installMessage: 'Please install SASS from https://sass-lang.com',
88
- run(args) {
89
- return ['sass', ...args];
90
- },
91
- }),
92
- new Executor('HTML Server', {
93
- extensions: ['html', 'htm'],
94
- watchExtensions: ['css', 'js', 'javascript', 'json'],
95
- checkInstallation: ['http-server', '--version'],
96
- installCommands: ['npm install -g http-server'],
97
- installMessage: 'Please install http-server from https://www.npmjs.com/package/http-server',
98
- run(args) {
99
- return ['http-server', ...args];
100
- },
101
- }),
102
- ];
@@ -1 +0,0 @@
1
- export default function (baseDir: string, extraIgnore?: string[]): import("ignore").Ignore;
@@ -1,11 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import ignore from "ignore";
4
- export default function (baseDir, extraIgnore = []) {
5
- const gitignorePath = path.resolve(path.join(baseDir, '.gitignore'));
6
- const ig = ignore({ ignorecase: true }).add(extraIgnore);
7
- if (fs.existsSync(gitignorePath)) {
8
- return ig.add(fs.readFileSync(gitignorePath).toString());
9
- }
10
- return ig;
11
- }
@@ -1,17 +0,0 @@
1
- import { ExecuteOptions } from "../arg-helper.cjs";
2
- export default class Execution {
3
- private command;
4
- private args;
5
- private options;
6
- private child;
7
- private benchMarkText;
8
- private isBenchmarkRunning;
9
- private isExecutionExecutedAnyTime;
10
- static start([command, ...args]: string[], options: ExecuteOptions): Execution;
11
- constructor(command: string, args: string[], options: ExecuteOptions);
12
- private setup;
13
- private startProcess;
14
- private killProcess;
15
- private clearBeforeStart;
16
- private renderInfoLogs;
17
- }
@@ -1,127 +0,0 @@
1
- import { spawn } from "cross-spawn";
2
- import * as readline from "readline";
3
- import watcher from "./watcher.mjs";
4
- import colors from "../lib/colors.mjs";
5
- import killProcess from "./kill-process.mjs";
6
- export default class Execution {
7
- static start([command, ...args], options) {
8
- return new Execution(command, args, options);
9
- }
10
- constructor(command, args, options) {
11
- this.command = command;
12
- this.args = args;
13
- this.options = options;
14
- this.child = null;
15
- this.benchMarkText = colors.dim.green('# Execution time');
16
- this.isBenchmarkRunning = false;
17
- this.isExecutionExecutedAnyTime = false;
18
- this.setup();
19
- this.startProcess();
20
- }
21
- setup() {
22
- var _a, _b;
23
- if (this.options.benchmarkPrefix) {
24
- this.benchMarkText =
25
- colors.bold(this.options.benchmarkPrefix) + ' ' + this.benchMarkText;
26
- }
27
- if (this.options.keystrokeReload) {
28
- readline.emitKeypressEvents(process.stdin);
29
- if (!this.options.stdinSafeMode) {
30
- (_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
31
- }
32
- process.stdin.on('keypress', (_, key) => {
33
- if (key.name === 'f5' || (key.ctrl && key.name === 'r')) {
34
- return this.startProcess();
35
- }
36
- if (key.ctrl && key.name === 'c') {
37
- this.killProcess();
38
- process.exit(0);
39
- }
40
- });
41
- }
42
- if (this.options.watch) {
43
- watcher(this.options.cwd, this.options.watchFocus, () => this.startProcess(), {
44
- ignore: this.options.watchIgnore,
45
- debounceDelay: this.options.watchDelay,
46
- extensions: new Set(this.options.watchExtensions),
47
- });
48
- }
49
- }
50
- startProcess() {
51
- this.killProcess();
52
- this.clearBeforeStart();
53
- this.renderInfoLogs();
54
- this.isExecutionExecutedAnyTime = true;
55
- this.child = spawn(this.command, this.args, {
56
- argv0: this.command,
57
- cwd: this.options.cwd,
58
- shell: this.options.shell,
59
- env: Object.assign(Object.assign({}, process.env), this.options.env),
60
- stdio: this.options.silent ? 'ignore' : 'inherit',
61
- });
62
- this.child.on('exit', (code) => {
63
- if (code && code > 0) {
64
- console.log(colors.red(`Process exited with code: ${colors.yellow(String(code))}`));
65
- }
66
- if (this.isBenchmarkRunning) {
67
- console.timeEnd(this.benchMarkText);
68
- this.isBenchmarkRunning = false;
69
- }
70
- if (this.options.keystrokeReload) {
71
- console.log(colors.blue.dim(`> Press ${colors.yellow('F5')} or ${colors.yellow('^R')} to reload...`));
72
- }
73
- });
74
- }
75
- killProcess() {
76
- if (!this.child)
77
- return;
78
- this.child.removeAllListeners();
79
- const isKilled = killProcess(this.child);
80
- if (!isKilled) {
81
- console.error(colors.bgRed('ERROR:'), colors.red('Failed to kill the previous process'));
82
- }
83
- this.child = null;
84
- }
85
- clearBeforeStart() {
86
- if (this.options.clearOnReload) {
87
- process.stdout.write('\x1Bc');
88
- process.stdout.cursorTo(0, 0);
89
- process.stdout.clearScreenDown();
90
- console.clear();
91
- }
92
- }
93
- renderInfoLogs() {
94
- if (this.options.showInfo && !this.isExecutionExecutedAnyTime) {
95
- if (this.options.watch) {
96
- console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching for extensions:'), colors.dim(this.options.watchExtensions
97
- .map((ext) => colors.reset(ext))
98
- .join(', ') || colors.yellow('*')));
99
- }
100
- if (this.options.watchFocus.length) {
101
- console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching target:'), colors.dim(this.options.watchFocus
102
- .map((ext) => colors.reset(ext))
103
- .join(', ') || colors.yellow('*')));
104
- }
105
- if (this.options.watchIgnore.length) {
106
- console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching ignore:'), colors.dim(this.options.watchIgnore
107
- .map((ext) => colors.reset(ext))
108
- .join(', ') || colors.yellow('*')));
109
- }
110
- if (this.options.shell) {
111
- console.log(colors.dim.bgGreen('INFO:'), colors.green('SHELL mode enabled'));
112
- }
113
- }
114
- if (this.options.showTime) {
115
- console.log(colors.dim.bgGreen('TIME:'), colors.green(new Date().toLocaleString()));
116
- }
117
- if (this.options.benchmark) {
118
- if (this.isBenchmarkRunning) {
119
- console.timeEnd(this.benchMarkText);
120
- }
121
- else {
122
- this.isBenchmarkRunning = true;
123
- }
124
- console.time(this.benchMarkText);
125
- }
126
- }
127
- }
@@ -1,2 +0,0 @@
1
- import { ChildProcess } from "child_process";
2
- export default function (child: ChildProcess): boolean;
@@ -1,24 +0,0 @@
1
- import * as os from "os";
2
- import { execSync } from "child_process";
3
- export default function (child) {
4
- if (!child.pid)
5
- return true;
6
- child.removeAllListeners();
7
- const isWindows = os.platform() === 'win32';
8
- try {
9
- if (isWindows) {
10
- execSync(`taskkill /pid ${child.pid} /T /F`, { stdio: 'ignore' });
11
- }
12
- else {
13
- process.kill(-child.pid, 'SIGKILL');
14
- }
15
- }
16
- catch (_a) { }
17
- try {
18
- process.kill(child.pid, 0);
19
- return false;
20
- }
21
- catch (error) {
22
- return true;
23
- }
24
- }
@@ -1,6 +0,0 @@
1
- export type WatcherOptions = {
2
- ignore: string[];
3
- extensions: Set<string>;
4
- debounceDelay: number;
5
- };
6
- export default function (cwd: string, targets: string | string[], callback: () => void, options: WatcherOptions): void;
@@ -1,31 +0,0 @@
1
- import * as path from "path";
2
- import gitignore from "./gitignore.mjs";
3
- import * as chokidar from "chokidar";
4
- import { createDebounce } from "../utils/debounce.mjs";
5
- export default function (cwd, targets, callback, options) {
6
- const ig = gitignore(cwd, options.ignore);
7
- const debounce = createDebounce(options.debounceDelay);
8
- const watcher = chokidar.watch(targets, {
9
- ignored: (filePath) => {
10
- for (const target of targets) {
11
- const relativePath = path.relative(target, filePath);
12
- if (!relativePath)
13
- return false;
14
- if (ig.ignores(relativePath))
15
- return true;
16
- if (options.extensions.size) {
17
- const ext = path.extname(relativePath).slice(1);
18
- if (ext && !options.extensions.has(ext))
19
- return true;
20
- }
21
- }
22
- return false;
23
- },
24
- interval: options.debounceDelay / 2,
25
- ignoreInitial: true,
26
- persistent: true,
27
- });
28
- watcher.on('add', () => debounce(() => callback()));
29
- watcher.on('change', () => debounce(() => callback()));
30
- watcher.on('unlink', () => debounce(() => callback()));
31
- }
package/dist/index.cjs DELETED
@@ -1,19 +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.Executor = void 0;
7
- require("./app.cjs");
8
- const arg_1 = require("./arg.cjs");
9
- const builtin_bin_1 = __importDefault(require("./builtin-bin/index.cjs"));
10
- const Executor_1 = __importDefault(require("./builtin-bin/Executor.cjs"));
11
- exports.Executor = Executor_1.default;
12
- exports.default = {
13
- addBin(bin) {
14
- builtin_bin_1.default.push(bin);
15
- },
16
- start(args) {
17
- arg_1.app.start(args);
18
- },
19
- };
package/dist/index.d.cts DELETED
@@ -1,8 +0,0 @@
1
- import "./app.cjs";
2
- import Executor from "./builtin-bin/Executor.cjs";
3
- export { Executor };
4
- declare const _default: {
5
- addBin(bin: Executor): void;
6
- start(args?: string[]): void;
7
- };
8
- export default _default;
package/dist/index.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import "./app.mjs";
2
- import Executor from "./builtin-bin/Executor.mjs";
3
- export { Executor };
4
- declare const _default: {
5
- addBin(bin: Executor): void;
6
- start(args?: string[]): void;
7
- };
8
- export default _default;
package/dist/index.mjs DELETED
@@ -1,13 +0,0 @@
1
- import "./app.mjs";
2
- import { app } from "./arg.mjs";
3
- import builtinBin from "./builtin-bin/index.mjs";
4
- import Executor from "./builtin-bin/Executor.mjs";
5
- export { Executor };
6
- export default {
7
- addBin(bin) {
8
- builtinBin.push(bin);
9
- },
10
- start(args) {
11
- app.start(args);
12
- },
13
- };
@@ -1,3 +0,0 @@
1
- import mjs from "ansi-colors";
2
- declare const _default: typeof mjs;
3
- export default _default;
@@ -1,4 +0,0 @@
1
- import mjs from "ansi-colors";
2
- import * as cjs from "ansi-colors";
3
- import currentModule from "./currentModule.mjs";
4
- export default currentModule.isCJS ? cjs : mjs;
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- isCJS: boolean;
3
- isESM: boolean;
4
- };
5
- export default _default;
@@ -1,17 +0,0 @@
1
- // @ts-nocheck
2
- let currentModule;
3
- try {
4
- currentModule = module;
5
- currentModule = exports;
6
- currentModule = 'cjs';
7
- }
8
- catch (_a) {
9
- currentModule = 'mjs';
10
- }
11
- if (!currentModule) {
12
- throw new Error('Unkown module System');
13
- }
14
- export default {
15
- isCJS: currentModule === 'cjs',
16
- isESM: currentModule === 'mjs',
17
- };
@@ -1 +0,0 @@
1
- export declare function createDebounce(delay: number): (fn: () => void) => void;
@@ -1,7 +0,0 @@
1
- export function createDebounce(delay) {
2
- let debounceTimeout;
3
- return function (fn) {
4
- clearTimeout(debounceTimeout);
5
- debounceTimeout = setTimeout(() => fn(), delay);
6
- };
7
- }
File without changes
File without changes
File without changes