rman 0.3.0 → 0.6.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/cjs/cli.js +2 -0
- package/cjs/commands/ci-command.js +81 -0
- package/cjs/commands/execute-command.js +5 -6
- package/cjs/commands/multi-task-command.js +6 -5
- package/cjs/commands/publish-command.js +10 -17
- package/cjs/commands/run-command.js +49 -27
- package/cjs/commands/version-command.js +52 -37
- package/cjs/core/command.js +16 -3
- package/cjs/core/logger.js +0 -1
- package/cjs/utils/file-utils.js +34 -0
- package/esm/cli.mjs +2 -0
- package/esm/commands/ci-command.d.ts +26 -0
- package/esm/commands/ci-command.mjs +74 -0
- package/esm/commands/execute-command.d.ts +2 -1
- package/esm/commands/execute-command.mjs +5 -6
- package/esm/commands/multi-task-command.d.ts +3 -1
- package/esm/commands/multi-task-command.mjs +6 -5
- package/esm/commands/publish-command.d.ts +10 -1
- package/esm/commands/publish-command.mjs +10 -17
- package/esm/commands/run-command.d.ts +18 -5
- package/esm/commands/run-command.mjs +49 -27
- package/esm/commands/version-command.d.ts +10 -4
- package/esm/commands/version-command.mjs +52 -37
- package/esm/core/command.d.ts +1 -1
- package/esm/core/command.mjs +16 -3
- package/esm/core/logger.d.ts +2 -0
- package/esm/core/logger.mjs +0 -1
- package/esm/utils/file-utils.d.ts +5 -0
- package/esm/utils/file-utils.mjs +25 -0
- package/package.json +2 -2
package/cjs/cli.js
CHANGED
|
@@ -18,6 +18,7 @@ const execute_command_1 = require("./commands/execute-command");
|
|
|
18
18
|
const run_command_1 = require("./commands/run-command");
|
|
19
19
|
const version_command_1 = require("./commands/version-command");
|
|
20
20
|
const publish_command_1 = require("./commands/publish-command");
|
|
21
|
+
const ci_command_1 = require("./commands/ci-command");
|
|
21
22
|
async function runCli(options) {
|
|
22
23
|
const s = path_1.default.resolve((0, utils_1.getDirname)(), '../package.json');
|
|
23
24
|
const pkgJson = JSON.parse(await promises_1.default.readFile(s, 'utf-8'));
|
|
@@ -48,6 +49,7 @@ async function runCli(options) {
|
|
|
48
49
|
run_command_1.RunCommand.initCli(repository, program);
|
|
49
50
|
version_command_1.VersionCommand.initCli(repository, program);
|
|
50
51
|
publish_command_1.PublishCommand.initCli(repository, program);
|
|
52
|
+
ci_command_1.CleanInstallCommand.initCli(repository, program);
|
|
51
53
|
if (!_argv.length)
|
|
52
54
|
program.showHelp();
|
|
53
55
|
else
|
|
@@ -0,0 +1,81 @@
|
|
|
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.CleanInstallCommand = void 0;
|
|
7
|
+
const power_tasks_1 = require("power-tasks");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const npmlog_1 = __importDefault(require("npmlog"));
|
|
10
|
+
const command_1 = require("../core/command");
|
|
11
|
+
const run_command_1 = require("./run-command");
|
|
12
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
class CleanInstallCommand extends run_command_1.RunCommand {
|
|
15
|
+
constructor(repository, options) {
|
|
16
|
+
super(repository, 'clean_', options);
|
|
17
|
+
this.repository = repository;
|
|
18
|
+
}
|
|
19
|
+
async _prepareTasks(packages) {
|
|
20
|
+
const tasks = await super._prepareTasks(packages);
|
|
21
|
+
const client = this.repository.config.client || 'npm';
|
|
22
|
+
if (!(client === 'npm' || client === 'yargs'))
|
|
23
|
+
throw new Error(`Invalid npm client "${client}"`);
|
|
24
|
+
tasks.push(new power_tasks_1.Task(async () => {
|
|
25
|
+
const dirname = this.repository.dirname;
|
|
26
|
+
await this._fsDelete(path_1.default.join(dirname, 'node_modules'));
|
|
27
|
+
await this._fsDelete(path_1.default.join(dirname, 'package-lock.json'));
|
|
28
|
+
await this._fsDelete(path_1.default.join(dirname, 'yarn-lock.json'));
|
|
29
|
+
npmlog_1.default.info(this.commandName, chalk_1.default.yellow('installing'), 'Running ' + client + ' install');
|
|
30
|
+
return super._exec({
|
|
31
|
+
name: 'root',
|
|
32
|
+
cwd: this.repository.dirname,
|
|
33
|
+
json: { ...this.repository.json },
|
|
34
|
+
command: client + ' install',
|
|
35
|
+
stdio: 'inherit'
|
|
36
|
+
});
|
|
37
|
+
}, { exclusive: true }));
|
|
38
|
+
return tasks;
|
|
39
|
+
}
|
|
40
|
+
async _exec(args, ctx) {
|
|
41
|
+
if (args.command === '#') {
|
|
42
|
+
if (args.name === 'root')
|
|
43
|
+
return { code: 0 };
|
|
44
|
+
const { cwd } = args;
|
|
45
|
+
await this._fsDelete(path_1.default.join(cwd, 'node_modules'));
|
|
46
|
+
await this._fsDelete(path_1.default.join(cwd, 'package-lock.json'));
|
|
47
|
+
await this._fsDelete(path_1.default.join(cwd, 'yarn-lock.json'));
|
|
48
|
+
return { code: 0 };
|
|
49
|
+
}
|
|
50
|
+
return super._exec(args, ctx);
|
|
51
|
+
}
|
|
52
|
+
async _fsDelete(fileOrDir) {
|
|
53
|
+
if (await (0, file_utils_1.fsExists)(fileOrDir)) {
|
|
54
|
+
npmlog_1.default.info(this.commandName, chalk_1.default.yellow('clean'), 'Deleting ' + fileOrDir);
|
|
55
|
+
await (0, file_utils_1.fsDelete)(fileOrDir);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.CleanInstallCommand = CleanInstallCommand;
|
|
60
|
+
CleanInstallCommand.commandName = 'ci';
|
|
61
|
+
(function (CleanInstallCommand) {
|
|
62
|
+
CleanInstallCommand.cliCommandOptions = {
|
|
63
|
+
...run_command_1.RunCommand.cliCommandOptions
|
|
64
|
+
};
|
|
65
|
+
function initCli(repository, program) {
|
|
66
|
+
program.command({
|
|
67
|
+
command: 'ci [...options]',
|
|
68
|
+
describe: 'Deletes all dependency modules and re-installs',
|
|
69
|
+
builder: (cmd) => {
|
|
70
|
+
return cmd
|
|
71
|
+
.example("$0 ci", '')
|
|
72
|
+
.option(CleanInstallCommand.cliCommandOptions);
|
|
73
|
+
},
|
|
74
|
+
handler: async (args) => {
|
|
75
|
+
const options = command_1.Command.composeOptions(CleanInstallCommand.commandName, args, repository.config);
|
|
76
|
+
await new CleanInstallCommand(repository, options).execute();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
CleanInstallCommand.initCli = initCli;
|
|
81
|
+
})(CleanInstallCommand = exports.CleanInstallCommand || (exports.CleanInstallCommand = {}));
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ExecuteCommand = void 0;
|
|
7
7
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const figures_1 = __importDefault(require("figures"));
|
|
10
9
|
const multi_task_command_1 = require("./multi-task-command");
|
|
11
10
|
const power_tasks_1 = require("power-tasks");
|
|
12
11
|
const exec_1 = require("../utils/exec");
|
|
@@ -18,18 +17,18 @@ class ExecuteCommand extends multi_task_command_1.MultiTaskCommand {
|
|
|
18
17
|
this.cmd = cmd;
|
|
19
18
|
this.argv = argv;
|
|
20
19
|
}
|
|
21
|
-
_prepareTasks() {
|
|
22
|
-
const packages = this.repository.getPackages({ toposort: !this.options.parallel });
|
|
20
|
+
_prepareTasks(packages) {
|
|
23
21
|
const tasks = [];
|
|
24
22
|
for (const p of packages) {
|
|
25
23
|
const task = new power_tasks_1.Task(async () => {
|
|
26
24
|
const t = Date.now();
|
|
27
|
-
npmlog_1.default.verbose(this.commandName, p.name, chalk_1.default.
|
|
25
|
+
npmlog_1.default.verbose(this.commandName, p.name, chalk_1.default.cyanBright.bold('executing'), npmlog_1.default.separator, this.cmd + ' ' + (this.argv?.join(' ') || ''));
|
|
28
26
|
const r = await (0, exec_1.exec)(this.cmd, {
|
|
29
27
|
cwd: p.dirname,
|
|
30
|
-
argv: this.argv
|
|
28
|
+
argv: this.argv,
|
|
29
|
+
stdio: npmlog_1.default.levelIndex <= 1000 ? 'inherit' : 'pipe'
|
|
31
30
|
});
|
|
32
|
-
npmlog_1.default.log((r.error ? 'error' : '
|
|
31
|
+
npmlog_1.default.log((r.error ? 'error' : 'info'), this.commandName, p.name, (r.error ? chalk_1.default.red.bold('failed') : chalk_1.default.green.bold('success')), npmlog_1.default.separator, this.cmd, chalk_1.default.yellow(' (' + (Date.now() - t) + ' ms') + ')');
|
|
33
32
|
}, {
|
|
34
33
|
name: p.name,
|
|
35
34
|
dependencies: this.options.parallel ? undefined : p.dependencies,
|
|
@@ -5,13 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MultiTaskCommand = void 0;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
8
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
10
|
-
const figures_1 = __importDefault(require("figures"));
|
|
11
9
|
const power_tasks_1 = require("power-tasks");
|
|
12
10
|
const command_1 = require("../core/command");
|
|
13
11
|
const constants_1 = require("../utils/constants");
|
|
14
|
-
const logSeparator = chalk_1.default.gray(figures_1.default.lineVerticalDashed0);
|
|
15
12
|
class MultiTaskCommand extends command_1.Command {
|
|
16
13
|
constructor(repository, options) {
|
|
17
14
|
super(options);
|
|
@@ -25,9 +22,10 @@ class MultiTaskCommand extends command_1.Command {
|
|
|
25
22
|
this.options.bail = true;
|
|
26
23
|
}
|
|
27
24
|
async _execute() {
|
|
28
|
-
const
|
|
25
|
+
const packages = await this._getPackages();
|
|
26
|
+
const childTasks = await this._prepareTasks(packages);
|
|
29
27
|
if (!(childTasks && childTasks.length)) {
|
|
30
|
-
npmlog_1.default.info(this.commandName,
|
|
28
|
+
npmlog_1.default.info(this.commandName, '', 'There is no task to process');
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
// this.enableProgress();
|
|
@@ -37,6 +35,9 @@ class MultiTaskCommand extends command_1.Command {
|
|
|
37
35
|
});
|
|
38
36
|
await this._task.toPromise().catch(() => void (0));
|
|
39
37
|
}
|
|
38
|
+
async _getPackages() {
|
|
39
|
+
return this.repository.getPackages({ toposort: !this.options.parallel });
|
|
40
|
+
}
|
|
40
41
|
}
|
|
41
42
|
exports.MultiTaskCommand = MultiTaskCommand;
|
|
42
43
|
(function (MultiTaskCommand) {
|
|
@@ -7,7 +7,6 @@ exports.PublishCommand = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const package_json_1 = __importDefault(require("package-json"));
|
|
9
9
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
10
|
-
const figures_1 = __importDefault(require("figures"));
|
|
11
10
|
const command_1 = require("../core/command");
|
|
12
11
|
const run_command_1 = require("./run-command");
|
|
13
12
|
class PublishCommand extends run_command_1.RunCommand {
|
|
@@ -15,33 +14,27 @@ class PublishCommand extends run_command_1.RunCommand {
|
|
|
15
14
|
super(repository, 'publish', options);
|
|
16
15
|
this.repository = repository;
|
|
17
16
|
}
|
|
18
|
-
async _prepareTasks() {
|
|
19
|
-
const { repository } = this;
|
|
20
|
-
const packages = repository.getPackages({ toposort: true });
|
|
17
|
+
async _prepareTasks(packages) {
|
|
21
18
|
const newVersions = {};
|
|
22
19
|
const selectedPackages = [];
|
|
23
20
|
for (const p of packages) {
|
|
24
21
|
const logPkgName = chalk_1.default.yellow(p.name);
|
|
25
22
|
const r = await (0, package_json_1.default)(p.json.name);
|
|
26
23
|
if (r.version === p.version) {
|
|
27
|
-
npmlog_1.default.info(this.commandName, logPkgName,
|
|
24
|
+
npmlog_1.default.info(this.commandName, logPkgName, npmlog_1.default.separator, `Ignored. Same version (${p.version}) in repository`);
|
|
28
25
|
continue;
|
|
29
26
|
}
|
|
30
27
|
selectedPackages.push(p);
|
|
31
28
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const childTask = this._preparePackageTask(_p, { newVersions });
|
|
40
|
-
if (childTask) {
|
|
41
|
-
tasks.push(childTask);
|
|
42
|
-
}
|
|
29
|
+
return super._prepareTasks(selectedPackages, { newVersions });
|
|
30
|
+
}
|
|
31
|
+
async _exec(args, options) {
|
|
32
|
+
if (args.command === '#') {
|
|
33
|
+
if (args.name === 'root')
|
|
34
|
+
return { code: 0 };
|
|
35
|
+
return super._exec({ ...args, command: 'npm publish' }, { ...options, stdio: 'inherit' });
|
|
43
36
|
}
|
|
44
|
-
return
|
|
37
|
+
return super._exec(args, options);
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
exports.PublishCommand = PublishCommand;
|
|
@@ -7,7 +7,6 @@ exports.RunCommand = void 0;
|
|
|
7
7
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
8
8
|
const power_tasks_1 = require("power-tasks");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const figures_1 = __importDefault(require("figures"));
|
|
11
10
|
const parse_npm_script_1 = __importDefault(require("@netlify/parse-npm-script"));
|
|
12
11
|
const multi_task_command_1 = require("./multi-task-command");
|
|
13
12
|
const command_1 = require("../core/command");
|
|
@@ -18,26 +17,45 @@ class RunCommand extends multi_task_command_1.MultiTaskCommand {
|
|
|
18
17
|
this.repository = repository;
|
|
19
18
|
this.script = script;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
_prepareTasks() {
|
|
25
|
-
const packages = this.repository.getPackages({ toposort: true });
|
|
26
|
-
const tasks = [];
|
|
20
|
+
_prepareTasks(packages, options) {
|
|
21
|
+
const packageTasks = [];
|
|
27
22
|
for (const p of packages) {
|
|
28
23
|
if (p.json.scripts) {
|
|
29
|
-
const childTask = this.
|
|
24
|
+
const childTask = this._prepareScriptTask({
|
|
25
|
+
name: p.name,
|
|
26
|
+
cwd: p.dirname,
|
|
27
|
+
json: p.json,
|
|
28
|
+
dependencies: p.dependencies
|
|
29
|
+
}, options);
|
|
30
30
|
if (childTask) {
|
|
31
|
-
|
|
31
|
+
packageTasks.push(childTask);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
const mainTask = this._prepareScriptTask({
|
|
36
|
+
name: 'root',
|
|
37
|
+
cwd: this.repository.dirname,
|
|
38
|
+
json: this.repository.json
|
|
39
|
+
});
|
|
40
|
+
if (!mainTask?.children)
|
|
41
|
+
return packageTasks;
|
|
42
|
+
const tasks = [];
|
|
43
|
+
const pre = mainTask.children.filter((t => t.name.endsWith(':pre' + this.script)));
|
|
44
|
+
const post = mainTask.children.filter((t => t.name.endsWith(':post' + this.script)));
|
|
45
|
+
pre.forEach(t => t.options.exclusive = true);
|
|
46
|
+
post.forEach(t => t.options.exclusive = true);
|
|
47
|
+
tasks.push(...pre);
|
|
48
|
+
tasks.push(...packageTasks);
|
|
49
|
+
tasks.push(...post);
|
|
35
50
|
return tasks;
|
|
36
51
|
}
|
|
37
|
-
|
|
52
|
+
_prepareScriptTask(args, ctx) {
|
|
53
|
+
const json = { ...args.json };
|
|
54
|
+
json.scripts = json.scripts || {};
|
|
55
|
+
json.scripts[this.script] = json.scripts[this.script] || '#';
|
|
38
56
|
let scriptInfo;
|
|
39
57
|
try {
|
|
40
|
-
scriptInfo = (0, parse_npm_script_1.default)(
|
|
58
|
+
scriptInfo = (0, parse_npm_script_1.default)(json, 'npm run ' + this.script);
|
|
41
59
|
if (!(scriptInfo && scriptInfo.raw))
|
|
42
60
|
return;
|
|
43
61
|
}
|
|
@@ -49,37 +67,41 @@ class RunCommand extends multi_task_command_1.MultiTaskCommand {
|
|
|
49
67
|
const parsed = Array.isArray(s.parsed) ? s.parsed : [s.parsed];
|
|
50
68
|
for (const cmd of parsed) {
|
|
51
69
|
const task = new power_tasks_1.Task(async () => {
|
|
52
|
-
return await this._exec(
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
return await this._exec({
|
|
71
|
+
...args,
|
|
72
|
+
command: cmd,
|
|
73
|
+
stdio: npmlog_1.default.levelIndex <= 1000 ? 'inherit' : 'pipe'
|
|
55
74
|
}, ctx);
|
|
56
75
|
}, {
|
|
57
|
-
name:
|
|
76
|
+
name: args.name + ':' + s.name,
|
|
58
77
|
dependencies: s.name.startsWith('pre') || s.name.startsWith('post') ?
|
|
59
|
-
undefined :
|
|
78
|
+
undefined : args.dependencies
|
|
60
79
|
});
|
|
61
80
|
children.push(task);
|
|
62
81
|
}
|
|
63
82
|
}
|
|
64
83
|
if (children.length) {
|
|
65
84
|
return new power_tasks_1.Task(children, {
|
|
66
|
-
name:
|
|
85
|
+
name: args.name,
|
|
67
86
|
bail: true,
|
|
68
87
|
serial: true,
|
|
69
88
|
});
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
|
-
async _exec(
|
|
73
|
-
|
|
91
|
+
async _exec(args, options) {
|
|
92
|
+
const logLevel = args.logLevel == null ? 'info' : args.logLevel;
|
|
93
|
+
if (logLevel)
|
|
94
|
+
npmlog_1.default.log(logLevel, this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.cyanBright.bold('executing'), npmlog_1.default.separator, args.command);
|
|
74
95
|
const t = Date.now();
|
|
75
|
-
const r = await (0, exec_1.exec)(command,
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
const r = await (0, exec_1.exec)(args.command, { cwd: args.cwd, stdio: args.stdio });
|
|
97
|
+
if (logLevel)
|
|
98
|
+
if (r.error) {
|
|
99
|
+
npmlog_1.default.error(this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.red.bold('failed'), npmlog_1.default.separator, args.command, npmlog_1.default.separator, r.error.message.trim());
|
|
100
|
+
npmlog_1.default.verbose(this.commandName, '', r.stderr || r.stdout);
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
npmlog_1.default.log(logLevel, this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.green.bold('executed'), npmlog_1.default.separator, args.command, chalk_1.default.yellow(' (' + (Date.now() - t) + ' ms)'));
|
|
104
|
+
if (r.error && !args.noThrow)
|
|
83
105
|
throw r.error;
|
|
84
106
|
return r;
|
|
85
107
|
}
|
|
@@ -5,27 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VersionCommand = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
9
|
const semver_1 = __importDefault(require("semver"));
|
|
11
10
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
12
11
|
const strip_color_1 = __importDefault(require("strip-color"));
|
|
13
|
-
const
|
|
12
|
+
const power_tasks_1 = require("power-tasks");
|
|
14
13
|
const run_command_1 = require("./run-command");
|
|
15
14
|
const git_utils_1 = require("../utils/git-utils");
|
|
16
15
|
const command_1 = require("../core/command");
|
|
16
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
17
|
class VersionCommand extends run_command_1.RunCommand {
|
|
18
18
|
constructor(repository, bump, options) {
|
|
19
19
|
super(repository, 'version', options);
|
|
20
20
|
this.repository = repository;
|
|
21
21
|
this.bump = bump;
|
|
22
22
|
}
|
|
23
|
-
async _prepareTasks() {
|
|
23
|
+
async _prepareTasks(packages) {
|
|
24
24
|
const { repository } = this;
|
|
25
25
|
const git = new git_utils_1.GitHelper({ cwd: repository.dirname });
|
|
26
26
|
const dirtyFiles = await git.listDirtyFiles();
|
|
27
27
|
const committedFiles = await git.listCommittedFiles();
|
|
28
|
-
const packages = repository.getPackages({ toposort: true });
|
|
29
28
|
const newVersions = {};
|
|
30
29
|
let errorCount = 0;
|
|
31
30
|
const selectedPackages = [];
|
|
@@ -35,7 +34,7 @@ class VersionCommand extends run_command_1.RunCommand {
|
|
|
35
34
|
let message = '';
|
|
36
35
|
let newVer = '';
|
|
37
36
|
const logPkgName = chalk_1.default.yellow(p.name);
|
|
38
|
-
if (!this.options.
|
|
37
|
+
if (!this.options.noTag) {
|
|
39
38
|
const isDirty = dirtyFiles.find(f => !path_1.default.relative(relDir, f).startsWith('..'));
|
|
40
39
|
if (isDirty) {
|
|
41
40
|
if (!this.options.ignoreDirty)
|
|
@@ -66,47 +65,63 @@ class VersionCommand extends run_command_1.RunCommand {
|
|
|
66
65
|
message: (0, strip_color_1.default)(message),
|
|
67
66
|
});
|
|
68
67
|
else
|
|
69
|
-
npmlog_1.default.log(this.options.ignoreDirty ? 'info' : 'error', this.commandName, logPkgName, chalk_1.default.
|
|
68
|
+
npmlog_1.default.log(this.options.ignoreDirty ? 'info' : 'error', this.commandName, logPkgName, chalk_1.default.whiteBright(p.version), status, npmlog_1.default.separator, message);
|
|
70
69
|
continue;
|
|
71
70
|
}
|
|
72
71
|
selectedPackages.push(p);
|
|
73
72
|
}
|
|
74
73
|
if (errorCount)
|
|
75
74
|
throw new Error('Unable to bump version due to error(s)');
|
|
75
|
+
const maxVer = Object.values(newVersions).reduce((m, v) => {
|
|
76
|
+
return semver_1.default.gt(m, v) ? m : v;
|
|
77
|
+
}, '0.0.0');
|
|
76
78
|
if (this.options.unified) {
|
|
77
|
-
const maxVer = Object.values(newVersions).reduce((m, v) => {
|
|
78
|
-
return semver_1.default.gt(m, v) ? m : v;
|
|
79
|
-
}, '0.0.0');
|
|
80
79
|
Object.keys(newVersions).forEach(k => newVersions[k] = maxVer);
|
|
81
80
|
}
|
|
82
|
-
const tasks =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
const tasks = await super._prepareTasks(selectedPackages, { newVersions });
|
|
82
|
+
tasks.forEach(t => t.options.exclusive = true);
|
|
83
|
+
if (this.options.unified)
|
|
84
|
+
tasks.push(new power_tasks_1.Task(async () => {
|
|
85
|
+
try {
|
|
86
|
+
await super._exec({
|
|
87
|
+
name: 'rman',
|
|
88
|
+
command: 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"',
|
|
89
|
+
cwd: this.repository.dirname,
|
|
90
|
+
stdio: npmlog_1.default.levelIndex <= 1000 ? 'inherit' : 'pipe',
|
|
91
|
+
logLevel: 'silly'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
//
|
|
96
|
+
}
|
|
97
|
+
}, { exclusive: true }));
|
|
94
98
|
return tasks;
|
|
95
99
|
}
|
|
96
|
-
async _exec(
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
async _exec(args, options) {
|
|
101
|
+
if (args.name === 'root')
|
|
102
|
+
return { code: 0 };
|
|
103
|
+
if (args.command === '#') {
|
|
104
|
+
const { newVersions } = options;
|
|
105
|
+
const oldVer = args.json.version;
|
|
106
|
+
const newVer = newVersions[args.name];
|
|
107
|
+
args.json.version = newVer;
|
|
108
|
+
delete args.json.scripts.version;
|
|
109
|
+
const f = path_1.default.join(args.cwd, 'package.json');
|
|
110
|
+
const data = JSON.stringify(args.json, undefined, 2);
|
|
111
|
+
await promises_1.default.writeFile(f, data, 'utf-8');
|
|
112
|
+
if (!this.options.noTag) {
|
|
113
|
+
await super._exec({
|
|
114
|
+
name: args.name,
|
|
115
|
+
command: 'git commit -m "' + newVer + '" package.json',
|
|
116
|
+
cwd: args.cwd,
|
|
117
|
+
stdio: npmlog_1.default.levelIndex <= 1000 ? 'inherit' : 'pipe',
|
|
118
|
+
logLevel: 'silly'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
npmlog_1.default.info(this.commandName, args.name, npmlog_1.default.separator, 'Version changed from ' + chalk_1.default.cyan(oldVer) + ' to ' + chalk_1.default.cyan(newVer));
|
|
107
122
|
return { code: 0 };
|
|
108
123
|
}
|
|
109
|
-
return super._exec(
|
|
124
|
+
return super._exec(args, options);
|
|
110
125
|
}
|
|
111
126
|
}
|
|
112
127
|
exports.VersionCommand = VersionCommand;
|
|
@@ -125,12 +140,12 @@ VersionCommand.commandName = 'version';
|
|
|
125
140
|
},
|
|
126
141
|
'ignore-dirty': {
|
|
127
142
|
alias: 'i',
|
|
128
|
-
describe: '#
|
|
143
|
+
describe: '# Do not bump version for dirty packages',
|
|
129
144
|
type: 'boolean'
|
|
130
145
|
},
|
|
131
|
-
'
|
|
132
|
-
alias: '
|
|
133
|
-
describe: '#
|
|
146
|
+
'no-tag': {
|
|
147
|
+
alias: 'n',
|
|
148
|
+
describe: '# Do not crate git version tag. (Ignores dirty check)',
|
|
134
149
|
type: 'boolean'
|
|
135
150
|
}
|
|
136
151
|
};
|
package/cjs/core/command.js
CHANGED
|
@@ -10,6 +10,9 @@ const is_ci_1 = __importDefault(require("is-ci"));
|
|
|
10
10
|
const putil_merge_1 = __importDefault(require("putil-merge"));
|
|
11
11
|
require("./logger");
|
|
12
12
|
const constants_1 = require("../utils/constants");
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const figures_1 = __importDefault(require("figures"));
|
|
15
|
+
const npmlog_2 = __importDefault(require("npmlog"));
|
|
13
16
|
const noOp = () => void (0);
|
|
14
17
|
class Command extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
15
18
|
constructor(options) {
|
|
@@ -20,6 +23,12 @@ class Command extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_t
|
|
|
20
23
|
this._options = options || {};
|
|
21
24
|
if (is_ci_1.default)
|
|
22
25
|
this.options.ci = true;
|
|
26
|
+
this.logger.separator = chalk_1.default.gray(figures_1.default.lineVerticalDashed0);
|
|
27
|
+
Object.defineProperty(this.logger, 'levelIndex', {
|
|
28
|
+
get() {
|
|
29
|
+
return npmlog_2.default.levels[npmlog_2.default.level] || 0;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
23
32
|
}
|
|
24
33
|
get options() {
|
|
25
34
|
return this._options;
|
|
@@ -56,7 +65,7 @@ class Command extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_t
|
|
|
56
65
|
await this.emitAsync('finish', undefined, v).catch(noOp);
|
|
57
66
|
this.disableProgress();
|
|
58
67
|
this.logger.resume();
|
|
59
|
-
this.logger.
|
|
68
|
+
this.logger.info('', 'Command completed');
|
|
60
69
|
return v;
|
|
61
70
|
}
|
|
62
71
|
catch (e) {
|
|
@@ -76,6 +85,10 @@ class Command extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_t
|
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
87
|
disableProgress() {
|
|
88
|
+
//
|
|
89
|
+
}
|
|
90
|
+
async _preExecute() {
|
|
91
|
+
npmlog_2.default.info('rman', `Executing "${this.commandName}" command`);
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
94
|
exports.Command = Command;
|
|
@@ -100,8 +113,8 @@ exports.Command = Command;
|
|
|
100
113
|
function composeOptions(commandName, yargArgs, config) {
|
|
101
114
|
const result = (0, putil_merge_1.default)({}, yargArgs);
|
|
102
115
|
(0, putil_merge_1.default)(result, config, { filter: (_, key) => key !== 'command' });
|
|
103
|
-
const cfgCmd = config.
|
|
104
|
-
config.command : undefined;
|
|
116
|
+
const cfgCmd = config.command && typeof config.command === 'object' ?
|
|
117
|
+
config.command[commandName] : undefined;
|
|
105
118
|
if (cfgCmd && typeof cfgCmd === 'object')
|
|
106
119
|
(0, putil_merge_1.default)(result, cfgCmd);
|
|
107
120
|
return result;
|
package/cjs/core/logger.js
CHANGED
|
@@ -4,5 +4,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const npmlog_1 = __importDefault(require("npmlog"));
|
|
7
|
-
npmlog_1.default.addLevel("success", 1500, { fg: "green", bold: true });
|
|
8
7
|
npmlog_1.default.addLevel('output', 3300, {}, '');
|
|
@@ -0,0 +1,34 @@
|
|
|
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.fsDelete = exports.tryStat = exports.fsExists = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
async function fsExists(s) {
|
|
10
|
+
return promises_1.default.lstat(s).then(() => true).catch(() => false);
|
|
11
|
+
}
|
|
12
|
+
exports.fsExists = fsExists;
|
|
13
|
+
async function tryStat(s) {
|
|
14
|
+
return promises_1.default.lstat(s).catch(() => undefined);
|
|
15
|
+
}
|
|
16
|
+
exports.tryStat = tryStat;
|
|
17
|
+
async function fsDelete(fileOrDir) {
|
|
18
|
+
const stat = await tryStat(fileOrDir);
|
|
19
|
+
if (stat) {
|
|
20
|
+
if (stat.isFile() || stat.isSymbolicLink()) {
|
|
21
|
+
await promises_1.default.unlink(fileOrDir);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (stat.isDirectory()) {
|
|
25
|
+
const list = await promises_1.default.readdir(fileOrDir);
|
|
26
|
+
for (const file of list)
|
|
27
|
+
await fsDelete(path_1.default.join(fileOrDir, file));
|
|
28
|
+
await promises_1.default.rmdir(fileOrDir);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
exports.fsDelete = fsDelete;
|
package/esm/cli.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { ExecuteCommand } from './commands/execute-command.mjs';
|
|
|
12
12
|
import { RunCommand } from './commands/run-command.mjs';
|
|
13
13
|
import { VersionCommand } from './commands/version-command.mjs';
|
|
14
14
|
import { PublishCommand } from './commands/publish-command.mjs';
|
|
15
|
+
import { CleanInstallCommand } from './commands/ci-command.mjs';
|
|
15
16
|
export async function runCli(options) {
|
|
16
17
|
const s = path.resolve(getDirname(), '../package.json');
|
|
17
18
|
const pkgJson = JSON.parse(await fs.readFile(s, 'utf-8'));
|
|
@@ -42,6 +43,7 @@ export async function runCli(options) {
|
|
|
42
43
|
RunCommand.initCli(repository, program);
|
|
43
44
|
VersionCommand.initCli(repository, program);
|
|
44
45
|
PublishCommand.initCli(repository, program);
|
|
46
|
+
CleanInstallCommand.initCli(repository, program);
|
|
45
47
|
if (!_argv.length)
|
|
46
48
|
program.showHelp();
|
|
47
49
|
else
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { Task } from 'power-tasks';
|
|
3
|
+
import { Repository } from '../core/repository';
|
|
4
|
+
import { Package } from '../core/package';
|
|
5
|
+
import { RunCommand } from './run-command';
|
|
6
|
+
import { ExecuteCommandResult } from '../utils/exec';
|
|
7
|
+
export declare class CleanInstallCommand extends RunCommand<CleanInstallCommand.Options> {
|
|
8
|
+
readonly repository: Repository;
|
|
9
|
+
static commandName: string;
|
|
10
|
+
constructor(repository: Repository, options?: CleanInstallCommand.Options);
|
|
11
|
+
protected _prepareTasks(packages: Package[]): Promise<Task[]>;
|
|
12
|
+
protected _exec(args: {
|
|
13
|
+
name: string;
|
|
14
|
+
json: any;
|
|
15
|
+
cwd: string;
|
|
16
|
+
dependencies?: string[];
|
|
17
|
+
command: string;
|
|
18
|
+
}, ctx?: any): Promise<ExecuteCommandResult>;
|
|
19
|
+
protected _fsDelete(fileOrDir: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare namespace CleanInstallCommand {
|
|
22
|
+
interface Options extends RunCommand.Options {
|
|
23
|
+
}
|
|
24
|
+
const cliCommandOptions: Record<string, yargs.Options>;
|
|
25
|
+
function initCli(repository: Repository, program: yargs.Argv): void;
|
|
26
|
+
}
|