uni-run 0.0.2 → 0.0.4

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.
@@ -0,0 +1,62 @@
1
+ import NoArg from 'noarg';
2
+ import type { app } from './arg';
3
+ import { ExecuteOptions } from './execution';
4
+ export declare const executionConfig: {
5
+ readonly flags: {
6
+ readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
7
+ required: true;
8
+ default: string;
9
+ description: "The current working directory";
10
+ }>;
11
+ readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
12
+ description: "Clear the console before running the script";
13
+ required: true;
14
+ default: true;
15
+ aliases: [string];
16
+ }>;
17
+ readonly reload: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
18
+ description: "Reload the page when pressing \"Ctrl+R\" or \"Meta+R\"";
19
+ required: true;
20
+ default: true;
21
+ aliases: [string];
22
+ }>;
23
+ readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
24
+ description: "Watch for changes";
25
+ required: true;
26
+ default: true;
27
+ aliases: [string];
28
+ }>;
29
+ readonly watchDelay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
30
+ description: "The delay to wait for the watcher to trigger";
31
+ required: true;
32
+ default: 100;
33
+ aliases: [string];
34
+ }>;
35
+ readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
36
+ description: "Looks for changes only of the given extensions";
37
+ required: true;
38
+ default: never[];
39
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
40
+ aliases: [string];
41
+ }>;
42
+ readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
43
+ required: true;
44
+ default: never[];
45
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
46
+ description: "Ignore the given targets";
47
+ }>;
48
+ readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
49
+ required: true;
50
+ default: never[];
51
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
52
+ description: "Environment variables";
53
+ }>;
54
+ };
55
+ readonly listArgument: {
56
+ readonly name: "args";
57
+ readonly description: "The arguments to pass to the script";
58
+ readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
59
+ };
60
+ readonly trailingArguments: "--";
61
+ };
62
+ export declare function mapFlagsToOptions(flags: NoArg.InferFlags<typeof app>, watchExtensions?: string[]): ExecuteOptions;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executionConfig = void 0;
4
+ exports.mapFlagsToOptions = mapFlagsToOptions;
5
+ const noarg_1 = require("noarg");
6
+ exports.executionConfig = noarg_1.default.defineConfig({
7
+ flags: {
8
+ cwd: noarg_1.default.string()
9
+ .default(process.cwd())
10
+ .description('The current working directory'),
11
+ clear: noarg_1.default.boolean()
12
+ .default(true)
13
+ .description('Clear the console before running the script')
14
+ .aliases('c'),
15
+ reload: noarg_1.default.boolean()
16
+ .default(true)
17
+ .description('Reload the page when pressing "Ctrl+R" or "Meta+R"')
18
+ .aliases('r'),
19
+ watch: noarg_1.default.boolean()
20
+ .default(true)
21
+ .description('Watch for changes')
22
+ .aliases('w'),
23
+ watchDelay: noarg_1.default.number()
24
+ .default(100)
25
+ .description('The delay to wait for the watcher to trigger')
26
+ .aliases('wd'),
27
+ ext: noarg_1.default.array(noarg_1.default.string())
28
+ .default([])
29
+ .description('Looks for changes only of the given extensions')
30
+ .aliases('e'),
31
+ ignore: noarg_1.default.array(noarg_1.default.string())
32
+ .default([])
33
+ .description('Ignore the given targets'),
34
+ env: noarg_1.default.array(noarg_1.default.string())
35
+ .default([])
36
+ .description('Environment variables'),
37
+ },
38
+ listArgument: {
39
+ name: 'args',
40
+ description: 'The arguments to pass to the script',
41
+ type: noarg_1.default.string(),
42
+ },
43
+ trailingArguments: '--',
44
+ });
45
+ function mapFlagsToOptions(flags, watchExtensions) {
46
+ return {
47
+ cwd: flags.cwd,
48
+ clearOnReload: flags.clear,
49
+ readlineReload: flags.reload,
50
+ env: flags.env.reduce((acc, env) => {
51
+ const [key, value] = env.split('=');
52
+ acc[key] = value;
53
+ return acc;
54
+ }, {}),
55
+ watch: flags.watch,
56
+ watchDelay: flags.watchDelay,
57
+ watchExtensions: flags.ext.length ? flags.ext : watchExtensions !== null && watchExtensions !== void 0 ? watchExtensions : [],
58
+ watchIgnore: flags.ignore,
59
+ };
60
+ }
package/dist/arg.d.ts CHANGED
@@ -9,10 +9,11 @@ export declare const app: NoArg<"uni-run", {
9
9
  }, {
10
10
  readonly optionalArguments: [];
11
11
  readonly globalFlags: {};
12
+ readonly description: "A universal runner for scripts";
12
13
  readonly arguments: [{
13
14
  readonly name: "script";
14
- readonly description: "Run a script";
15
15
  readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
16
+ readonly description: "Run a script";
16
17
  }];
17
18
  readonly listArgument: {
18
19
  readonly name: "args";
package/dist/arg.js CHANGED
@@ -2,52 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exec = exports.app = void 0;
4
4
  const noarg_1 = require("noarg");
5
- const executionConfig = noarg_1.default.defineConfig({
6
- flags: {
7
- cwd: noarg_1.default.string()
8
- .default(process.cwd())
9
- .description('The current working directory'),
10
- clear: noarg_1.default.boolean()
11
- .default(true)
12
- .description('Clear the console before running the script')
13
- .aliases('c'),
14
- reload: noarg_1.default.boolean()
15
- .default(true)
16
- .description('Reload the page when pressing "Ctrl+R" or "Meta+R"')
17
- .aliases('r'),
18
- watch: noarg_1.default.boolean()
19
- .default(true)
20
- .description('Watch for changes')
21
- .aliases('w'),
22
- watchDelay: noarg_1.default.number()
23
- .default(100)
24
- .description('The delay to wait for the watcher to trigger')
25
- .aliases('wd'),
26
- ext: noarg_1.default.array(noarg_1.default.string())
27
- .default([])
28
- .description('Looks for changes only of the given extensions')
29
- .aliases('e'),
30
- ignore: noarg_1.default.array(noarg_1.default.string())
31
- .default([])
32
- .description('Ignore the given targets'),
33
- env: noarg_1.default.array(noarg_1.default.string())
34
- .default([])
35
- .description('Environment variables'),
36
- },
37
- listArgument: {
38
- name: 'args',
39
- description: 'The arguments to pass to the script',
40
- type: noarg_1.default.string(),
41
- },
42
- trailingArguments: '--',
43
- });
44
- exports.app = noarg_1.default.create('uni-run', Object.assign(Object.assign({}, executionConfig), { arguments: [
45
- {
46
- name: 'script',
47
- description: 'Run a script',
48
- type: noarg_1.default.string(),
49
- },
50
- ], system: {
51
- splitListByComma: true,
52
- } }));
53
- exports.exec = exports.app.create('exec', Object.assign(Object.assign({}, executionConfig), { description: 'Execute a script with the given binary' }));
5
+ const arg_helper_1 = require("./arg-helper");
6
+ exports.app = noarg_1.default.create('uni-run', Object.assign(Object.assign({}, arg_helper_1.executionConfig), { description: 'A universal runner for scripts', system: { splitListByComma: true }, arguments: [
7
+ { name: 'script', type: noarg_1.default.string(), description: 'Run a script' },
8
+ ] }));
9
+ exports.exec = exports.app.create('exec', Object.assign(Object.assign({}, arg_helper_1.executionConfig), { description: 'Execute a script with the given binary' }));
@@ -0,0 +1,19 @@
1
+ type ExecutionBinConfig = {
2
+ command: string;
3
+ extensions: string[];
4
+ watchExtensions?: string[];
5
+ runArgs?: string[];
6
+ checkInstallationArgs?: string[];
7
+ howToInstall?: () => void;
8
+ installCommands?: string[][];
9
+ };
10
+ export default class Executor {
11
+ name: string;
12
+ config: ExecutionBinConfig;
13
+ constructor(name: string, config: ExecutionBinConfig);
14
+ getArgs(...args: string[]): string[];
15
+ isSupported(script: string): boolean;
16
+ isInstalled(): boolean;
17
+ renderHowToInstall(): void;
18
+ }
19
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const confirm_1 = require("@inquirer/confirm");
4
+ const cross_spawn_1 = require("cross-spawn");
5
+ class Executor {
6
+ constructor(name, config) {
7
+ var _a;
8
+ this.name = name;
9
+ this.config = config;
10
+ (_a = this.config.watchExtensions) === null || _a === void 0 ? void 0 : _a.push(...this.config.extensions);
11
+ }
12
+ getArgs(...args) {
13
+ var _a;
14
+ return [this.config.command, ...((_a = this.config.runArgs) !== null && _a !== void 0 ? _a : []), ...args];
15
+ }
16
+ isSupported(script) {
17
+ return this.config.extensions.includes(script.split('.').pop() || '');
18
+ }
19
+ isInstalled() {
20
+ const result = (0, cross_spawn_1.sync)(this.config.command, [...(this.config.checkInstallationArgs || [])], { stdio: 'ignore' });
21
+ if (result.status === 1)
22
+ return false;
23
+ return true;
24
+ }
25
+ renderHowToInstall() {
26
+ var _a;
27
+ console.error(`${this.name} is not installed.`);
28
+ if (this.config.howToInstall) {
29
+ console.log('How to install:');
30
+ this.config.howToInstall();
31
+ }
32
+ if (!((_a = this.config.installCommands) === null || _a === void 0 ? void 0 : _a.length))
33
+ return;
34
+ (0, confirm_1.default)({ message: 'Do you want to install it?' }).then((ans) => {
35
+ var _a;
36
+ if (!ans)
37
+ return;
38
+ (_a = this.config.installCommands) === null || _a === void 0 ? void 0 : _a.forEach(([command, ...args]) => {
39
+ if (!command)
40
+ return;
41
+ (0, cross_spawn_1.sync)(command, args, { stdio: 'inherit' });
42
+ });
43
+ });
44
+ }
45
+ }
46
+ exports.default = Executor;
@@ -1,3 +1,3 @@
1
- import ExecutionBin from './ExecutionBin';
2
- declare const _default: ExecutionBin[];
1
+ import Executor from './Executor';
2
+ declare const _default: Executor[];
3
3
  export default _default;
@@ -1,53 +1,84 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const ExecutionBin_1 = require("./ExecutionBin");
3
+ const Executor_1 = require("./Executor");
4
4
  exports.default = [
5
- new ExecutionBin_1.default({
6
- name: 'Node.js',
5
+ new Executor_1.default('Node.js', {
7
6
  command: 'node',
8
7
  extensions: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
9
- run(...args) {
10
- return [this.command, ...args];
11
- },
8
+ watchExtensions: ['html', 'css', 'json'],
12
9
  checkInstallationArgs: ['--version'],
13
10
  howToInstall: () => {
14
11
  console.log('Please install Node.js from https://nodejs.org/');
15
12
  },
16
13
  }),
17
- new ExecutionBin_1.default({
18
- name: 'TypeScript',
14
+ new Executor_1.default('TypeScript', {
19
15
  command: 'ts-node',
20
16
  extensions: ['ts', 'tsx', 'cts', 'ctsx', 'mts', 'mtsx'],
21
- run(...args) {
22
- return [this.command, ...args];
23
- },
17
+ watchExtensions: [
18
+ 'html',
19
+ 'css',
20
+ 'json',
21
+ 'js',
22
+ 'javascript',
23
+ 'jsx',
24
+ 'cjs',
25
+ 'cjsx',
26
+ 'mjs',
27
+ 'mjsx',
28
+ ],
24
29
  checkInstallationArgs: ['--version'],
30
+ installCommands: [['npm', 'install', '-g', 'ts-node']],
25
31
  howToInstall: () => {
26
32
  console.log('Please install ts-node from https://www.npmjs.com/package/ts-node');
27
33
  },
28
34
  }),
29
- new ExecutionBin_1.default({
30
- name: 'python',
35
+ new Executor_1.default('Python', {
31
36
  command: 'python',
32
37
  extensions: ['py'],
33
- run(...args) {
34
- return [this.command, ...args];
35
- },
36
38
  checkInstallationArgs: ['--version'],
37
39
  howToInstall: () => {
38
40
  console.log('Please install Python from https://www.python.org/');
39
41
  },
40
42
  }),
41
- new ExecutionBin_1.default({
42
- name: 'java',
43
+ new Executor_1.default('Java - Oracle', {
43
44
  command: 'java',
44
45
  extensions: ['java'],
45
- run(...args) {
46
- return [this.command, ...args];
47
- },
48
46
  checkInstallationArgs: ['--version'],
49
47
  howToInstall: () => {
50
48
  console.log('Please install Java from https://www.oracle.com/java/');
51
49
  },
52
50
  }),
51
+ new Executor_1.default('Powershell', {
52
+ command: 'powershell',
53
+ extensions: ['ps1'],
54
+ checkInstallationArgs: ['-command', '"Get-Host"'],
55
+ howToInstall: () => {
56
+ console.log('Please install Powershell from https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell');
57
+ },
58
+ }),
59
+ new Executor_1.default('Cmd - Command Prompt', {
60
+ command: 'cmd',
61
+ runArgs: ['/c'],
62
+ extensions: ['cmd', 'bat'],
63
+ checkInstallationArgs: ['/c', 'echo', 'ok'],
64
+ howToInstall: () => {
65
+ console.log('Please install Command Prompt from Windows');
66
+ },
67
+ }),
68
+ new Executor_1.default('Shell', {
69
+ command: 'bash',
70
+ extensions: ['sh'],
71
+ checkInstallationArgs: ['--version'],
72
+ howToInstall: () => {
73
+ console.log('Please install Bash from https://www.gnu.org/software/bash/');
74
+ },
75
+ }),
76
+ new Executor_1.default('Lua', {
77
+ command: 'lua',
78
+ extensions: ['lua'],
79
+ checkInstallationArgs: ['--version'],
80
+ howToInstall: () => {
81
+ console.log('Please install Lua from https://www.lua.org/');
82
+ },
83
+ }),
53
84
  ];
@@ -0,0 +1,22 @@
1
+ export default class Execution {
2
+ private command;
3
+ private args;
4
+ private options;
5
+ private child;
6
+ static start([command, ...args]: string[], options: ExecuteOptions): Execution;
7
+ constructor(command: string, args: string[], options: ExecuteOptions);
8
+ private setup;
9
+ private runProcess;
10
+ private killProcess;
11
+ private clearBeforeStart;
12
+ }
13
+ export type ExecuteOptions = {
14
+ cwd: string;
15
+ clearOnReload: boolean;
16
+ readlineReload: boolean;
17
+ watch: boolean;
18
+ watchDelay: number;
19
+ watchIgnore: string[];
20
+ watchExtensions: string[];
21
+ env: Record<string, string>;
22
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cross_spawn_1 = require("cross-spawn");
4
+ const readline = require("readline");
5
+ const watcher_1 = require("./watcher");
6
+ const colors_1 = require("../utils/colors");
7
+ const kill_process_1 = require("./kill-process");
8
+ class Execution {
9
+ static start([command, ...args], options) {
10
+ return new Execution(command, args, options);
11
+ }
12
+ constructor(command, args, options) {
13
+ this.command = command;
14
+ this.args = args;
15
+ this.options = options;
16
+ this.child = null;
17
+ this.setup();
18
+ this.runProcess();
19
+ }
20
+ setup() {
21
+ var _a, _b;
22
+ if (this.options.readlineReload) {
23
+ readline.emitKeypressEvents(process.stdin);
24
+ (_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
25
+ process.stdin.on('keypress', (_, key) => {
26
+ if (key.name === 'f5')
27
+ return this.runProcess();
28
+ if ((key.ctrl || key.meta) && key.name === 'r')
29
+ return this.runProcess();
30
+ if (key.ctrl && key.name === 'c') {
31
+ this.killProcess();
32
+ process.exit(0);
33
+ }
34
+ });
35
+ }
36
+ if (this.options.watch) {
37
+ (0, watcher_1.default)(this.options.cwd, {
38
+ ignore: this.options.watchIgnore,
39
+ debounceDelay: this.options.watchDelay,
40
+ extensions: new Set(this.options.watchExtensions),
41
+ }, () => this.runProcess());
42
+ }
43
+ }
44
+ runProcess() {
45
+ this.killProcess();
46
+ this.clearBeforeStart();
47
+ this.child = (0, cross_spawn_1.spawn)(this.command, this.args, {
48
+ stdio: 'inherit',
49
+ cwd: this.options.cwd,
50
+ env: Object.assign({}, this.options.env),
51
+ });
52
+ this.child.on('error', console.error);
53
+ this.child.on('exit', (code) => {
54
+ if (code && code > 0) {
55
+ console.log('');
56
+ console.log(colors_1.default.red(`Process exited with code: ${colors_1.default.yellow(String(code))}`));
57
+ }
58
+ if (this.options.readlineReload) {
59
+ console.log(colors_1.default.blue.dim(`⟳ Press ${colors_1.default.yellow('F5')} or ${colors_1.default.yellow('^R')} to reload...`));
60
+ }
61
+ });
62
+ }
63
+ killProcess() {
64
+ if (!this.child)
65
+ return;
66
+ this.child.removeAllListeners();
67
+ if (!(0, kill_process_1.default)(this.child)) {
68
+ console.error(colors_1.default.red('Failed to kill the previous process'));
69
+ }
70
+ this.child = null;
71
+ }
72
+ clearBeforeStart() {
73
+ if (this.options.clearOnReload) {
74
+ process.stdout.write('\x1Bc');
75
+ console.clear();
76
+ }
77
+ }
78
+ }
79
+ exports.default = Execution;
@@ -0,0 +1,2 @@
1
+ import { ChildProcess } from 'child_process';
2
+ export default function (child: ChildProcess): boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const os = require("os");
5
+ const child_process_1 = require("child_process");
6
+ function default_1(child) {
7
+ if (!child.pid)
8
+ return true;
9
+ child.removeAllListeners();
10
+ const isWindows = os.platform() === 'win32';
11
+ try {
12
+ if (isWindows) {
13
+ (0, child_process_1.execSync)(`taskkill /pid ${child.pid} /T /F`, { stdio: 'ignore' });
14
+ }
15
+ else {
16
+ process.kill(-child.pid, 'SIGKILL');
17
+ }
18
+ }
19
+ catch (_a) { }
20
+ try {
21
+ process.kill(child.pid, 0);
22
+ return false;
23
+ }
24
+ catch (error) {
25
+ return true;
26
+ }
27
+ }
package/dist/index.js CHANGED
@@ -1,44 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const arg = require("./arg");
4
+ const execution_1 = require("./execution");
4
5
  const builtin_bin_1 = require("./builtin-bin");
5
- const execute_1 = require("./execute");
6
- function mapFlagsToOptions(flags) {
7
- return {
8
- cwd: flags.cwd,
9
- clearOnReload: flags.clear,
10
- readlineReload: flags.reload,
11
- env: flags.env.reduce((acc, env) => {
12
- const [key, value] = env.split('=');
13
- acc[key] = value;
14
- return acc;
15
- }, {}),
16
- watch: flags.watch,
17
- watchDelay: flags.watchDelay,
18
- watchExtensions: flags.ext,
19
- watchIgnore: flags.ignore,
20
- };
21
- }
6
+ const arg_helper_1 = require("./arg-helper");
22
7
  arg.app.on(([script, listArs, trailingArgs], flags) => {
23
- if (script) {
24
- const bin = builtin_bin_1.default.find((bin) => bin.isSupported(script));
25
- if (!bin) {
26
- console.log('Unsupported script:', script);
27
- console.log('You may try "ur exec bin script.ext - --flags"');
28
- process.exit(1);
29
- }
30
- if (!bin.isInstalled()) {
31
- console.error(`${bin.displayName} is not installed.`);
32
- if (bin.howToInstall) {
33
- console.log('How to install:');
34
- bin.howToInstall();
35
- }
36
- process.exit(1);
37
- }
38
- return (0, execute_1.default)(bin.run(script, ...listArs, ...trailingArgs), mapFlagsToOptions(flags));
8
+ const bin = builtin_bin_1.default.find((bin) => bin.isSupported(script));
9
+ if (!bin) {
10
+ console.log('Unsupported script:', script);
11
+ return console.log('You may try "ur exec bin script.ext - --flags"');
39
12
  }
40
- arg.app.renderHelp();
13
+ if (!bin.isInstalled()) {
14
+ return bin.renderHowToInstall();
15
+ }
16
+ execution_1.default.start(bin.getArgs(script, ...listArs, ...trailingArgs), (0, arg_helper_1.mapFlagsToOptions)(flags, bin.config.watchExtensions));
41
17
  });
42
18
  arg.exec.on(([listArs, trailingArgs], flags) => {
43
- (0, execute_1.default)([...listArs, ...trailingArgs], mapFlagsToOptions(flags));
19
+ execution_1.default.start([...listArs, ...trailingArgs], (0, arg_helper_1.mapFlagsToOptions)(flags));
44
20
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "uni-run",
3
3
  "description": "Universal Runner for many language",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "type": "commonjs",
6
6
  "scripts": {
7
7
  "ts": "w ./src/__lab__/index.ts",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/cross-spawn": "^6.0.6",
25
+ "@types/node": "^22.5.0",
25
26
  "typescript": "^5.5.4"
26
27
  },
27
28
  "repository": {
@@ -1,18 +0,0 @@
1
- export default class ExecutionBin {
2
- displayName: string;
3
- command: string;
4
- run: (...args: string[]) => [command: string, ...args: string[]];
5
- extensions: Set<string>;
6
- checkInstallationArgs?: string[];
7
- howToInstall?: () => void;
8
- constructor(config: {
9
- name: string;
10
- command: string;
11
- extensions: string[];
12
- run: (...args: string[]) => [command: string, ...args: string[]];
13
- checkInstallationArgs?: string[];
14
- howToInstall?: () => void;
15
- });
16
- isSupported(script: string): boolean;
17
- isInstalled(): boolean;
18
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cross_spawn_1 = require("cross-spawn");
4
- class ExecutionBin {
5
- constructor(config) {
6
- this.displayName = config.name;
7
- this.command = config.command;
8
- this.extensions = new Set(config.extensions);
9
- this.run = config.run;
10
- this.checkInstallationArgs = config.checkInstallationArgs;
11
- this.howToInstall = config.howToInstall;
12
- }
13
- isSupported(script) {
14
- return this.extensions.has(script.split('.').pop() || '');
15
- }
16
- isInstalled() {
17
- const result = (0, cross_spawn_1.sync)(this.command, this.checkInstallationArgs ? this.checkInstallationArgs : [], { shell: false, stdio: 'ignore' });
18
- if (result.status === 1)
19
- return false;
20
- return true;
21
- }
22
- }
23
- exports.default = ExecutionBin;
package/dist/execute.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export type ExecuteOptions = {
2
- cwd: string;
3
- clearOnReload: boolean;
4
- readlineReload: boolean;
5
- watch: boolean;
6
- watchDelay: number;
7
- watchIgnore: string[];
8
- watchExtensions: string[];
9
- env?: Record<string, string>;
10
- };
11
- export default function ([command, ...args]: string[], options: ExecuteOptions): void;
package/dist/execute.js DELETED
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const readline = require("readline");
5
- const cross_spawn_1 = require("cross-spawn");
6
- const colors_1 = require("./utils/colors");
7
- const watcher_1 = require("./watcher");
8
- function default_1([command, ...args], options) {
9
- var _a, _b;
10
- if (options.readlineReload) {
11
- readline.emitKeypressEvents(process.stdin);
12
- (_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
13
- process.stdin.on('keypress', (_, key) => {
14
- if (key.name === 'f5')
15
- return runProcess();
16
- if ((key.ctrl || key.meta) && key.name === 'r')
17
- return runProcess();
18
- if (key.ctrl && key.name === 'c') {
19
- killProcess();
20
- console.log('^C...');
21
- process.exit(0);
22
- }
23
- });
24
- }
25
- if (options.watch) {
26
- (0, watcher_1.default)(options.cwd, {
27
- ignore: options.watchIgnore,
28
- debounceDelay: options.watchDelay,
29
- extensions: new Set(options.watchExtensions),
30
- }, () => runProcess());
31
- }
32
- let child = null;
33
- function runProcess() {
34
- if (options.clearOnReload) {
35
- process.stdout.write('\x1Bc');
36
- console.clear();
37
- }
38
- killProcess();
39
- child = (0, cross_spawn_1.spawn)(command, args, {
40
- shell: false,
41
- cwd: options.cwd,
42
- stdio: 'inherit',
43
- env: Object.assign({}, options.env),
44
- });
45
- child.on('error', console.error);
46
- child.on('exit', (code) => {
47
- if (code && code > 0) {
48
- console.log('');
49
- console.log(colors_1.default.red(`Process exited with code: ${colors_1.default.yellow(String(code))}`));
50
- }
51
- if (options.readlineReload) {
52
- console.log(colors_1.default.blue.dim(`⟳ Press ${colors_1.default.yellow('F5')} or ${colors_1.default.yellow('^R')} to reload...`));
53
- }
54
- });
55
- }
56
- function killProcess() {
57
- if (child) {
58
- child.removeAllListeners();
59
- child.kill();
60
- }
61
- }
62
- runProcess();
63
- process.on('exit', killProcess);
64
- process.on('SIGINT', killProcess);
65
- process.on('cleanup', killProcess);
66
- }
File without changes
File without changes
File without changes