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
|
@@ -1,120 +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.executeCommand = void 0;
|
|
16
|
-
const child_process_1 = require("child_process");
|
|
17
|
-
const npm_run_path_1 = __importDefault(require("npm-run-path"));
|
|
18
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
-
const utils_js_1 = require("./utils.js");
|
|
20
|
-
const runningChildren = new Map();
|
|
21
|
-
function executeCommand(command, options) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const opts = Object.assign({}, options);
|
|
25
|
-
opts.env = Object.assign(Object.assign({}, npm_run_path_1.default.env({ cwd: options === null || options === void 0 ? void 0 : options.cwd })), opts.env);
|
|
26
|
-
opts.cwd = opts.cwd || process.cwd();
|
|
27
|
-
opts.color = opts.color == null ? true : opts.color;
|
|
28
|
-
const spawnOptions = {
|
|
29
|
-
stdio: opts.stdio || 'pipe',
|
|
30
|
-
env: opts.env,
|
|
31
|
-
cwd: opts.cwd,
|
|
32
|
-
shell: options === null || options === void 0 ? void 0 : options.shell,
|
|
33
|
-
windowsHide: true
|
|
34
|
-
};
|
|
35
|
-
const result = {
|
|
36
|
-
code: undefined,
|
|
37
|
-
stderr: '',
|
|
38
|
-
stdout: ''
|
|
39
|
-
};
|
|
40
|
-
const buffer = {
|
|
41
|
-
stdout: '',
|
|
42
|
-
stderr: ''
|
|
43
|
-
};
|
|
44
|
-
const processData = (data, stdio) => {
|
|
45
|
-
buffer[stdio] += data;
|
|
46
|
-
result[stdio] += data;
|
|
47
|
-
if (opts.onData)
|
|
48
|
-
opts.onData(data, stdio);
|
|
49
|
-
};
|
|
50
|
-
const processLines = (stdio, flush) => {
|
|
51
|
-
let chunk = buffer[stdio];
|
|
52
|
-
let i;
|
|
53
|
-
if (flush && !chunk.endsWith('\n'))
|
|
54
|
-
chunk += '\n';
|
|
55
|
-
while ((i = chunk.indexOf('\n')) >= 0) {
|
|
56
|
-
const line = chunk.substring(0, i);
|
|
57
|
-
chunk = chunk.substring(i + 1);
|
|
58
|
-
if (opts.onLine)
|
|
59
|
-
opts.onLine(line, stdio);
|
|
60
|
-
}
|
|
61
|
-
buffer[stdio] = chunk;
|
|
62
|
-
};
|
|
63
|
-
const child = (0, child_process_1.spawn)(command, opts.argv || [], spawnOptions);
|
|
64
|
-
if (child.pid) {
|
|
65
|
-
runningChildren.set(child.pid, child);
|
|
66
|
-
if (opts.onSpawn)
|
|
67
|
-
opts.onSpawn(child);
|
|
68
|
-
}
|
|
69
|
-
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
70
|
-
processData(data, 'stdout');
|
|
71
|
-
processLines('stdout');
|
|
72
|
-
});
|
|
73
|
-
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
74
|
-
processData(data, 'stderr');
|
|
75
|
-
processLines('stderr');
|
|
76
|
-
});
|
|
77
|
-
return new Promise(resolve => {
|
|
78
|
-
let resolved;
|
|
79
|
-
child.on('error', (err) => {
|
|
80
|
-
if (child.pid)
|
|
81
|
-
runningChildren.delete(child.pid);
|
|
82
|
-
processLines('stdout', true);
|
|
83
|
-
processLines('stderr', true);
|
|
84
|
-
if (resolved)
|
|
85
|
-
return;
|
|
86
|
-
result.code = err.code || 1;
|
|
87
|
-
result.error = err;
|
|
88
|
-
if (!result.error) {
|
|
89
|
-
const text = `Command failed (${result.code})`;
|
|
90
|
-
result.error =
|
|
91
|
-
new Error((opts.color ? chalk_1.default.red(text) : text) + '\n ' +
|
|
92
|
-
opts.color ? chalk_1.default.white(err.message) : err.message);
|
|
93
|
-
}
|
|
94
|
-
resolved = true;
|
|
95
|
-
resolve(result);
|
|
96
|
-
});
|
|
97
|
-
child.on('close', (code) => {
|
|
98
|
-
if (child.pid)
|
|
99
|
-
runningChildren.delete(child.pid);
|
|
100
|
-
processLines('stdout', true);
|
|
101
|
-
processLines('stderr', true);
|
|
102
|
-
if (resolved)
|
|
103
|
-
return;
|
|
104
|
-
result.code = code;
|
|
105
|
-
resolved = true;
|
|
106
|
-
if (code) {
|
|
107
|
-
const text = `Command failed (${result.code})`;
|
|
108
|
-
result.error = new Error((opts.color ? chalk_1.default.red(text) : text));
|
|
109
|
-
}
|
|
110
|
-
return resolve(result);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
exports.executeCommand = executeCommand;
|
|
116
|
-
(0, utils_js_1.onProcessExit)(() => {
|
|
117
|
-
runningChildren.forEach((child) => {
|
|
118
|
-
child.kill();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,240 +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.Workspace = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
-
const cli_progress_1 = require("cli-progress");
|
|
21
|
-
const utils_js_1 = require("./utils.js");
|
|
22
|
-
const executor_js_1 = require("./executor.js");
|
|
23
|
-
const package_js_1 = require("./package.js");
|
|
24
|
-
const npm_provider_js_1 = require("./providers/npm-provider.js");
|
|
25
|
-
const providers = [
|
|
26
|
-
new npm_provider_js_1.NpmProvider()
|
|
27
|
-
];
|
|
28
|
-
class Workspace {
|
|
29
|
-
constructor(root, packages, options) {
|
|
30
|
-
this.root = root;
|
|
31
|
-
this._options = Object.assign({}, options);
|
|
32
|
-
this._packages = packages;
|
|
33
|
-
this._determineDependencies();
|
|
34
|
-
this._sortPackages();
|
|
35
|
-
}
|
|
36
|
-
get packages() {
|
|
37
|
-
return this._packages;
|
|
38
|
-
}
|
|
39
|
-
getPackage(name) {
|
|
40
|
-
return this.packages.find(p => p.name === name);
|
|
41
|
-
}
|
|
42
|
-
runScript(script, options = {}) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const packages = {};
|
|
45
|
-
const result = {
|
|
46
|
-
script,
|
|
47
|
-
errorCount: 0,
|
|
48
|
-
commands: []
|
|
49
|
-
};
|
|
50
|
-
options.gauge = options.gauge == null ? true : options.gauge;
|
|
51
|
-
const progressBars = options.gauge && new cli_progress_1.MultiBar({
|
|
52
|
-
format: '[' + chalk_1.default.cyan('{bar}') + '] {percentage}% | {value}/{total} | ' +
|
|
53
|
-
chalk_1.default.yellowBright('{package}') + ' | ' + chalk_1.default.yellow('{command}'),
|
|
54
|
-
barsize: 30,
|
|
55
|
-
hideCursor: true
|
|
56
|
-
}, cli_progress_1.Presets.rect);
|
|
57
|
-
const overallProgress = progressBars && progressBars.create(0, 0);
|
|
58
|
-
let totalCommands = 0;
|
|
59
|
-
for (const p of this.packages) {
|
|
60
|
-
const commands = p.getScriptCommands(script);
|
|
61
|
-
const progress = progressBars && progressBars.create(commands.length, 0);
|
|
62
|
-
packages[p.name] = {
|
|
63
|
-
package: p,
|
|
64
|
-
commands: [...commands],
|
|
65
|
-
progress
|
|
66
|
-
};
|
|
67
|
-
totalCommands += commands.length;
|
|
68
|
-
if (progress)
|
|
69
|
-
progress.start(commands.length, 0, {
|
|
70
|
-
package: p.name,
|
|
71
|
-
command: 'Waiting'
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
if (overallProgress) {
|
|
75
|
-
overallProgress.start(totalCommands, 0, { package: 'Overall', command: '' });
|
|
76
|
-
}
|
|
77
|
-
const t = Date.now();
|
|
78
|
-
return new Promise((resolve) => {
|
|
79
|
-
const remaining = new Set(Object.keys(packages));
|
|
80
|
-
const runScripts = () => {
|
|
81
|
-
for (const pkgName of remaining) {
|
|
82
|
-
const pkgInfo = packages[pkgName];
|
|
83
|
-
const pkg = pkgInfo.package;
|
|
84
|
-
const progress = pkgInfo.progress;
|
|
85
|
-
for (let k = 0; k < pkgInfo.commands.length; k++) {
|
|
86
|
-
const cmd = pkgInfo.commands[k];
|
|
87
|
-
if (cmd.status === 'running')
|
|
88
|
-
break;
|
|
89
|
-
if (!cmd.status) {
|
|
90
|
-
const concurrent = cmd.step.startsWith('pre');
|
|
91
|
-
if (!concurrent &&
|
|
92
|
-
pkg.dependencies.find(dep => (0, utils_js_1.setFind)(remaining, p => p === dep))) {
|
|
93
|
-
cmd.status = '';
|
|
94
|
-
if (progress)
|
|
95
|
-
progress.update({ command: chalk_1.default.bgYellow.white('Waiting dependencies') });
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
cmd.status = 'running';
|
|
99
|
-
if (progress)
|
|
100
|
-
progress.update({ command: cmd.name });
|
|
101
|
-
else
|
|
102
|
-
console.log('[' + chalk_1.default.whiteBright(pkg.name) + '] ' +
|
|
103
|
-
chalk_1.default.yellow(cmd.command), (chalk_1.default.cyanBright(' +' + (Date.now() - t))));
|
|
104
|
-
void (0, executor_js_1.executeCommand)(cmd.command, Object.assign(Object.assign({}, options), { cwd: pkg.dirname, shell: true })).then(r => {
|
|
105
|
-
if (overallProgress)
|
|
106
|
-
overallProgress.increment(1);
|
|
107
|
-
if (progress)
|
|
108
|
-
progress.increment(1);
|
|
109
|
-
const cr = {
|
|
110
|
-
package: pkg.name,
|
|
111
|
-
command: cmd,
|
|
112
|
-
code: r.code || 1,
|
|
113
|
-
error: r.error,
|
|
114
|
-
stdout: r.stdout,
|
|
115
|
-
stderr: r.stderr
|
|
116
|
-
};
|
|
117
|
-
result.code = result.code || r.code;
|
|
118
|
-
if (r.error)
|
|
119
|
-
result.errorCount++;
|
|
120
|
-
result.commands.push(cr);
|
|
121
|
-
cmd.status = 'done';
|
|
122
|
-
if (r.error || k === pkgInfo.commands.length - 1) {
|
|
123
|
-
if (progress) {
|
|
124
|
-
if (r.error)
|
|
125
|
-
progress.update({ command: chalk_1.default.yellow(cmd.name) + chalk_1.default.red(' Filed!') });
|
|
126
|
-
else
|
|
127
|
-
progress.update({ command: chalk_1.default.green(' Completed!') });
|
|
128
|
-
}
|
|
129
|
-
remaining.delete(pkg.name);
|
|
130
|
-
}
|
|
131
|
-
if (!remaining.size) {
|
|
132
|
-
if (progressBars)
|
|
133
|
-
progressBars.stop();
|
|
134
|
-
return resolve(result);
|
|
135
|
-
}
|
|
136
|
-
if (!result.errorCount)
|
|
137
|
-
setTimeout(runScripts, 1);
|
|
138
|
-
});
|
|
139
|
-
if (!concurrent)
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
runScripts();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
static create(root, options) {
|
|
150
|
-
root = root || process.cwd();
|
|
151
|
-
let deep = (options === null || options === void 0 ? void 0 : options.deep) || 0;
|
|
152
|
-
while (deep-- >= 0 && fs_1.default.existsSync(root)) {
|
|
153
|
-
for (let i = providers.length - 1; i >= 0; i--) {
|
|
154
|
-
const provider = providers[i];
|
|
155
|
-
const inf = provider.parse(root);
|
|
156
|
-
if (!inf)
|
|
157
|
-
continue;
|
|
158
|
-
const pkgJson = (0, utils_js_1.getPackageJson)(inf.root);
|
|
159
|
-
if (!pkgJson)
|
|
160
|
-
continue;
|
|
161
|
-
const packages = [];
|
|
162
|
-
for (const pattern of inf.packages) {
|
|
163
|
-
const dirs = fast_glob_1.default.sync(pattern, {
|
|
164
|
-
cwd: inf.root,
|
|
165
|
-
absolute: true,
|
|
166
|
-
deep: 0,
|
|
167
|
-
onlyDirectories: true
|
|
168
|
-
});
|
|
169
|
-
for (const dir of dirs) {
|
|
170
|
-
const p = detectPackage(dir);
|
|
171
|
-
if (p && !packages.find(x => x.name === p.name))
|
|
172
|
-
packages.push(p);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return new Workspace(inf.root, packages, pkgJson.rman);
|
|
176
|
-
}
|
|
177
|
-
root = path_1.default.resolve(root, '..');
|
|
178
|
-
}
|
|
179
|
-
throw new Error('No project workspace detected');
|
|
180
|
-
}
|
|
181
|
-
_determineDependencies() {
|
|
182
|
-
const deps = {};
|
|
183
|
-
for (const pkg of this.packages) {
|
|
184
|
-
const o = Object.assign(Object.assign(Object.assign(Object.assign({}, pkg.def.dependencies), pkg.def.devDependencies), pkg.def.peerDependencies), pkg.def.optionalDependencies);
|
|
185
|
-
const dependencies = [];
|
|
186
|
-
for (const k of Object.keys(o)) {
|
|
187
|
-
const p = this.getPackage(k);
|
|
188
|
-
if (p)
|
|
189
|
-
dependencies.push(k);
|
|
190
|
-
}
|
|
191
|
-
deps[pkg.name] = dependencies;
|
|
192
|
-
pkg.dependencies = dependencies;
|
|
193
|
-
}
|
|
194
|
-
let circularCheck;
|
|
195
|
-
const deepFindDependencies = (pkg, target) => {
|
|
196
|
-
if (circularCheck.includes(pkg.name))
|
|
197
|
-
return;
|
|
198
|
-
circularCheck.push(pkg.name);
|
|
199
|
-
for (const s of pkg.dependencies) {
|
|
200
|
-
if (!target.includes(s)) {
|
|
201
|
-
target.push(s);
|
|
202
|
-
const p = this.getPackage(s);
|
|
203
|
-
if (p) {
|
|
204
|
-
deepFindDependencies(p, target);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
for (const pkg of this.packages) {
|
|
210
|
-
circularCheck = [];
|
|
211
|
-
deepFindDependencies(pkg, pkg.dependencies);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
_sortPackages() {
|
|
215
|
-
const packages = [...this.packages];
|
|
216
|
-
const packageOrder = this._options.packageOrder;
|
|
217
|
-
packages.sort((a, b) => {
|
|
218
|
-
if (packageOrder) {
|
|
219
|
-
const a1 = packageOrder.indexOf(a.name);
|
|
220
|
-
const b1 = packageOrder.indexOf(b.name);
|
|
221
|
-
const i = (a1 >= 0 ? a1 : Number.MAX_SAFE_INTEGER) - (b1 >= 0 ? b1 : Number.MAX_SAFE_INTEGER);
|
|
222
|
-
if (i !== 0)
|
|
223
|
-
return i;
|
|
224
|
-
}
|
|
225
|
-
if (b.dependencies.includes(a.name))
|
|
226
|
-
return -1;
|
|
227
|
-
if (a.dependencies.includes(b.name))
|
|
228
|
-
return 1;
|
|
229
|
-
return 0;
|
|
230
|
-
});
|
|
231
|
-
this._packages = packages;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
exports.Workspace = Workspace;
|
|
235
|
-
function detectPackage(dirname) {
|
|
236
|
-
const pkgJson = (0, utils_js_1.getPackageJson)(dirname);
|
|
237
|
-
if (pkgJson && pkgJson.name) {
|
|
238
|
-
return new package_js_1.Package(dirname, pkgJson);
|
|
239
|
-
}
|
|
240
|
-
}
|