uni-run 0.0.0

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/dist/arg.d.ts ADDED
@@ -0,0 +1,142 @@
1
+ import NoArg from 'noarg';
2
+ export declare const app: NoArg<"uni-run", {
3
+ readonly allowEqualAssign: true;
4
+ readonly booleanNotSyntaxEnding: "\\";
5
+ readonly allowDuplicateFlagForList: true;
6
+ readonly splitListByComma: true;
7
+ }, {
8
+ readonly help: true;
9
+ }, {
10
+ readonly optionalArguments: [];
11
+ readonly globalFlags: {};
12
+ readonly arguments: [{
13
+ readonly name: "script";
14
+ readonly description: "Run a script";
15
+ readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
16
+ }];
17
+ readonly listArgument: {
18
+ readonly name: "args";
19
+ readonly description: "The arguments to pass to the script";
20
+ readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
21
+ };
22
+ readonly trailingArguments: "--";
23
+ readonly flags: {
24
+ readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
25
+ required: true;
26
+ default: string;
27
+ description: "The current working directory";
28
+ }>;
29
+ readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
30
+ description: "Clear the console before running the script";
31
+ required: true;
32
+ default: true;
33
+ aliases: [string];
34
+ }>;
35
+ readonly reload: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
36
+ description: "Reload the page when pressing \"Ctrl+R\" or \"Meta+R\"";
37
+ required: true;
38
+ default: true;
39
+ aliases: [string];
40
+ }>;
41
+ readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
42
+ description: "Watch for changes";
43
+ required: true;
44
+ default: true;
45
+ aliases: [string];
46
+ }>;
47
+ readonly watchDelay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
48
+ description: "The delay to wait for the watcher to trigger";
49
+ required: true;
50
+ default: 100;
51
+ aliases: [string];
52
+ }>;
53
+ readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
54
+ description: "Looks for changes only of the given extensions";
55
+ required: true;
56
+ default: never[];
57
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
58
+ aliases: [string];
59
+ }>;
60
+ readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
61
+ required: true;
62
+ default: never[];
63
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
64
+ description: "Ignore the given targets";
65
+ }>;
66
+ readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
67
+ required: true;
68
+ default: never[];
69
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
70
+ description: "Environment variables";
71
+ }>;
72
+ };
73
+ }>;
74
+ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProgram<"exec", {
75
+ readonly allowEqualAssign: true;
76
+ readonly booleanNotSyntaxEnding: "\\";
77
+ readonly allowDuplicateFlagForList: true;
78
+ readonly splitListByComma: true;
79
+ }, {
80
+ readonly help: true;
81
+ }, {
82
+ readonly description: "Execute a script with the given binary";
83
+ readonly arguments: [];
84
+ readonly optionalArguments: [];
85
+ readonly listArgument: {
86
+ readonly name: "args";
87
+ readonly description: "The arguments to pass to the script";
88
+ readonly type: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
89
+ };
90
+ readonly trailingArguments: "--";
91
+ readonly flags: {
92
+ readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
93
+ required: true;
94
+ default: string;
95
+ description: "The current working directory";
96
+ }>;
97
+ readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
98
+ description: "Clear the console before running the script";
99
+ required: true;
100
+ default: true;
101
+ aliases: [string];
102
+ }>;
103
+ readonly reload: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
104
+ description: "Reload the page when pressing \"Ctrl+R\" or \"Meta+R\"";
105
+ required: true;
106
+ default: true;
107
+ aliases: [string];
108
+ }>;
109
+ readonly watch: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
110
+ description: "Watch for changes";
111
+ required: true;
112
+ default: true;
113
+ aliases: [string];
114
+ }>;
115
+ readonly watchDelay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
116
+ description: "The delay to wait for the watcher to trigger";
117
+ required: true;
118
+ default: 100;
119
+ aliases: [string];
120
+ }>;
121
+ readonly ext: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
122
+ description: "Looks for changes only of the given extensions";
123
+ required: true;
124
+ default: never[];
125
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
126
+ aliases: [string];
127
+ }>;
128
+ readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
129
+ required: true;
130
+ default: never[];
131
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
132
+ description: "Ignore the given targets";
133
+ }>;
134
+ readonly env: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
135
+ required: true;
136
+ default: never[];
137
+ schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
138
+ description: "Environment variables";
139
+ }>;
140
+ };
141
+ globalFlags: {};
142
+ }>;
package/dist/arg.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exec = exports.app = void 0;
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' }));
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './index';
package/dist/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ require("./index");
5
+ const arg_1 = require("./arg");
6
+ arg_1.app.start();
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,23 @@
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 : []);
18
+ if (result.status === 1)
19
+ return false;
20
+ return true;
21
+ }
22
+ }
23
+ exports.default = ExecutionBin;
@@ -0,0 +1,3 @@
1
+ import ExecutionBin from './ExecutionBin';
2
+ declare const _default: ExecutionBin[];
3
+ export default _default;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ExecutionBin_1 = require("./ExecutionBin");
4
+ exports.default = [
5
+ new ExecutionBin_1.default({
6
+ name: 'Node.js',
7
+ command: 'node',
8
+ extensions: ['js', 'javascript', 'jsx', 'cjs', 'cjsx', 'mjs', 'mjsx'],
9
+ run(...args) {
10
+ return [this.command, ...args];
11
+ },
12
+ checkInstallationArgs: ['--version'],
13
+ howToInstall: () => {
14
+ console.log('Please install Node.js from https://nodejs.org/');
15
+ },
16
+ }),
17
+ new ExecutionBin_1.default({
18
+ name: 'TypeScript',
19
+ command: 'ts-node',
20
+ extensions: ['ts', 'tsx', 'cts', 'ctsx', 'mts', 'mtsx'],
21
+ run(...args) {
22
+ return [this.command, ...args];
23
+ },
24
+ checkInstallationArgs: ['--version'],
25
+ howToInstall: () => {
26
+ console.log('Please install ts-node from https://www.npmjs.com/package/ts-node');
27
+ },
28
+ }),
29
+ new ExecutionBin_1.default({
30
+ name: 'python',
31
+ command: 'python',
32
+ extensions: ['py'],
33
+ run(...args) {
34
+ return [this.command, ...args];
35
+ },
36
+ checkInstallationArgs: ['--version'],
37
+ howToInstall: () => {
38
+ console.log('Please install Python from https://www.python.org/');
39
+ },
40
+ }),
41
+ new ExecutionBin_1.default({
42
+ name: 'java',
43
+ command: 'java',
44
+ extensions: ['java'],
45
+ run(...args) {
46
+ return [this.command, ...args];
47
+ },
48
+ checkInstallationArgs: ['--version'],
49
+ howToInstall: () => {
50
+ console.log('Please install Java from https://www.oracle.com/java/');
51
+ },
52
+ }),
53
+ ];
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1,59 @@
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 exec();
16
+ if ((key.ctrl || key.meta) && key.name === 'r')
17
+ return exec();
18
+ if (key.ctrl && key.name === 'c') {
19
+ console.log('^C...');
20
+ process.exit(0);
21
+ }
22
+ });
23
+ }
24
+ if (options.watch) {
25
+ (0, watcher_1.default)(options.cwd, {
26
+ ignore: options.watchIgnore,
27
+ debounceDelay: options.watchDelay,
28
+ extensions: new Set(options.watchExtensions),
29
+ }, () => exec());
30
+ }
31
+ let child = null;
32
+ function exec() {
33
+ if (options.clearOnReload) {
34
+ process.stdout.write('\x1Bc');
35
+ console.clear();
36
+ }
37
+ if (child) {
38
+ child.removeAllListeners();
39
+ child.kill();
40
+ }
41
+ child = (0, cross_spawn_1.spawn)(command, args, {
42
+ argv0: command,
43
+ cwd: options.cwd,
44
+ stdio: 'inherit',
45
+ env: Object.assign({}, options.env),
46
+ });
47
+ child.on('error', console.error);
48
+ child.on('exit', (code) => {
49
+ if (code && code > 0) {
50
+ console.log('');
51
+ console.log(colors_1.default.red(`Process exited with code: ${colors_1.default.yellow(String(code))}`));
52
+ }
53
+ if (options.readlineReload) {
54
+ console.log(colors_1.default.blue.dim(`⟳ Press ${colors_1.default.yellow('F5')} or ${colors_1.default.yellow('^R')} to reload...`));
55
+ }
56
+ });
57
+ }
58
+ exec();
59
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const arg = require("./arg");
4
+ 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
+ }
22
+ 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));
39
+ }
40
+ arg.app.renderHelp();
41
+ });
42
+ arg.exec.on(([listArs, trailingArgs], flags) => {
43
+ (0, execute_1.default)([...listArs, ...trailingArgs], mapFlagsToOptions(flags));
44
+ });
@@ -0,0 +1,2 @@
1
+ import * as colors from 'ansi-colors';
2
+ export default colors;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const colors = require("ansi-colors");
4
+ exports.default = colors;
@@ -0,0 +1 @@
1
+ export declare function createDebounce(delay: number): (fn: Function) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDebounce = createDebounce;
4
+ function createDebounce(delay) {
5
+ let debounceTimeout;
6
+ return function (fn) {
7
+ clearTimeout(debounceTimeout);
8
+ debounceTimeout = setTimeout(() => fn(), delay);
9
+ };
10
+ }
@@ -0,0 +1 @@
1
+ export default function (baseDir: string, extraIgnore?: string[]): import("ignore").Ignore;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const ignore_1 = require("ignore");
7
+ function default_1(baseDir, extraIgnore = []) {
8
+ const gitignorePath = path.resolve(path.join(baseDir, '.gitignore'));
9
+ const ig = (0, ignore_1.default)({ ignorecase: true }).add(extraIgnore);
10
+ if (fs.existsSync(gitignorePath)) {
11
+ return ig.add(fs.readFileSync(gitignorePath).toString());
12
+ }
13
+ return ig;
14
+ }
@@ -0,0 +1,6 @@
1
+ export type WatcherOptions = {
2
+ ignore: string[];
3
+ extensions: Set<string>;
4
+ debounceDelay: number;
5
+ };
6
+ export default function (dir: string, options: WatcherOptions, callback: () => void): void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const path = require("path");
5
+ const chokidar = require("chokidar");
6
+ const gitignore_1 = require("./gitignore");
7
+ const debounce_1 = require("../utils/debounce");
8
+ function default_1(dir, options, callback) {
9
+ const ig = (0, gitignore_1.default)(dir, options.ignore);
10
+ const debounce = (0, debounce_1.createDebounce)(options.debounceDelay);
11
+ const watcher = chokidar.watch(dir, {
12
+ ignored: (filePath) => {
13
+ const relativePath = path.relative(dir, filePath);
14
+ if (!relativePath)
15
+ return false;
16
+ if (ig.ignores(relativePath))
17
+ return true;
18
+ if (options.extensions.size) {
19
+ const ext = path.extname(relativePath).slice(1);
20
+ if (ext && !options.extensions.has(ext))
21
+ return true;
22
+ }
23
+ return false;
24
+ },
25
+ interval: options.debounceDelay / 2,
26
+ persistent: true,
27
+ ignoreInitial: true,
28
+ });
29
+ watcher.on('add', (event) => {
30
+ debounce(() => callback());
31
+ });
32
+ watcher.on('change', (event) => {
33
+ debounce(() => callback());
34
+ });
35
+ watcher.on('unlink', () => {
36
+ debounce(() => callback());
37
+ });
38
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "uni-run",
3
+ "description": "Universal Runner for many language",
4
+ "version": "0.0.0",
5
+ "type": "commonjs",
6
+ "scripts": {
7
+ "ts": "w ./src/__lab__/index.ts",
8
+ "js": "n ./dist/__lab__/index.js",
9
+ "dev": "tsc --watch",
10
+ "build": "node ./build.cjs"
11
+ },
12
+ "bin": {
13
+ "ur": "./dist/bin.js",
14
+ "uni-run": "./dist/bin.js"
15
+ },
16
+ "dependencies": {
17
+ "ansi-colors": "^4.1.3",
18
+ "chokidar": "^3.6.0",
19
+ "cross-spawn": "^7.0.3",
20
+ "ignore": "^5.3.2",
21
+ "noarg": "^3.0.21"
22
+ },
23
+ "devDependencies": {
24
+ "@types/cross-spawn": "^6.0.6",
25
+ "typescript": "^5.5.4"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/NazmusSayad/uni-run"
30
+ }
31
+ }