runallx 1.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.
Files changed (3) hide show
  1. package/bin/runallx.js +73 -0
  2. package/package.json +36 -0
  3. package/readme.md +16 -0
package/bin/runallx.js ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync } from 'fs';
4
+ import { spawn } from 'child_process';
5
+ import path from 'path';
6
+ import process from 'process';
7
+ import readline from 'readline';
8
+
9
+ if (process.argv.length < 4) {
10
+ console.error('Usage: runall <npm|yarn|pnpm> <script1> [script2 ...]');
11
+ process.exit(1);
12
+ }
13
+
14
+ const pm = process.argv[2];
15
+ const scriptNames = process.argv.slice(3);
16
+
17
+ if (!['yarn', 'npm', 'pnpm'].includes(pm)) {
18
+ console.error(`runall: unsupported package manager "${pm}"`);
19
+ process.exit(1);
20
+ }
21
+
22
+ const pkgPath = path.resolve(process.cwd(), 'package.json');
23
+ let pkg;
24
+ try {
25
+ pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
26
+ } catch {
27
+ console.error('runall: cannot find package.json in current directory');
28
+ process.exit(1);
29
+ }
30
+
31
+ const scripts = pkg.scripts || {};
32
+
33
+ for (const name of scriptNames) {
34
+ if (!scripts[name]) {
35
+ console.error(`runall: script "${name}" not found in package.json`);
36
+ process.exit(1);
37
+ }
38
+ }
39
+
40
+ console.log(`runall: using package manager "${pm}"`);
41
+ console.log(`runall: starting ${scriptNames.join(', ')}`);
42
+
43
+ const children = [];
44
+
45
+ scriptNames.forEach((name) => {
46
+ const args = pm === 'npm' ? ['run', name] : [name];
47
+
48
+ const child = spawn(pm, args, {
49
+ shell: true,
50
+ stdio: ['ignore', 'pipe', 'pipe'],
51
+ env: process.env,
52
+ });
53
+
54
+ readline.createInterface({ input: child.stdout }).on('line', (line) => {
55
+ console.log(`[${name}] ${line}`);
56
+ });
57
+
58
+ readline.createInterface({ input: child.stderr }).on('line', (line) => {
59
+ console.error(`[${name}] ${line}`);
60
+ });
61
+
62
+ child.on('exit', (code) => {
63
+ console.log(`[${name}] exited with code ${code}`);
64
+ });
65
+
66
+ children.push(child);
67
+ });
68
+
69
+ process.on('SIGINT', () => {
70
+ console.log('\nrunall: stopping all processes...');
71
+ children.forEach((c) => c.kill('SIGINT'));
72
+ process.exit(0);
73
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "runallx",
3
+ "version": "1.0.0",
4
+ "description": "run all package.json",
5
+ "keywords": [
6
+ "cli",
7
+ "npm",
8
+ "yarn",
9
+ "pnpm",
10
+ "scripts",
11
+ "parallel",
12
+ "runallx"
13
+ ],
14
+ "homepage": "https://github.com/tianxidev/runallx#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/tianxidev/runallx/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/tianxidev/runallx.git"
21
+ },
22
+ "license": "MIT",
23
+ "engines": {
24
+ "node": ">=14"
25
+ },
26
+ "author": "Terenna",
27
+ "type": "module",
28
+ "main": "index.js",
29
+ "bin": {
30
+ "runallx": "bin/runallx.js"
31
+ },
32
+ "scripts": {
33
+ "runallx": "node bin/runallx.js",
34
+ "test": "echo \"Error: no test specified\" && exit 1"
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,16 @@
1
+ # RUNALL
2
+
3
+ ## example
4
+
5
+ ```package.json
6
+ "scripts": {
7
+ "dev-api": "cross-env NODE_ENV=development nodemon --exec ts-node src/api.ts",
8
+ "dev-tcp": "cross-env NODE_ENV=development nodemon --exec ts-node src/tcp.ts",
9
+ }
10
+ ```
11
+
12
+ **run**
13
+ ```
14
+ runallx yarn dev-api dev-tcp
15
+ ```
16
+