rman 0.1.0 → 0.2.2
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/bin/rman.js +2 -2
- package/cjs/cli.js +48 -58
- 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/cjs/{workspace → core}/types.js +0 -0
- package/cjs/debug.js +5 -0
- package/cjs/index.js +1 -1
- package/cjs/utils/constants.js +5 -0
- package/cjs/{workspace/executor.js → utils/exec.js} +20 -19
- 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 -1
- package/esm/cli.mjs +46 -56
- 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/{workspace → core}/types.mjs +0 -0
- package/esm/debug.d.ts +1 -0
- package/esm/debug.mjs +3 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.mjs +1 -1
- package/esm/utils/constants.d.ts +2 -0
- package/esm/utils/constants.mjs +2 -0
- package/esm/{workspace/executor.d.ts → utils/exec.d.ts} +5 -8
- package/esm/{workspace/executor.mjs → utils/exec.mjs} +18 -17
- 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 +44 -24
- package/bin/debug.ts +0 -4
- package/cjs/workspace/package.js +0 -43
- package/cjs/workspace/providers/npm-provider.js +0 -16
- package/cjs/workspace/utils.js +0 -31
- package/cjs/workspace/workspace.js +0 -245
- package/esm/workspace/package.d.ts +0 -27
- package/esm/workspace/package.mjs +0 -36
- package/esm/workspace/providers/npm-provider.d.ts +0 -4
- package/esm/workspace/providers/npm-provider.mjs +0 -12
- package/esm/workspace/types.d.ts +0 -10
- package/esm/workspace/utils.d.ts +0 -6
- package/esm/workspace/utils.mjs +0 -22
- package/esm/workspace/workspace.d.ts +0 -17
- package/esm/workspace/workspace.mjs +0 -238
|
@@ -3,28 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.exec = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const utils_1 = require("./utils");
|
|
8
|
+
const signal_exit_1 = __importDefault(require("signal-exit"));
|
|
9
|
+
const npm_run_path_1 = require("./npm-run-path");
|
|
11
10
|
const runningChildren = new Map();
|
|
12
|
-
async function
|
|
11
|
+
async function exec(command, options) {
|
|
13
12
|
const opts = {
|
|
14
|
-
|
|
13
|
+
shell: true,
|
|
14
|
+
throwOnError: true,
|
|
15
|
+
...options,
|
|
15
16
|
};
|
|
16
17
|
opts.env = {
|
|
17
|
-
...npm_run_path_1.
|
|
18
|
-
// FORCE_COLOR: `${chalk.level}`,
|
|
18
|
+
...(0, npm_run_path_1.npmRunPathEnv)({ cwd: opts.cwd }),
|
|
19
19
|
...opts.env
|
|
20
20
|
};
|
|
21
21
|
opts.cwd = opts.cwd || process.cwd();
|
|
22
|
-
opts.color = opts.color == null ? true : opts.color;
|
|
23
22
|
const spawnOptions = {
|
|
24
23
|
stdio: opts.stdio || 'pipe',
|
|
25
24
|
env: opts.env,
|
|
26
25
|
cwd: opts.cwd,
|
|
27
|
-
shell:
|
|
26
|
+
shell: opts.shell,
|
|
28
27
|
windowsHide: true
|
|
29
28
|
};
|
|
30
29
|
const result = {
|
|
@@ -69,7 +68,7 @@ async function executeCommand(command, options) {
|
|
|
69
68
|
processData(data, 'stderr');
|
|
70
69
|
processLines('stderr');
|
|
71
70
|
});
|
|
72
|
-
return new Promise(resolve => {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
73
72
|
let resolved;
|
|
74
73
|
child.on('error', (err) => {
|
|
75
74
|
if (child.pid)
|
|
@@ -79,14 +78,16 @@ async function executeCommand(command, options) {
|
|
|
79
78
|
if (resolved)
|
|
80
79
|
return;
|
|
81
80
|
result.code = err.code || 1;
|
|
82
|
-
|
|
83
|
-
if (!result.error) {
|
|
81
|
+
if (!err) {
|
|
84
82
|
const text = `Command failed (${result.code})`;
|
|
85
|
-
|
|
86
|
-
new Error((opts.color ? chalk_1.default.red(text) : text) + '\n ' +
|
|
87
|
-
opts.color ? chalk_1.default.white(err.message) : err.message);
|
|
83
|
+
err = new Error(text);
|
|
88
84
|
}
|
|
85
|
+
if (typeof err === 'string')
|
|
86
|
+
err = new Error(err);
|
|
87
|
+
result.error = err;
|
|
89
88
|
resolved = true;
|
|
89
|
+
if (opts.throwOnError)
|
|
90
|
+
return reject(result.error);
|
|
90
91
|
resolve(result);
|
|
91
92
|
});
|
|
92
93
|
child.on('close', (code) => {
|
|
@@ -100,14 +101,14 @@ async function executeCommand(command, options) {
|
|
|
100
101
|
resolved = true;
|
|
101
102
|
if (code) {
|
|
102
103
|
const text = `Command failed (${result.code})`;
|
|
103
|
-
result.error = new Error(
|
|
104
|
+
result.error = new Error(text);
|
|
104
105
|
}
|
|
105
106
|
return resolve(result);
|
|
106
107
|
});
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
exports.
|
|
110
|
-
(0,
|
|
110
|
+
exports.exec = exec;
|
|
111
|
+
(0, signal_exit_1.default)(() => {
|
|
111
112
|
runningChildren.forEach((child) => {
|
|
112
113
|
child.kill();
|
|
113
114
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GitHelper = void 0;
|
|
7
|
+
const exec_1 = require("./exec");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class GitHelper {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.cwd = options?.cwd || process.cwd();
|
|
12
|
+
}
|
|
13
|
+
async listDirtyFileStatus(options) {
|
|
14
|
+
const x = await (0, exec_1.exec)('git', {
|
|
15
|
+
cwd: this.cwd,
|
|
16
|
+
argv: ['status', '--porcelain']
|
|
17
|
+
});
|
|
18
|
+
const result = [];
|
|
19
|
+
const files = x.stdout ? x.stdout.trim().split(/\s*\n\s*/) : [];
|
|
20
|
+
for (const f of files) {
|
|
21
|
+
const m = f.match(/^(\w+) (.+)$/);
|
|
22
|
+
if (m) {
|
|
23
|
+
result.push({
|
|
24
|
+
filename: options?.absolute ? path_1.default.join(this.cwd, m[2]) : m[2],
|
|
25
|
+
status: m[1]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
async listDirtyFiles(options) {
|
|
32
|
+
return (await this.listDirtyFileStatus(options)).map(x => x.filename);
|
|
33
|
+
}
|
|
34
|
+
async listCommitSha() {
|
|
35
|
+
const x = await (0, exec_1.exec)('git', {
|
|
36
|
+
cwd: this.cwd,
|
|
37
|
+
argv: ['cherry']
|
|
38
|
+
});
|
|
39
|
+
const matches = x.stdout ? x.stdout.matchAll(/([a-f0-9]+)/gi) : [];
|
|
40
|
+
const result = [];
|
|
41
|
+
for (const m of matches) {
|
|
42
|
+
result.push(m[1]);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
async listCommittedFiles(options) {
|
|
47
|
+
const shaArr = options?.commits
|
|
48
|
+
? (Array.isArray(options?.commits) ? options?.commits : [options?.commits])
|
|
49
|
+
: await this.listCommitSha();
|
|
50
|
+
let result = [];
|
|
51
|
+
for (const s of shaArr) {
|
|
52
|
+
const x = await (0, exec_1.exec)('git', {
|
|
53
|
+
cwd: this.cwd,
|
|
54
|
+
argv: ['show', s, '--name-only', '--pretty="format:"']
|
|
55
|
+
});
|
|
56
|
+
result.push(...(x.stdout ? x.stdout.trim().split(/\s*\n\s*/) : []));
|
|
57
|
+
}
|
|
58
|
+
if (options?.absolute)
|
|
59
|
+
result = result.map(f => path_1.default.join(this.cwd, f));
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
async readFileLastPublished(filePath, commitSha) {
|
|
63
|
+
const x = await (0, exec_1.exec)('git', {
|
|
64
|
+
cwd: this.cwd,
|
|
65
|
+
argv: ['show', (commitSha || 'HEAD') + ':"' + filePath + '"']
|
|
66
|
+
});
|
|
67
|
+
return x.stdout || '';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.GitHelper = GitHelper;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.npmRunPathEnv = exports.npmRunPath = void 0;
|
|
7
|
+
/* eslint-disable max-len */
|
|
8
|
+
/**
|
|
9
|
+
* Inspired from [npm-run-path](https://github.com/sindresorhus/npm-run-path)
|
|
10
|
+
*/
|
|
11
|
+
const process_1 = __importDefault(require("process"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const path_key_1 = __importDefault(require("path-key"));
|
|
14
|
+
/**
|
|
15
|
+
Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
|
|
16
|
+
@returns The augmented path string.
|
|
17
|
+
@example
|
|
18
|
+
```
|
|
19
|
+
import childProcess from 'node:child_process';
|
|
20
|
+
import {npmRunPath} from 'npm-run-path';
|
|
21
|
+
console.log(process.env.PATH);
|
|
22
|
+
//=> '/usr/local/bin'
|
|
23
|
+
console.log(npmRunPath());
|
|
24
|
+
//=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin'
|
|
25
|
+
```
|
|
26
|
+
*/
|
|
27
|
+
function npmRunPath(options = {}) {
|
|
28
|
+
const cwd = options.cwd || process_1.default.cwd();
|
|
29
|
+
const path_ = options.path || process_1.default.env[(0, path_key_1.default)()];
|
|
30
|
+
const execPath = options.execPath || process_1.default.execPath;
|
|
31
|
+
let previous;
|
|
32
|
+
let cwdPath = path_1.default.resolve(cwd);
|
|
33
|
+
const result = [];
|
|
34
|
+
while (previous !== cwdPath) {
|
|
35
|
+
result.push(path_1.default.join(cwdPath, 'node_modules/.bin'));
|
|
36
|
+
previous = cwdPath;
|
|
37
|
+
cwdPath = path_1.default.resolve(cwdPath, '..');
|
|
38
|
+
}
|
|
39
|
+
// Ensure the running `node` binary is used.
|
|
40
|
+
result.push(path_1.default.resolve(cwd, execPath, '..'));
|
|
41
|
+
return [...result, path_].join(path_1.default.delimiter);
|
|
42
|
+
}
|
|
43
|
+
exports.npmRunPath = npmRunPath;
|
|
44
|
+
/**
|
|
45
|
+
@returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
|
|
46
|
+
@example
|
|
47
|
+
```
|
|
48
|
+
import childProcess from 'node:child_process';
|
|
49
|
+
import {npmRunPathEnv} from 'npm-run-path';
|
|
50
|
+
// `foo` is a locally installed binary
|
|
51
|
+
childProcess.execFileSync('foo', {
|
|
52
|
+
env: npmRunPathEnv()
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
*/
|
|
56
|
+
function npmRunPathEnv(options = {}) {
|
|
57
|
+
const env = { ...(options.env || process_1.default.env) };
|
|
58
|
+
const path_ = (0, path_key_1.default)({ env });
|
|
59
|
+
const opts = { ...options, path: env[path_] };
|
|
60
|
+
env[path_] = npmRunPath(opts);
|
|
61
|
+
return env;
|
|
62
|
+
}
|
|
63
|
+
exports.npmRunPathEnv = npmRunPathEnv;
|
package/cjs/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPackageJson = exports.getDirname = void 0;
|
|
7
|
+
// noinspection ES6UnusedImports
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
function getDirname() {
|
|
12
|
+
const pst = Error.prepareStackTrace;
|
|
13
|
+
Error.prepareStackTrace = function (_, stack) {
|
|
14
|
+
Error.prepareStackTrace = pst;
|
|
15
|
+
return stack;
|
|
16
|
+
};
|
|
17
|
+
const e = new Error();
|
|
18
|
+
if (!e.stack)
|
|
19
|
+
throw Error('Can not parse stack');
|
|
20
|
+
const stack = e.stack.slice(1);
|
|
21
|
+
while (stack) {
|
|
22
|
+
const frame = stack.shift();
|
|
23
|
+
const filename = frame && frame.getFileName();
|
|
24
|
+
if (filename)
|
|
25
|
+
return path_1.default.dirname(filename).replace('file://', '');
|
|
26
|
+
}
|
|
27
|
+
throw Error('Can not parse stack');
|
|
28
|
+
}
|
|
29
|
+
exports.getDirname = getDirname;
|
|
30
|
+
function getPackageJson(dirname) {
|
|
31
|
+
const f = path_1.default.resolve(dirname, 'package.json');
|
|
32
|
+
if (!fs_1.default.existsSync(f))
|
|
33
|
+
return;
|
|
34
|
+
return JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
|
|
35
|
+
}
|
|
36
|
+
exports.getPackageJson = getPackageJson;
|
package/esm/cli.d.ts
CHANGED
package/esm/cli.mjs
CHANGED
|
@@ -1,60 +1,50 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
|
+
import yargs from "yargs";
|
|
3
4
|
import chalk from 'chalk';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const cmd = result.commands[i];
|
|
50
|
-
if (cmd.error) {
|
|
51
|
-
s += '\n' + (i + 1) + ') ' +
|
|
52
|
-
chalk.cyanBright(cmd.package) + '\n' +
|
|
53
|
-
chalk.white(cmd.command) + '\n' +
|
|
54
|
-
chalk.red('Error: ' + cmd.error.message) + '\n' +
|
|
55
|
-
chalk.red(cmd.stderr) + '\n';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
console.error(s);
|
|
59
|
-
}
|
|
5
|
+
import { getDirname } from './utils.mjs';
|
|
6
|
+
import { Repository } from './core/repository.mjs';
|
|
7
|
+
import { InfoCommand } from './commands/info-command.mjs';
|
|
8
|
+
import { Command } from './core/command.mjs';
|
|
9
|
+
import { ListCommand } from './commands/list-command.mjs';
|
|
10
|
+
import { ChangedCommand } from './commands/changed-command.mjs';
|
|
11
|
+
import { ExecuteCommand } from './commands/execute-command.mjs';
|
|
12
|
+
import { RunCommand } from './commands/run-command.mjs';
|
|
13
|
+
import { VersionCommand } from './commands/version-command.mjs';
|
|
14
|
+
import { PublishCommand } from './commands/publish-command.mjs';
|
|
15
|
+
export async function runCli(options) {
|
|
16
|
+
const s = path.resolve(getDirname(), '../package.json');
|
|
17
|
+
const pkgJson = JSON.parse(await fs.readFile(s, 'utf-8'));
|
|
18
|
+
const repository = Repository.create(options?.cwd);
|
|
19
|
+
const _argv = options?.argv || process.argv.slice(2);
|
|
20
|
+
const globalKeys = Object.keys(Command.globalOptions).concat(["help", "version"]);
|
|
21
|
+
const program = yargs(_argv)
|
|
22
|
+
// .scriptName('rman')
|
|
23
|
+
.strict()
|
|
24
|
+
.version(pkgJson.version || '').alias('version', 'v')
|
|
25
|
+
.usage('$0 <cmd> [options...]')
|
|
26
|
+
.help('help').alias('help', 'h')
|
|
27
|
+
.showHelpOnFail(false, 'Run with --help for available options')
|
|
28
|
+
.fail((msg, err) => {
|
|
29
|
+
const text = (msg
|
|
30
|
+
? msg + '\n\n' + chalk.whiteBright('Run with --help for available options')
|
|
31
|
+
: (err ? err.message : ''));
|
|
32
|
+
console.log('\n' + chalk.red(text));
|
|
33
|
+
throw msg;
|
|
34
|
+
})
|
|
35
|
+
// group options under "Global Options:" header
|
|
36
|
+
.options(Command.globalOptions)
|
|
37
|
+
.group(globalKeys, "Global Options:");
|
|
38
|
+
InfoCommand.initCli(repository, program);
|
|
39
|
+
ListCommand.initCli(repository, program);
|
|
40
|
+
ChangedCommand.initCli(repository, program);
|
|
41
|
+
ExecuteCommand.initCli(repository, program);
|
|
42
|
+
RunCommand.initCli(repository, program);
|
|
43
|
+
VersionCommand.initCli(repository, program);
|
|
44
|
+
PublishCommand.initCli(repository, program);
|
|
45
|
+
if (!_argv.length)
|
|
46
|
+
program.showHelp();
|
|
47
|
+
else
|
|
48
|
+
await program.parseAsync()
|
|
49
|
+
.catch(() => false);
|
|
60
50
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { Repository } from '../core/repository';
|
|
3
|
+
import { ListCommand } from './list-command';
|
|
4
|
+
import { Package } from '../core/package';
|
|
5
|
+
export declare class ChangedCommand extends ListCommand {
|
|
6
|
+
readonly repository: Repository;
|
|
7
|
+
static commandName: string;
|
|
8
|
+
constructor(repository: Repository, options?: ListCommand.Options);
|
|
9
|
+
protected _filter(pkg: Package, inf: {
|
|
10
|
+
isDirty?: boolean;
|
|
11
|
+
isCommitted?: boolean;
|
|
12
|
+
}): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace ChangedCommand {
|
|
15
|
+
function initCli(repository: Repository, program: yargs.Argv): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ListCommand } from './list-command.mjs';
|
|
2
|
+
import { Command } from './../core/command.mjs';
|
|
3
|
+
export class ChangedCommand extends ListCommand {
|
|
4
|
+
constructor(repository, options) {
|
|
5
|
+
super(repository, options);
|
|
6
|
+
this.repository = repository;
|
|
7
|
+
}
|
|
8
|
+
_filter(pkg, inf) {
|
|
9
|
+
if (!super._filter(pkg, inf))
|
|
10
|
+
return false;
|
|
11
|
+
return !!(inf.isDirty || inf.isCommitted);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
ChangedCommand.commandName = 'changed';
|
|
15
|
+
(function (ChangedCommand) {
|
|
16
|
+
function initCli(repository, program) {
|
|
17
|
+
program.command({
|
|
18
|
+
command: 'changed [options...]',
|
|
19
|
+
describe: 'List local packages that have changed since the last tagged release',
|
|
20
|
+
builder: (cmd) => {
|
|
21
|
+
return cmd
|
|
22
|
+
.example("$0 changed", "# List changed packages")
|
|
23
|
+
.example('$0 changed --json', '# List changed packages in JSON format')
|
|
24
|
+
.option(ListCommand.cliCommandOptions);
|
|
25
|
+
},
|
|
26
|
+
handler: async (args) => {
|
|
27
|
+
const options = Command.composeOptions(ChangedCommand.commandName, args, repository.config);
|
|
28
|
+
await new ChangedCommand(repository, options)
|
|
29
|
+
.execute();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
ChangedCommand.initCli = initCli;
|
|
34
|
+
})(ChangedCommand || (ChangedCommand = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { Repository } from '../core/repository';
|
|
3
|
+
import { MultiTaskCommand } from './multi-task-command';
|
|
4
|
+
import { Task } from 'power-tasks';
|
|
5
|
+
export declare class ExecuteCommand extends MultiTaskCommand<ExecuteCommand.Options> {
|
|
6
|
+
readonly repository: Repository;
|
|
7
|
+
cmd: string;
|
|
8
|
+
argv?: string[] | undefined;
|
|
9
|
+
static commandName: string;
|
|
10
|
+
constructor(repository: Repository, cmd: string, argv?: string[] | undefined, options?: ExecuteCommand.Options);
|
|
11
|
+
protected _prepareTasks(): Task[];
|
|
12
|
+
}
|
|
13
|
+
export declare namespace ExecuteCommand {
|
|
14
|
+
interface Options extends MultiTaskCommand.Options {
|
|
15
|
+
}
|
|
16
|
+
const cliCommandOptions: Record<string, yargs.Options>;
|
|
17
|
+
function initCli(repository: Repository, program: yargs.Argv): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import logger from 'npmlog';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import figures from 'figures';
|
|
4
|
+
import { MultiTaskCommand } from './multi-task-command.mjs';
|
|
5
|
+
import { Task } from 'power-tasks';
|
|
6
|
+
import { exec } from './../utils/exec.mjs';
|
|
7
|
+
import { Command } from './../core/command.mjs';
|
|
8
|
+
export class ExecuteCommand extends MultiTaskCommand {
|
|
9
|
+
constructor(repository, cmd, argv, options) {
|
|
10
|
+
super(repository, options);
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.cmd = cmd;
|
|
13
|
+
this.argv = argv;
|
|
14
|
+
}
|
|
15
|
+
_prepareTasks() {
|
|
16
|
+
const packages = this.repository.getPackages({ toposort: !this.options.parallel });
|
|
17
|
+
const tasks = [];
|
|
18
|
+
for (const p of packages) {
|
|
19
|
+
const task = new Task(async () => {
|
|
20
|
+
const t = Date.now();
|
|
21
|
+
logger.verbose(this.commandName, p.name, chalk.gray(figures.lineVerticalDashed0), chalk.cyanBright.bold('executing'), chalk.gray(figures.lineVerticalDashed0), this.cmd + ' ' + (this.argv?.join(' ') || ''));
|
|
22
|
+
const r = await exec(this.cmd, {
|
|
23
|
+
cwd: p.dirname,
|
|
24
|
+
argv: this.argv
|
|
25
|
+
});
|
|
26
|
+
logger.log((r.error ? 'error' : 'verbose'), this.commandName, chalk.gray(figures.lineVerticalDashed0), p.name, chalk.gray(figures.lineVerticalDashed0), (r.error ? chalk.red.bold('failed') : chalk.green.bold('success')), chalk.gray(figures.lineVerticalDashed0), 'Completed in ' + chalk.yellow('' + (Date.now() - t) + ' ms'));
|
|
27
|
+
}, {
|
|
28
|
+
name: p.name,
|
|
29
|
+
dependencies: this.options.parallel ? undefined : p.dependencies,
|
|
30
|
+
bail: this.options.bail,
|
|
31
|
+
concurrency: this.options.concurrency
|
|
32
|
+
});
|
|
33
|
+
tasks.push(task);
|
|
34
|
+
}
|
|
35
|
+
return tasks;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
ExecuteCommand.commandName = 'exec';
|
|
39
|
+
(function (ExecuteCommand) {
|
|
40
|
+
ExecuteCommand.cliCommandOptions = {
|
|
41
|
+
...MultiTaskCommand.cliCommandOptions
|
|
42
|
+
};
|
|
43
|
+
function initCli(repository, program) {
|
|
44
|
+
program.command({
|
|
45
|
+
command: 'exec [cmd] [args..]',
|
|
46
|
+
describe: 'Execute an arbitrary command in each package',
|
|
47
|
+
builder: (cmd) => {
|
|
48
|
+
return cmd
|
|
49
|
+
.example("$0 exec -- ls", '')
|
|
50
|
+
.example('$0 exec -- rm -rf ./node_modules', '')
|
|
51
|
+
.parserConfiguration({
|
|
52
|
+
"populate--": true,
|
|
53
|
+
})
|
|
54
|
+
.positional("cmd", {
|
|
55
|
+
describe: "The command to execute. Any command flags must be passed after --",
|
|
56
|
+
type: "string",
|
|
57
|
+
})
|
|
58
|
+
.positional("args", {
|
|
59
|
+
describe: "Positional arguments to send to command",
|
|
60
|
+
type: "string",
|
|
61
|
+
})
|
|
62
|
+
.option(ExecuteCommand.cliCommandOptions);
|
|
63
|
+
},
|
|
64
|
+
handler: async (args) => {
|
|
65
|
+
const argv = args['--'] || [];
|
|
66
|
+
const options = Command.composeOptions(ExecuteCommand.commandName, args, repository.config);
|
|
67
|
+
await new ExecuteCommand(repository, '' + argv.shift(), argv, options).execute();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
ExecuteCommand.initCli = initCli;
|
|
72
|
+
})(ExecuteCommand || (ExecuteCommand = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { Command } from '../core/command';
|
|
3
|
+
import { Repository } from '../core/repository';
|
|
4
|
+
export declare class InfoCommand extends Command {
|
|
5
|
+
static commandName: string;
|
|
6
|
+
protected _execute(): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace InfoCommand {
|
|
9
|
+
function initCli(repository: Repository, program: yargs.Argv): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import envinfo from 'envinfo';
|
|
3
|
+
import semver from 'semver';
|
|
4
|
+
import { Command } from './../core/command.mjs';
|
|
5
|
+
export class InfoCommand extends Command {
|
|
6
|
+
async _execute() {
|
|
7
|
+
const systemInfo = JSON.parse(await envinfo.run({
|
|
8
|
+
System: ['OS', 'CPU', 'Memory', 'Shell'],
|
|
9
|
+
Binaries: ['Node', 'Yarn', 'npm'],
|
|
10
|
+
Utilities: ['Git'],
|
|
11
|
+
npmPackages: ['rman', 'typescript'],
|
|
12
|
+
npmGlobalPackages: ['typescript']
|
|
13
|
+
}, { json: true }));
|
|
14
|
+
if (this.options.json) {
|
|
15
|
+
this.logger.output('', '%j', systemInfo);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const maxName = Object.keys(systemInfo).reduce((l, p) => Object.keys(systemInfo[p]).reduce((i, x) => l = Math.max(i, x.length), l), 0);
|
|
19
|
+
for (const [categoryName, category] of Object.entries(systemInfo)) {
|
|
20
|
+
this.logger.output('', '', chalk.whiteBright(categoryName) + ':');
|
|
21
|
+
for (const [n, v] of Object.entries(category)) {
|
|
22
|
+
const label = ' ' + chalk.reset(n) +
|
|
23
|
+
' '.repeat(maxName - n.length) + ' :';
|
|
24
|
+
if (typeof v === 'string') {
|
|
25
|
+
this.logger.output('', label, chalk.yellowBright(v));
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (v.version)
|
|
29
|
+
this.logger.output('', label, chalk.yellowBright(v.version), (v.path ? ' ' + chalk.yellow(v.path) : ''));
|
|
30
|
+
if (v.installed) {
|
|
31
|
+
if (v.wanted === 'latest' || semver.intersects(v.installed, v.wanted))
|
|
32
|
+
this.logger.output('', label, chalk.yellowBright(v.installed));
|
|
33
|
+
else
|
|
34
|
+
this.logger.output('', label, chalk.red(v.installed), ' => ', chalk.yellowBright(v.wanted));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
InfoCommand.commandName = 'info';
|
|
41
|
+
(function (InfoCommand) {
|
|
42
|
+
function initCli(repository, program) {
|
|
43
|
+
program.command({
|
|
44
|
+
command: 'info [options...]',
|
|
45
|
+
describe: 'Prints local environment information',
|
|
46
|
+
builder: (cmd) => {
|
|
47
|
+
return cmd
|
|
48
|
+
.example("$0 info", "# Prints information")
|
|
49
|
+
.example('$0 info --json', '# Prints information in JSON format');
|
|
50
|
+
},
|
|
51
|
+
handler: async (args) => {
|
|
52
|
+
const options = Command.composeOptions(InfoCommand.commandName, args, repository.config);
|
|
53
|
+
await new InfoCommand(options)
|
|
54
|
+
.execute();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
InfoCommand.initCli = initCli;
|
|
59
|
+
})(InfoCommand || (InfoCommand = {}));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import EasyTable from 'easy-table';
|
|
3
|
+
import { Command } from '../core/command';
|
|
4
|
+
import { Repository } from '../core/repository';
|
|
5
|
+
import { Package } from '../core/package';
|
|
6
|
+
export declare class ListCommand<TOptions extends ListCommand.Options = ListCommand.Options> extends Command<TOptions> {
|
|
7
|
+
readonly repository: Repository;
|
|
8
|
+
static commandName: string;
|
|
9
|
+
onPrepare?(pkg: Package, data: ListCommand.PackageOutput): ListCommand.PackageOutput;
|
|
10
|
+
onPrintTable?(pkg: Package, data: ListCommand.PackageOutput, table: EasyTable): ListCommand.PackageOutput;
|
|
11
|
+
constructor(repository: Repository, options?: TOptions);
|
|
12
|
+
protected _filter(pkg: Package, inf: {
|
|
13
|
+
isDirty?: boolean;
|
|
14
|
+
isCommitted?: boolean;
|
|
15
|
+
}): boolean;
|
|
16
|
+
protected _execute(): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
export declare namespace ListCommand {
|
|
19
|
+
interface Options {
|
|
20
|
+
json?: boolean;
|
|
21
|
+
parseable?: boolean;
|
|
22
|
+
short?: boolean;
|
|
23
|
+
toposort?: boolean;
|
|
24
|
+
graph?: boolean;
|
|
25
|
+
changed?: boolean;
|
|
26
|
+
filter?: string | ((pkg: Package) => boolean);
|
|
27
|
+
}
|
|
28
|
+
interface PackageOutput {
|
|
29
|
+
name: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
location?: string;
|
|
32
|
+
private?: boolean;
|
|
33
|
+
isDirty?: boolean;
|
|
34
|
+
isCommitted?: boolean;
|
|
35
|
+
}
|
|
36
|
+
const cliCommandOptions: Record<string, yargs.Options>;
|
|
37
|
+
function initCli(repository: Repository, program: yargs.Argv): void;
|
|
38
|
+
}
|