uni-run 1.0.5 → 1.0.7
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} +49 -33
- package/dist/{arg-helper.d.ts → arg-helper.d.cts} +60 -46
- package/dist/arg-helper.d.mts +129 -0
- package/dist/arg-helper.mjs +98 -0
- package/dist/{arg.js → arg.cjs} +5 -2
- package/dist/{arg.d.ts → arg.d.cts} +109 -83
- package/dist/arg.d.mts +257 -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} +37 -9
- package/dist/execution/{index.d.ts → index.d.cts} +1 -1
- package/dist/execution/index.d.mts +15 -0
- package/dist/execution/index.mjs +105 -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 +60 -0
- package/dist/execution/watcher.d.cts +6 -0
- package/dist/execution/watcher.d.mts +6 -0
- package/dist/execution/watcher.mjs +31 -0
- 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 +11 -8
- package/dist/execution/gitignore.js +0 -14
- package/dist/execution/watcher.d.ts +0 -6
- package/dist/execution/watcher.js +0 -38
- 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/utils/{debounce.js → debounce.cjs} +0 -0
- /package/dist/utils/{debounce.d.ts → debounce.d.cts} +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
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
|
-
const execution_1 = require("../execution");
|
|
4
|
-
const confirm_1 = require("@inquirer/confirm");
|
|
6
|
+
const execution_1 = __importDefault(require("../execution/index.cjs"));
|
|
7
|
+
const confirm_1 = __importDefault(require("@inquirer/confirm"));
|
|
5
8
|
const cross_spawn_1 = require("cross-spawn");
|
|
6
9
|
class Executor {
|
|
7
10
|
constructor(name, config) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExecuteOptions } from "../arg-helper.mjs";
|
|
2
|
+
type BinConfig = {
|
|
3
|
+
extensions: string[];
|
|
4
|
+
watchExtensions?: string[];
|
|
5
|
+
run: (args: string[], options: ExecuteOptions) => string[];
|
|
6
|
+
installMessage?: string;
|
|
7
|
+
installCommands?: string[] | ((options: ExecuteOptions) => string[]);
|
|
8
|
+
checkInstallation?: string[] | ((options: ExecuteOptions) => string[]);
|
|
9
|
+
};
|
|
10
|
+
export default class Executor {
|
|
11
|
+
private name;
|
|
12
|
+
private config;
|
|
13
|
+
constructor(name: string, config: BinConfig);
|
|
14
|
+
getName(): string;
|
|
15
|
+
getRelatedExts(): string[];
|
|
16
|
+
start(options: ExecuteOptions, args: string[]): void;
|
|
17
|
+
isSupported(script: string): boolean;
|
|
18
|
+
private isInstalled;
|
|
19
|
+
private renderHowToInstall;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Execution from "../execution/index.mjs";
|
|
2
|
+
import confirm from "@inquirer/confirm";
|
|
3
|
+
import { sync as spawnSync } from "cross-spawn";
|
|
4
|
+
export default class Executor {
|
|
5
|
+
constructor(name, config) {
|
|
6
|
+
var _a;
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.config = config;
|
|
9
|
+
(_a = this.config.watchExtensions) === null || _a === void 0 ? void 0 : _a.push(...this.config.extensions);
|
|
10
|
+
}
|
|
11
|
+
getName() {
|
|
12
|
+
return this.name;
|
|
13
|
+
}
|
|
14
|
+
getRelatedExts() {
|
|
15
|
+
var _a;
|
|
16
|
+
return [...this.config.extensions, ...((_a = this.config.watchExtensions) !== null && _a !== void 0 ? _a : [])];
|
|
17
|
+
}
|
|
18
|
+
start(options, args) {
|
|
19
|
+
if (!this.isInstalled(options)) {
|
|
20
|
+
return this.renderHowToInstall(options);
|
|
21
|
+
}
|
|
22
|
+
Execution.start(this.config.run(args, options), options);
|
|
23
|
+
}
|
|
24
|
+
isSupported(script) {
|
|
25
|
+
return this.config.extensions.includes(script.split('.').pop() || '');
|
|
26
|
+
}
|
|
27
|
+
isInstalled(options) {
|
|
28
|
+
if (!this.config.checkInstallation)
|
|
29
|
+
return true;
|
|
30
|
+
const [command, ...args] = typeof this.config.checkInstallation === 'function'
|
|
31
|
+
? this.config.checkInstallation(options)
|
|
32
|
+
: this.config.checkInstallation || [];
|
|
33
|
+
const result = spawnSync(command, args, {
|
|
34
|
+
stdio: 'ignore',
|
|
35
|
+
});
|
|
36
|
+
if (result.status === 1)
|
|
37
|
+
return false;
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
renderHowToInstall(options) {
|
|
41
|
+
console.error(`${this.name} is not installed.`);
|
|
42
|
+
if (this.config.installMessage) {
|
|
43
|
+
console.log('How to install:');
|
|
44
|
+
console.log(this.config.installMessage);
|
|
45
|
+
}
|
|
46
|
+
const commands = typeof this.config.installCommands === 'function'
|
|
47
|
+
? this.config.installCommands(options)
|
|
48
|
+
: this.config.installCommands;
|
|
49
|
+
if (!commands || !commands.length)
|
|
50
|
+
return;
|
|
51
|
+
confirm({ message: 'Do you want to install it?' }).then((ans) => {
|
|
52
|
+
if (!ans)
|
|
53
|
+
return;
|
|
54
|
+
commands.forEach(([command, ...args]) => {
|
|
55
|
+
if (!command)
|
|
56
|
+
return;
|
|
57
|
+
spawnSync(command, args, { stdio: 'inherit' });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
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
|
-
const Executor_1 = require("./Executor");
|
|
6
|
+
const Executor_1 = __importDefault(require("./Executor.cjs"));
|
|
4
7
|
exports.default = [
|
|
5
8
|
new Executor_1.default('Node.js', {
|
|
6
9
|
extensions: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
|
|
@@ -0,0 +1,94 @@
|
|
|
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('Lua', {
|
|
68
|
+
extensions: ['lua'],
|
|
69
|
+
checkInstallation: ['lua', '--version'],
|
|
70
|
+
installMessage: 'Please install Lua from https://www.lua.org',
|
|
71
|
+
run(args) {
|
|
72
|
+
return ['lua', ...args];
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
new Executor('SASS (CSS)', {
|
|
76
|
+
extensions: ['sass', 'scss'],
|
|
77
|
+
checkInstallation: ['sass', '--version'],
|
|
78
|
+
installCommands: ['npm install -g sass'],
|
|
79
|
+
installMessage: 'Please install SASS from https://sass-lang.com',
|
|
80
|
+
run(args) {
|
|
81
|
+
return ['sass', ...args];
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
new Executor('HTML Server', {
|
|
85
|
+
extensions: ['html', 'htm'],
|
|
86
|
+
watchExtensions: ['css', 'js', 'javascript', 'json'],
|
|
87
|
+
checkInstallation: ['http-server', '--version'],
|
|
88
|
+
installCommands: ['npm install -g http-server'],
|
|
89
|
+
installMessage: 'Please install http-server from https://www.npmjs.com/package/http-server',
|
|
90
|
+
run(args) {
|
|
91
|
+
return ['http-server', ...args];
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
];
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
exports.default = default_1;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
+
function default_1(baseDir, extraIgnore = []) {
|
|
34
|
+
const gitignorePath = path.resolve(path.join(baseDir, '.gitignore'));
|
|
35
|
+
const ig = (0, ignore_1.default)({ ignorecase: true }).add(extraIgnore);
|
|
36
|
+
if (fs.existsSync(gitignorePath)) {
|
|
37
|
+
return ig.add(fs.readFileSync(gitignorePath).toString());
|
|
38
|
+
}
|
|
39
|
+
return ig;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (baseDir: string, extraIgnore?: string[]): import("ignore").Ignore;
|
|
@@ -0,0 +1,11 @@
|
|
|
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,10 +1,36 @@
|
|
|
1
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
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
const cross_spawn_1 = require("cross-spawn");
|
|
4
|
-
const readline = require("readline");
|
|
5
|
-
const watcher_1 = require("./watcher");
|
|
6
|
-
const colors_1 = require("../lib/colors");
|
|
7
|
-
const kill_process_1 = require("./kill-process");
|
|
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"));
|
|
8
34
|
class Execution {
|
|
9
35
|
static start([command, ...args], options) {
|
|
10
36
|
return new Execution(command, args, options);
|
|
@@ -25,7 +51,7 @@ class Execution {
|
|
|
25
51
|
this.benchMarkText =
|
|
26
52
|
colors_1.default.bold(this.options.benchmarkPrefix) + ' ' + this.benchMarkText;
|
|
27
53
|
}
|
|
28
|
-
if (this.options.
|
|
54
|
+
if (this.options.keystrokeReload) {
|
|
29
55
|
readline.emitKeypressEvents(process.stdin);
|
|
30
56
|
(_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
|
|
31
57
|
process.stdin.on('keypress', (_, key) => {
|
|
@@ -39,11 +65,13 @@ class Execution {
|
|
|
39
65
|
});
|
|
40
66
|
}
|
|
41
67
|
if (this.options.watch) {
|
|
42
|
-
(0, watcher_1.default)(this.options.cwd,
|
|
43
|
-
|
|
68
|
+
(0, watcher_1.default)(this.options.cwd, this.options.watchInclude.length
|
|
69
|
+
? this.options.watchInclude
|
|
70
|
+
: [this.options.cwd], () => this.runProcess(), {
|
|
71
|
+
ignore: this.options.watchExclude,
|
|
44
72
|
debounceDelay: this.options.watchDelay,
|
|
45
73
|
extensions: new Set(this.options.watchExtensions),
|
|
46
|
-
}
|
|
74
|
+
});
|
|
47
75
|
}
|
|
48
76
|
}
|
|
49
77
|
runProcess() {
|
|
@@ -82,7 +110,7 @@ class Execution {
|
|
|
82
110
|
.map((ext) => colors_1.default.yellow(ext))
|
|
83
111
|
.join(', ') || colors_1.default.yellow('*')));
|
|
84
112
|
}
|
|
85
|
-
if (this.options.
|
|
113
|
+
if (this.options.keystrokeReload) {
|
|
86
114
|
console.log(colors_1.default.blue.dim(`> Press ${colors_1.default.yellow('F5')} or ${colors_1.default.yellow('^R')} to reload...`));
|
|
87
115
|
}
|
|
88
116
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExecuteOptions } from "../arg-helper.mjs";
|
|
2
|
+
export default class Execution {
|
|
3
|
+
private command;
|
|
4
|
+
private args;
|
|
5
|
+
private options;
|
|
6
|
+
private child;
|
|
7
|
+
private benchMarkText;
|
|
8
|
+
private isBenchmarkRunning;
|
|
9
|
+
static start([command, ...args]: string[], options: ExecuteOptions): Execution;
|
|
10
|
+
constructor(command: string, args: string[], options: ExecuteOptions);
|
|
11
|
+
private setup;
|
|
12
|
+
private runProcess;
|
|
13
|
+
private killProcess;
|
|
14
|
+
private clearBeforeStart;
|
|
15
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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.blue('> Execution time');
|
|
16
|
+
this.isBenchmarkRunning = false;
|
|
17
|
+
this.setup();
|
|
18
|
+
this.runProcess();
|
|
19
|
+
}
|
|
20
|
+
setup() {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (this.options.benchmarkPrefix) {
|
|
23
|
+
this.benchMarkText =
|
|
24
|
+
colors.bold(this.options.benchmarkPrefix) + ' ' + this.benchMarkText;
|
|
25
|
+
}
|
|
26
|
+
if (this.options.keystrokeReload) {
|
|
27
|
+
readline.emitKeypressEvents(process.stdin);
|
|
28
|
+
(_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
|
|
29
|
+
process.stdin.on('keypress', (_, key) => {
|
|
30
|
+
if (key.name === 'f5' || (key.ctrl && key.name === 'r')) {
|
|
31
|
+
return this.runProcess();
|
|
32
|
+
}
|
|
33
|
+
if (key.ctrl && key.name === 'c') {
|
|
34
|
+
this.killProcess();
|
|
35
|
+
return process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (this.options.watch) {
|
|
40
|
+
watcher(this.options.cwd, this.options.watchInclude.length
|
|
41
|
+
? this.options.watchInclude
|
|
42
|
+
: [this.options.cwd], () => this.runProcess(), {
|
|
43
|
+
ignore: this.options.watchExclude,
|
|
44
|
+
debounceDelay: this.options.watchDelay,
|
|
45
|
+
extensions: new Set(this.options.watchExtensions),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
runProcess() {
|
|
50
|
+
this.killProcess();
|
|
51
|
+
this.clearBeforeStart();
|
|
52
|
+
if (this.options.showTime) {
|
|
53
|
+
console.log('@', colors.yellow(new Date().toLocaleString()));
|
|
54
|
+
}
|
|
55
|
+
if (this.options.benchmark) {
|
|
56
|
+
if (this.isBenchmarkRunning) {
|
|
57
|
+
console.timeEnd(this.benchMarkText);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.isBenchmarkRunning = true;
|
|
61
|
+
}
|
|
62
|
+
console.time(this.benchMarkText);
|
|
63
|
+
}
|
|
64
|
+
this.child = spawn(this.command, this.args, {
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
argv0: this.command,
|
|
67
|
+
cwd: this.options.cwd,
|
|
68
|
+
shell: this.options.shell,
|
|
69
|
+
env: Object.assign({}, this.options.env),
|
|
70
|
+
});
|
|
71
|
+
this.child.on('error', console.error);
|
|
72
|
+
this.child.on('exit', (code) => {
|
|
73
|
+
if (code && code > 0) {
|
|
74
|
+
console.log(colors.red(`Process exited with code: ${colors.yellow(String(code))}`));
|
|
75
|
+
}
|
|
76
|
+
if (this.options.benchmark) {
|
|
77
|
+
this.isBenchmarkRunning = false;
|
|
78
|
+
console.timeEnd(this.benchMarkText);
|
|
79
|
+
}
|
|
80
|
+
if (this.options.watch && this.options.showInfo) {
|
|
81
|
+
console.log(colors.dim.blue('> Watching for extensions:'), colors.dim(this.options.watchExtensions
|
|
82
|
+
.map((ext) => colors.yellow(ext))
|
|
83
|
+
.join(', ') || colors.yellow('*')));
|
|
84
|
+
}
|
|
85
|
+
if (this.options.keystrokeReload) {
|
|
86
|
+
console.log(colors.blue.dim(`> Press ${colors.yellow('F5')} or ${colors.yellow('^R')} to reload...`));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
killProcess() {
|
|
91
|
+
if (!this.child)
|
|
92
|
+
return;
|
|
93
|
+
this.child.removeAllListeners();
|
|
94
|
+
if (!killProcess(this.child)) {
|
|
95
|
+
console.error(colors.red('Failed to kill the previous process'));
|
|
96
|
+
}
|
|
97
|
+
this.child = null;
|
|
98
|
+
}
|
|
99
|
+
clearBeforeStart() {
|
|
100
|
+
if (this.options.clearOnReload) {
|
|
101
|
+
process.stdout.write('\x1Bc');
|
|
102
|
+
console.clear();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = default_1;
|
|
27
|
+
const os = __importStar(require("os"));
|
|
28
|
+
const child_process_1 = require("child_process");
|
|
29
|
+
function default_1(child) {
|
|
30
|
+
if (!child.pid)
|
|
31
|
+
return true;
|
|
32
|
+
child.removeAllListeners();
|
|
33
|
+
const isWindows = os.platform() === 'win32';
|
|
34
|
+
try {
|
|
35
|
+
if (isWindows) {
|
|
36
|
+
(0, child_process_1.execSync)(`taskkill /pid ${child.pid} /T /F`, { stdio: 'ignore' });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (_a) { }
|
|
43
|
+
try {
|
|
44
|
+
process.kill(child.pid, 0);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ChildProcess } from
|
|
1
|
+
import { ChildProcess } from "child_process";
|
|
2
2
|
export default function (child: ChildProcess): boolean;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const os = require("os");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
function default_1(child) {
|
|
1
|
+
import * as os from "os";
|
|
2
|
+
import { execSync } from "child_process";
|
|
3
|
+
export default function (child) {
|
|
7
4
|
if (!child.pid)
|
|
8
5
|
return true;
|
|
9
6
|
child.removeAllListeners();
|
|
10
7
|
const isWindows = os.platform() === 'win32';
|
|
11
8
|
try {
|
|
12
9
|
if (isWindows) {
|
|
13
|
-
|
|
10
|
+
execSync(`taskkill /pid ${child.pid} /T /F`, { stdio: 'ignore' });
|
|
14
11
|
}
|
|
15
12
|
else {
|
|
16
13
|
process.kill(-child.pid, 'SIGKILL');
|
|
@@ -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
|
+
exports.default = default_1;
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
const gitignore_1 = __importDefault(require("./gitignore.cjs"));
|
|
32
|
+
const chokidar = __importStar(require("chokidar"));
|
|
33
|
+
const debounce_1 = require("../utils/debounce.cjs");
|
|
34
|
+
function default_1(cwd, targets, callback, options) {
|
|
35
|
+
const ig = (0, gitignore_1.default)(cwd, options.ignore);
|
|
36
|
+
const debounce = (0, debounce_1.createDebounce)(options.debounceDelay);
|
|
37
|
+
const watcher = chokidar.watch(targets, {
|
|
38
|
+
ignored: (filePath) => {
|
|
39
|
+
for (const target of targets) {
|
|
40
|
+
const relativePath = path.relative(target, filePath);
|
|
41
|
+
if (!relativePath)
|
|
42
|
+
return false;
|
|
43
|
+
if (ig.ignores(relativePath))
|
|
44
|
+
return true;
|
|
45
|
+
if (options.extensions.size) {
|
|
46
|
+
const ext = path.extname(relativePath).slice(1);
|
|
47
|
+
if (ext && !options.extensions.has(ext))
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
interval: options.debounceDelay / 2,
|
|
54
|
+
ignoreInitial: true,
|
|
55
|
+
persistent: true,
|
|
56
|
+
});
|
|
57
|
+
watcher.on('add', () => debounce(() => callback()));
|
|
58
|
+
watcher.on('change', () => debounce(() => callback()));
|
|
59
|
+
watcher.on('unlink', () => debounce(() => callback()));
|
|
60
|
+
}
|