rman 0.0.4 → 0.1.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/README.md +22 -90
- package/bin/debug.ts +1 -1
- package/bin/rman.js +1 -1
- package/cjs/cli.js +67 -0
- package/{dist → cjs}/index.js +0 -0
- package/cjs/package.json +3 -0
- package/cjs/workspace/executor.js +114 -0
- package/{dist → cjs}/workspace/package.js +1 -1
- package/{dist → cjs}/workspace/providers/npm-provider.js +2 -2
- package/{dist → cjs}/workspace/types.js +0 -0
- package/{dist → cjs}/workspace/utils.js +0 -0
- package/cjs/workspace/workspace.js +245 -0
- package/{dist → esm}/cli.d.ts +0 -0
- package/esm/cli.mjs +60 -0
- package/{dist → esm}/index.d.ts +0 -0
- package/esm/index.mjs +1 -0
- package/{dist → esm}/workspace/executor.d.ts +0 -0
- package/esm/workspace/executor.mjs +107 -0
- package/{dist → esm}/workspace/package.d.ts +0 -0
- package/esm/workspace/package.mjs +36 -0
- package/{dist → esm}/workspace/providers/npm-provider.d.ts +0 -0
- package/esm/workspace/providers/npm-provider.mjs +12 -0
- package/{dist → esm}/workspace/types.d.ts +0 -0
- package/esm/workspace/types.mjs +1 -0
- package/{dist → esm}/workspace/utils.d.ts +0 -0
- package/esm/workspace/utils.mjs +22 -0
- package/{dist → esm}/workspace/workspace.d.ts +3 -3
- package/esm/workspace/workspace.mjs +238 -0
- package/package.json +27 -14
- package/dist/cli.js +0 -71
- package/dist/workspace/executor.js +0 -120
- package/dist/workspace/workspace.js +0 -240
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import npmRubPath from 'npm-run-path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { onProcessExit } from './utils.mjs';
|
|
5
|
+
const runningChildren = new Map();
|
|
6
|
+
export async function executeCommand(command, options) {
|
|
7
|
+
const opts = {
|
|
8
|
+
...options
|
|
9
|
+
};
|
|
10
|
+
opts.env = {
|
|
11
|
+
...npmRubPath.env({ cwd: options?.cwd }),
|
|
12
|
+
// FORCE_COLOR: `${chalk.level}`,
|
|
13
|
+
...opts.env
|
|
14
|
+
};
|
|
15
|
+
opts.cwd = opts.cwd || process.cwd();
|
|
16
|
+
opts.color = opts.color == null ? true : opts.color;
|
|
17
|
+
const spawnOptions = {
|
|
18
|
+
stdio: opts.stdio || 'pipe',
|
|
19
|
+
env: opts.env,
|
|
20
|
+
cwd: opts.cwd,
|
|
21
|
+
shell: options?.shell,
|
|
22
|
+
windowsHide: true
|
|
23
|
+
};
|
|
24
|
+
const result = {
|
|
25
|
+
code: undefined,
|
|
26
|
+
stderr: '',
|
|
27
|
+
stdout: ''
|
|
28
|
+
};
|
|
29
|
+
const buffer = {
|
|
30
|
+
stdout: '',
|
|
31
|
+
stderr: ''
|
|
32
|
+
};
|
|
33
|
+
const processData = (data, stdio) => {
|
|
34
|
+
buffer[stdio] += data;
|
|
35
|
+
result[stdio] += data;
|
|
36
|
+
if (opts.onData)
|
|
37
|
+
opts.onData(data, stdio);
|
|
38
|
+
};
|
|
39
|
+
const processLines = (stdio, flush) => {
|
|
40
|
+
let chunk = buffer[stdio];
|
|
41
|
+
let i;
|
|
42
|
+
if (flush && !chunk.endsWith('\n'))
|
|
43
|
+
chunk += '\n';
|
|
44
|
+
while ((i = chunk.indexOf('\n')) >= 0) {
|
|
45
|
+
const line = chunk.substring(0, i);
|
|
46
|
+
chunk = chunk.substring(i + 1);
|
|
47
|
+
if (opts.onLine)
|
|
48
|
+
opts.onLine(line, stdio);
|
|
49
|
+
}
|
|
50
|
+
buffer[stdio] = chunk;
|
|
51
|
+
};
|
|
52
|
+
const child = spawn(command, opts.argv || [], spawnOptions);
|
|
53
|
+
if (child.pid) {
|
|
54
|
+
runningChildren.set(child.pid, child);
|
|
55
|
+
if (opts.onSpawn)
|
|
56
|
+
opts.onSpawn(child);
|
|
57
|
+
}
|
|
58
|
+
child.stdout?.on('data', (data) => {
|
|
59
|
+
processData(data, 'stdout');
|
|
60
|
+
processLines('stdout');
|
|
61
|
+
});
|
|
62
|
+
child.stderr?.on('data', (data) => {
|
|
63
|
+
processData(data, 'stderr');
|
|
64
|
+
processLines('stderr');
|
|
65
|
+
});
|
|
66
|
+
return new Promise(resolve => {
|
|
67
|
+
let resolved;
|
|
68
|
+
child.on('error', (err) => {
|
|
69
|
+
if (child.pid)
|
|
70
|
+
runningChildren.delete(child.pid);
|
|
71
|
+
processLines('stdout', true);
|
|
72
|
+
processLines('stderr', true);
|
|
73
|
+
if (resolved)
|
|
74
|
+
return;
|
|
75
|
+
result.code = err.code || 1;
|
|
76
|
+
result.error = err;
|
|
77
|
+
if (!result.error) {
|
|
78
|
+
const text = `Command failed (${result.code})`;
|
|
79
|
+
result.error =
|
|
80
|
+
new Error((opts.color ? chalk.red(text) : text) + '\n ' +
|
|
81
|
+
opts.color ? chalk.white(err.message) : err.message);
|
|
82
|
+
}
|
|
83
|
+
resolved = true;
|
|
84
|
+
resolve(result);
|
|
85
|
+
});
|
|
86
|
+
child.on('close', (code) => {
|
|
87
|
+
if (child.pid)
|
|
88
|
+
runningChildren.delete(child.pid);
|
|
89
|
+
processLines('stdout', true);
|
|
90
|
+
processLines('stderr', true);
|
|
91
|
+
if (resolved)
|
|
92
|
+
return;
|
|
93
|
+
result.code = code;
|
|
94
|
+
resolved = true;
|
|
95
|
+
if (code) {
|
|
96
|
+
const text = `Command failed (${result.code})`;
|
|
97
|
+
result.error = new Error((opts.color ? chalk.red(text) : text));
|
|
98
|
+
}
|
|
99
|
+
return resolve(result);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
onProcessExit(() => {
|
|
104
|
+
runningChildren.forEach((child) => {
|
|
105
|
+
child.kill();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import parseNpmScript from '@netlify/parse-npm-script';
|
|
2
|
+
export class Package {
|
|
3
|
+
constructor(dirname, def) {
|
|
4
|
+
this.dirname = dirname;
|
|
5
|
+
this.dependencies = [];
|
|
6
|
+
Object.defineProperty(this, 'def', {
|
|
7
|
+
enumerable: false,
|
|
8
|
+
value: def,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return this.def.name;
|
|
13
|
+
}
|
|
14
|
+
getScriptCommands(script) {
|
|
15
|
+
const result = [];
|
|
16
|
+
let scriptInfo;
|
|
17
|
+
try {
|
|
18
|
+
scriptInfo = parseNpmScript(this.def, 'npm run ' + script);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
if (scriptInfo && scriptInfo.raw)
|
|
24
|
+
for (const step of scriptInfo.steps) {
|
|
25
|
+
const parsed = Array.isArray(step.parsed) ? step.parsed : [step.parsed];
|
|
26
|
+
for (const cmd of parsed) {
|
|
27
|
+
result.push({
|
|
28
|
+
name: cmd.split(' ')[0],
|
|
29
|
+
command: cmd,
|
|
30
|
+
step: step.name
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getPackageJson } from './../utils.mjs';
|
|
2
|
+
export class NpmProvider {
|
|
3
|
+
parse(root) {
|
|
4
|
+
const pkg = getPackageJson(root);
|
|
5
|
+
if (pkg && typeof pkg.workspaces === 'object') {
|
|
6
|
+
if (Array.isArray(pkg.workspaces))
|
|
7
|
+
return { root, packages: pkg.workspaces };
|
|
8
|
+
if (Array.isArray(pkg.workspaces.packages))
|
|
9
|
+
return { root, packages: pkg.workspaces.packages };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
export function getPackageJson(dirname) {
|
|
4
|
+
const f = path.resolve(dirname, 'package.json');
|
|
5
|
+
if (!fs.existsSync(f))
|
|
6
|
+
return;
|
|
7
|
+
return JSON.parse(fs.readFileSync(f, 'utf-8'));
|
|
8
|
+
}
|
|
9
|
+
export function onProcessExit(listener, forceExit = true) {
|
|
10
|
+
["SIGTERM", "SIGINT"].forEach((event) => process.once(event, (signal) => {
|
|
11
|
+
listener(signal);
|
|
12
|
+
if (forceExit)
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}));
|
|
15
|
+
process.once("exit", () => listener("exit"));
|
|
16
|
+
}
|
|
17
|
+
export function setFind(set, cb) {
|
|
18
|
+
for (const e of set) {
|
|
19
|
+
if (cb(e))
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IRunScriptOptions } from './executor
|
|
2
|
-
import { Package, RunScriptResult } from './package
|
|
3
|
-
import { IWorkspaceOptions } from './types
|
|
1
|
+
import { IRunScriptOptions } from './executor';
|
|
2
|
+
import { Package, RunScriptResult } from './package';
|
|
3
|
+
import { IWorkspaceOptions } from './types';
|
|
4
4
|
export declare class Workspace {
|
|
5
5
|
readonly root: string;
|
|
6
6
|
private _options;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import glob from 'fast-glob';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { MultiBar, Presets } from 'cli-progress';
|
|
6
|
+
import { getPackageJson, setFind } from './utils.mjs';
|
|
7
|
+
import { executeCommand } from './executor.mjs';
|
|
8
|
+
import { Package } from './package.mjs';
|
|
9
|
+
import { NpmProvider } from './providers/npm-provider.mjs';
|
|
10
|
+
const providers = [
|
|
11
|
+
new NpmProvider()
|
|
12
|
+
];
|
|
13
|
+
export class Workspace {
|
|
14
|
+
constructor(root, packages, options) {
|
|
15
|
+
this.root = root;
|
|
16
|
+
this._options = { ...options };
|
|
17
|
+
this._packages = packages;
|
|
18
|
+
this._determineDependencies();
|
|
19
|
+
this._sortPackages();
|
|
20
|
+
}
|
|
21
|
+
get packages() {
|
|
22
|
+
return this._packages;
|
|
23
|
+
}
|
|
24
|
+
getPackage(name) {
|
|
25
|
+
return this.packages.find(p => p.name === name);
|
|
26
|
+
}
|
|
27
|
+
async runScript(script, options = {}) {
|
|
28
|
+
const packages = {};
|
|
29
|
+
const result = {
|
|
30
|
+
script,
|
|
31
|
+
errorCount: 0,
|
|
32
|
+
commands: []
|
|
33
|
+
};
|
|
34
|
+
options.gauge = options.gauge == null ? true : options.gauge;
|
|
35
|
+
let totalCommands = 0;
|
|
36
|
+
for (const p of this.packages) {
|
|
37
|
+
const commands = p.getScriptCommands(script);
|
|
38
|
+
totalCommands += commands.length;
|
|
39
|
+
packages[p.name] = {
|
|
40
|
+
package: p,
|
|
41
|
+
commands: [...commands]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!totalCommands)
|
|
45
|
+
return result;
|
|
46
|
+
let overallProgress;
|
|
47
|
+
const progressBars = options.gauge && new MultiBar({
|
|
48
|
+
format: '[' + chalk.cyan('{bar}') + '] {percentage}% | {value}/{total} | ' +
|
|
49
|
+
chalk.yellowBright('{package}') + ' | ' + chalk.yellow('{command}'),
|
|
50
|
+
barsize: 30,
|
|
51
|
+
hideCursor: true,
|
|
52
|
+
barCompleteChar: '\u2588',
|
|
53
|
+
barIncompleteChar: '\u2591',
|
|
54
|
+
}, Presets.rect);
|
|
55
|
+
if (progressBars) {
|
|
56
|
+
overallProgress = progressBars.create(totalCommands, 0);
|
|
57
|
+
overallProgress.start(totalCommands, 0, { package: '=== OVERALL ===', command: '' });
|
|
58
|
+
for (const p of Object.values(packages)) {
|
|
59
|
+
if (p.commands.length) {
|
|
60
|
+
p.progress = progressBars.create(p.commands.length, 0);
|
|
61
|
+
p.progress.start(p.commands.length, 0, {
|
|
62
|
+
package: p.name,
|
|
63
|
+
command: 'Waiting'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const t = Date.now();
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const remaining = new Set(Object.keys(packages));
|
|
71
|
+
const runScripts = () => {
|
|
72
|
+
for (const pkgName of remaining) {
|
|
73
|
+
const pkgInfo = packages[pkgName];
|
|
74
|
+
const pkg = pkgInfo.package;
|
|
75
|
+
const progress = pkgInfo.progress;
|
|
76
|
+
for (let k = 0; k < pkgInfo.commands.length; k++) {
|
|
77
|
+
const cmd = pkgInfo.commands[k];
|
|
78
|
+
if (cmd.status === 'running')
|
|
79
|
+
break;
|
|
80
|
+
if (!cmd.status) {
|
|
81
|
+
const concurrent = cmd.step.startsWith('pre');
|
|
82
|
+
if (!concurrent &&
|
|
83
|
+
pkg.dependencies.find(dep => setFind(remaining, p => p === dep))) {
|
|
84
|
+
cmd.status = '';
|
|
85
|
+
if (progress)
|
|
86
|
+
progress.update({ command: chalk.bgYellow.white('Waiting dependencies') });
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
cmd.status = 'running';
|
|
90
|
+
if (progress)
|
|
91
|
+
progress.update({ command: cmd.name });
|
|
92
|
+
else
|
|
93
|
+
console.log('[' + chalk.whiteBright(pkg.name) + '] ' +
|
|
94
|
+
chalk.yellow(cmd.command), (chalk.cyanBright(' +' + (Date.now() - t))));
|
|
95
|
+
void executeCommand(cmd.command, {
|
|
96
|
+
...options,
|
|
97
|
+
cwd: pkg.dirname,
|
|
98
|
+
shell: true
|
|
99
|
+
}).then(r => {
|
|
100
|
+
if (overallProgress)
|
|
101
|
+
overallProgress.increment(1);
|
|
102
|
+
if (progress)
|
|
103
|
+
progress.increment(1);
|
|
104
|
+
const cr = {
|
|
105
|
+
package: pkg.name,
|
|
106
|
+
command: cmd,
|
|
107
|
+
code: r.code || 1,
|
|
108
|
+
error: r.error,
|
|
109
|
+
stdout: r.stdout,
|
|
110
|
+
stderr: r.stderr
|
|
111
|
+
};
|
|
112
|
+
result.code = result.code || r.code;
|
|
113
|
+
if (r.error)
|
|
114
|
+
result.errorCount++;
|
|
115
|
+
result.commands.push(cr);
|
|
116
|
+
cmd.status = 'done';
|
|
117
|
+
if (r.error || k === pkgInfo.commands.length - 1) {
|
|
118
|
+
if (progress) {
|
|
119
|
+
if (r.error)
|
|
120
|
+
progress.update({ command: chalk.yellow(cmd.name) + chalk.red(' Filed!') });
|
|
121
|
+
else
|
|
122
|
+
progress.update({ command: chalk.green(' Completed!') });
|
|
123
|
+
}
|
|
124
|
+
remaining.delete(pkg.name);
|
|
125
|
+
}
|
|
126
|
+
if (!remaining.size) {
|
|
127
|
+
if (progressBars)
|
|
128
|
+
progressBars.stop();
|
|
129
|
+
return resolve(result);
|
|
130
|
+
}
|
|
131
|
+
if (!result.errorCount)
|
|
132
|
+
setTimeout(runScripts, 1);
|
|
133
|
+
});
|
|
134
|
+
if (!concurrent)
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
runScripts();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
static create(root, options) {
|
|
144
|
+
root = root || process.cwd();
|
|
145
|
+
let deep = options?.deep || 0;
|
|
146
|
+
while (deep-- >= 0 && fs.existsSync(root)) {
|
|
147
|
+
for (let i = providers.length - 1; i >= 0; i--) {
|
|
148
|
+
const provider = providers[i];
|
|
149
|
+
const inf = provider.parse(root);
|
|
150
|
+
if (!inf)
|
|
151
|
+
continue;
|
|
152
|
+
const pkgJson = getPackageJson(inf.root);
|
|
153
|
+
if (!pkgJson)
|
|
154
|
+
continue;
|
|
155
|
+
const packages = [];
|
|
156
|
+
for (const pattern of inf.packages) {
|
|
157
|
+
const dirs = glob.sync(pattern, {
|
|
158
|
+
cwd: inf.root,
|
|
159
|
+
absolute: true,
|
|
160
|
+
deep: 0,
|
|
161
|
+
onlyDirectories: true
|
|
162
|
+
});
|
|
163
|
+
for (const dir of dirs) {
|
|
164
|
+
const p = detectPackage(dir);
|
|
165
|
+
if (p && !packages.find(x => x.name === p.name))
|
|
166
|
+
packages.push(p);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return new Workspace(inf.root, packages, pkgJson.rman);
|
|
170
|
+
}
|
|
171
|
+
root = path.resolve(root, '..');
|
|
172
|
+
}
|
|
173
|
+
throw new Error('No project workspace detected');
|
|
174
|
+
}
|
|
175
|
+
_determineDependencies() {
|
|
176
|
+
const deps = {};
|
|
177
|
+
for (const pkg of this.packages) {
|
|
178
|
+
const o = {
|
|
179
|
+
...pkg.def.dependencies,
|
|
180
|
+
...pkg.def.devDependencies,
|
|
181
|
+
...pkg.def.peerDependencies,
|
|
182
|
+
...pkg.def.optionalDependencies
|
|
183
|
+
};
|
|
184
|
+
const dependencies = [];
|
|
185
|
+
for (const k of Object.keys(o)) {
|
|
186
|
+
const p = this.getPackage(k);
|
|
187
|
+
if (p)
|
|
188
|
+
dependencies.push(k);
|
|
189
|
+
}
|
|
190
|
+
deps[pkg.name] = dependencies;
|
|
191
|
+
pkg.dependencies = dependencies;
|
|
192
|
+
}
|
|
193
|
+
let circularCheck;
|
|
194
|
+
const deepFindDependencies = (pkg, target) => {
|
|
195
|
+
if (circularCheck.includes(pkg.name))
|
|
196
|
+
return;
|
|
197
|
+
circularCheck.push(pkg.name);
|
|
198
|
+
for (const s of pkg.dependencies) {
|
|
199
|
+
if (!target.includes(s)) {
|
|
200
|
+
target.push(s);
|
|
201
|
+
const p = this.getPackage(s);
|
|
202
|
+
if (p) {
|
|
203
|
+
deepFindDependencies(p, target);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
for (const pkg of this.packages) {
|
|
209
|
+
circularCheck = [];
|
|
210
|
+
deepFindDependencies(pkg, pkg.dependencies);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
_sortPackages() {
|
|
214
|
+
const packages = [...this.packages];
|
|
215
|
+
const packageOrder = this._options.packageOrder;
|
|
216
|
+
packages.sort((a, b) => {
|
|
217
|
+
if (packageOrder) {
|
|
218
|
+
const a1 = packageOrder.indexOf(a.name);
|
|
219
|
+
const b1 = packageOrder.indexOf(b.name);
|
|
220
|
+
const i = (a1 >= 0 ? a1 : Number.MAX_SAFE_INTEGER) - (b1 >= 0 ? b1 : Number.MAX_SAFE_INTEGER);
|
|
221
|
+
if (i !== 0)
|
|
222
|
+
return i;
|
|
223
|
+
}
|
|
224
|
+
if (b.dependencies.includes(a.name))
|
|
225
|
+
return -1;
|
|
226
|
+
if (a.dependencies.includes(b.name))
|
|
227
|
+
return 1;
|
|
228
|
+
return 0;
|
|
229
|
+
});
|
|
230
|
+
this._packages = packages;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function detectPackage(dirname) {
|
|
234
|
+
const pkgJson = getPackageJson(dirname);
|
|
235
|
+
if (pkgJson && pkgJson.name) {
|
|
236
|
+
return new Package(dirname, pkgJson);
|
|
237
|
+
}
|
|
238
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rman",
|
|
3
3
|
"description": "Monorepo repository manager",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"contributors": [
|
|
@@ -22,23 +22,30 @@
|
|
|
22
22
|
"bin": {
|
|
23
23
|
"rman": "bin/rman.js"
|
|
24
24
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "cjs/index.js",
|
|
27
|
+
"module": "esm/index.mjs",
|
|
28
|
+
"types": "esm/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./cjs/index.js",
|
|
31
|
+
"./cjs": "./cjs/index.js",
|
|
32
|
+
"./esm": "./esm/index.mjs"
|
|
33
|
+
},
|
|
27
34
|
"dependencies": {
|
|
35
|
+
"@netlify/parse-npm-script": "^0.1.2",
|
|
28
36
|
"chalk": "^4.1.2",
|
|
37
|
+
"cli-progress": "^3.9.1",
|
|
29
38
|
"commander": "^8.3.0",
|
|
30
39
|
"fast-glob": "^3.2.7",
|
|
31
|
-
"npm-run-path": "^4.0.1"
|
|
32
|
-
"@netlify/parse-npm-script": "^0.1.2",
|
|
33
|
-
"cli-progress": "^3.9.1"
|
|
40
|
+
"npm-run-path": "^4.0.1"
|
|
34
41
|
},
|
|
35
42
|
"devDependencies": {
|
|
43
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
44
|
+
"@types/cli-progress": "^3.9.2",
|
|
36
45
|
"@types/mocha": "^9.0.0",
|
|
37
46
|
"@types/node": "^16.4.8",
|
|
38
|
-
"@types/cli-progress": "^3.9.2",
|
|
39
47
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
40
48
|
"@typescript-eslint/parser": "^5.0.0",
|
|
41
|
-
"@babel/eslint-parser": "^7.16.3",
|
|
42
49
|
"eslint": "^8.0.0",
|
|
43
50
|
"eslint-config-google": "^0.14.0",
|
|
44
51
|
"mocha": "^9.0.1",
|
|
@@ -47,14 +54,17 @@
|
|
|
47
54
|
"ts-loader": "^9.0.0",
|
|
48
55
|
"ts-node": "^10.0.0",
|
|
49
56
|
"tsconfig-paths": "^3.9.0",
|
|
50
|
-
"typescript": "^4.5.2"
|
|
57
|
+
"typescript": "^4.5.2",
|
|
58
|
+
"typescript-esm": "^2.0.0"
|
|
51
59
|
},
|
|
52
60
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
61
|
+
"node": ">=14.0",
|
|
62
|
+
"npm": ">=7.0.0"
|
|
54
63
|
},
|
|
55
64
|
"files": [
|
|
56
|
-
"dist/",
|
|
57
65
|
"bin/",
|
|
66
|
+
"cjs/",
|
|
67
|
+
"esm/",
|
|
58
68
|
"LICENSE",
|
|
59
69
|
"README.md"
|
|
60
70
|
],
|
|
@@ -62,10 +72,13 @@
|
|
|
62
72
|
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register --reporter spec test/**/*.spec.ts",
|
|
63
73
|
"cover": "nyc --reporter=cobertura --reporter html --reporter text npm run test",
|
|
64
74
|
"clean": "npm run clean:src && npm run clean:dist",
|
|
65
|
-
"clean:dist": "
|
|
75
|
+
"clean:dist": "rimraf cjs esm",
|
|
66
76
|
"clean:src": "ts-cleanup -s src --all | ts-cleanup -s test",
|
|
67
|
-
"prebuild": "npm run clean && npm run lint",
|
|
68
|
-
"build": "
|
|
77
|
+
"prebuild": "npm run clean:dist && npm run lint",
|
|
78
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
79
|
+
"build:cjs": "tsc -b tsconfig.build-cjs.json",
|
|
80
|
+
"build:esm": "tsc -b tsconfig.build-esm.json && tsc-esm -p tsconfig.build-esm.json",
|
|
81
|
+
"postbuild": "cp ./src/package.cjs.json ./cjs/package.json",
|
|
69
82
|
"compile": "tsc -b tsconfig.json",
|
|
70
83
|
"lint": "eslint src/** --no-error-on-unmatched-pattern",
|
|
71
84
|
"travis-cover": "nyc --reporter lcovonly npm run test"
|
package/dist/cli.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.run = void 0;
|
|
16
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
-
const url_1 = require("url");
|
|
18
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
-
const commander_1 = require("commander");
|
|
20
|
-
const workspace_js_1 = require("./workspace/workspace.js");
|
|
21
|
-
function run(argv = process.argv) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const pkgJson = JSON.parse(yield promises_1.default.readFile(new url_1.URL('../package.json', __dirname), 'utf-8'));
|
|
24
|
-
commander_1.program.version(pkgJson.version || '');
|
|
25
|
-
commander_1.program
|
|
26
|
-
.command('run <script>')
|
|
27
|
-
.description('Executes given script for every package in repository')
|
|
28
|
-
.action((script) => __awaiter(this, void 0, void 0, function* () { return runScript(script); }))
|
|
29
|
-
.allowUnknownOption();
|
|
30
|
-
commander_1.program
|
|
31
|
-
.command('build')
|
|
32
|
-
.description('Executes "build" script for every package in repository')
|
|
33
|
-
.action(() => __awaiter(this, void 0, void 0, function* () { return runScript('build'); }))
|
|
34
|
-
.allowUnknownOption();
|
|
35
|
-
commander_1.program
|
|
36
|
-
.command('lint')
|
|
37
|
-
.description('Executes "lint" script for every package in repository')
|
|
38
|
-
.action(() => __awaiter(this, void 0, void 0, function* () { return runScript('lint'); }))
|
|
39
|
-
.allowUnknownOption();
|
|
40
|
-
commander_1.program
|
|
41
|
-
.command('test')
|
|
42
|
-
.description('Executes "test" script for every package in repository')
|
|
43
|
-
.action(() => __awaiter(this, void 0, void 0, function* () { return runScript('lint'); }))
|
|
44
|
-
.allowUnknownOption();
|
|
45
|
-
commander_1.program.parse(argv);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
exports.run = run;
|
|
49
|
-
function runScript(script) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const workspace = workspace_js_1.Workspace.create();
|
|
52
|
-
const result = yield workspace.runScript(script, {
|
|
53
|
-
gauge: true
|
|
54
|
-
});
|
|
55
|
-
if (result.errorCount) {
|
|
56
|
-
console.error('\n' + chalk_1.default.yellow(result.errorCount) + chalk_1.default.white(' error(s)'));
|
|
57
|
-
let s = '';
|
|
58
|
-
for (let i = 0; i < result.commands.length; i++) {
|
|
59
|
-
const cmd = result.commands[i];
|
|
60
|
-
if (cmd.error) {
|
|
61
|
-
s += '\n' + (i + 1) + ') ' +
|
|
62
|
-
chalk_1.default.cyanBright(cmd.package) + '\n' +
|
|
63
|
-
chalk_1.default.white(cmd.command) + '\n' +
|
|
64
|
-
chalk_1.default.red('Error: ' + cmd.error.message) + '\n' +
|
|
65
|
-
chalk_1.default.red(cmd.stderr) + '\n';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
console.error(s);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|