rman 0.0.4 → 0.2.1
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/rman.js +2 -2
- package/cjs/cli.js +57 -0
- package/cjs/commands/changed-command.js +38 -0
- package/cjs/commands/execute-command.js +79 -0
- package/cjs/commands/info-command.js +66 -0
- package/cjs/commands/list-command.js +141 -0
- package/cjs/commands/multi-task-command.js +70 -0
- package/cjs/commands/publish-command.js +74 -0
- package/cjs/commands/run-command.js +103 -0
- package/cjs/commands/version-command.js +155 -0
- package/cjs/core/command.js +110 -0
- package/cjs/core/config.js +73 -0
- package/cjs/core/logger.js +8 -0
- package/cjs/core/package.js +33 -0
- package/cjs/core/repository.js +133 -0
- package/{dist/workspace → cjs/core}/types.js +0 -0
- package/cjs/debug.js +5 -0
- package/{dist → cjs}/index.js +1 -1
- package/cjs/package.json +3 -0
- package/cjs/utils/constants.js +5 -0
- package/cjs/utils/exec.js +115 -0
- package/cjs/utils/git-utils.js +70 -0
- package/cjs/utils/npm-run-path.js +63 -0
- package/cjs/utils.js +36 -0
- package/esm/cli.d.ts +4 -0
- package/esm/cli.mjs +50 -0
- package/esm/commands/changed-command.d.ts +16 -0
- package/esm/commands/changed-command.mjs +34 -0
- package/esm/commands/execute-command.d.ts +18 -0
- package/esm/commands/execute-command.mjs +72 -0
- package/esm/commands/info-command.d.ts +10 -0
- package/esm/commands/info-command.mjs +59 -0
- package/esm/commands/list-command.d.ts +38 -0
- package/esm/commands/list-command.mjs +134 -0
- package/esm/commands/multi-task-command.d.ts +20 -0
- package/esm/commands/multi-task-command.mjs +63 -0
- package/esm/commands/publish-command.d.ts +17 -0
- package/esm/commands/publish-command.mjs +67 -0
- package/esm/commands/run-command.d.ts +22 -0
- package/esm/commands/run-command.mjs +96 -0
- package/esm/commands/version-command.d.ts +24 -0
- package/esm/commands/version-command.mjs +148 -0
- package/esm/core/command.d.ts +35 -0
- package/esm/core/command.mjs +103 -0
- package/esm/core/config.d.ts +9 -0
- package/esm/core/config.mjs +66 -0
- package/esm/core/logger.d.ts +10 -0
- package/esm/core/logger.mjs +3 -0
- package/esm/core/package.d.ts +11 -0
- package/esm/core/package.mjs +26 -0
- package/esm/core/repository.d.ts +18 -0
- package/esm/core/repository.mjs +126 -0
- package/esm/core/types.d.ts +14 -0
- package/esm/core/types.mjs +1 -0
- package/esm/debug.d.ts +1 -0
- package/esm/debug.mjs +3 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.mjs +1 -0
- package/esm/utils/constants.d.ts +2 -0
- package/esm/utils/constants.mjs +2 -0
- package/{dist/workspace/executor.d.ts → esm/utils/exec.d.ts} +5 -8
- package/esm/utils/exec.mjs +108 -0
- package/esm/utils/git-utils.d.ts +25 -0
- package/esm/utils/git-utils.mjs +63 -0
- package/esm/utils/npm-run-path.d.ts +67 -0
- package/esm/utils/npm-run-path.mjs +55 -0
- package/esm/utils.d.ts +2 -0
- package/esm/utils.mjs +28 -0
- package/package.json +64 -31
- package/bin/debug.ts +0 -4
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -71
- package/dist/index.d.ts +0 -1
- package/dist/workspace/executor.js +0 -120
- package/dist/workspace/package.d.ts +0 -27
- package/dist/workspace/package.js +0 -43
- package/dist/workspace/providers/npm-provider.d.ts +0 -4
- package/dist/workspace/providers/npm-provider.js +0 -16
- package/dist/workspace/types.d.ts +0 -10
- package/dist/workspace/utils.d.ts +0 -6
- package/dist/workspace/utils.js +0 -31
- package/dist/workspace/workspace.d.ts +0 -17
- package/dist/workspace/workspace.js +0 -240
|
@@ -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
|
-
}
|