rman 0.5.1 → 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.
@@ -29,7 +29,7 @@ class CleanInstallCommand extends run_command_1.RunCommand {
29
29
  npmlog_1.default.info(this.commandName, chalk_1.default.yellow('installing'), 'Running ' + client + ' install');
30
30
  return super._exec({
31
31
  name: 'root',
32
- dirname: this.repository.dirname,
32
+ cwd: this.repository.dirname,
33
33
  json: { ...this.repository.json },
34
34
  command: client + ' install',
35
35
  stdio: 'inherit'
@@ -41,10 +41,10 @@ class CleanInstallCommand extends run_command_1.RunCommand {
41
41
  if (args.command === '#') {
42
42
  if (args.name === 'root')
43
43
  return { code: 0 };
44
- const { dirname } = args;
45
- await this._fsDelete(path_1.default.join(dirname, 'node_modules'));
46
- await this._fsDelete(path_1.default.join(dirname, 'package-lock.json'));
47
- await this._fsDelete(path_1.default.join(dirname, 'yarn-lock.json'));
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
48
  return { code: 0 };
49
49
  }
50
50
  return super._exec(args, ctx);
@@ -23,7 +23,7 @@ class RunCommand extends multi_task_command_1.MultiTaskCommand {
23
23
  if (p.json.scripts) {
24
24
  const childTask = this._prepareScriptTask({
25
25
  name: p.name,
26
- dirname: p.dirname,
26
+ cwd: p.dirname,
27
27
  json: p.json,
28
28
  dependencies: p.dependencies
29
29
  }, options);
@@ -34,7 +34,7 @@ class RunCommand extends multi_task_command_1.MultiTaskCommand {
34
34
  }
35
35
  const mainTask = this._prepareScriptTask({
36
36
  name: 'root',
37
- dirname: this.repository.dirname,
37
+ cwd: this.repository.dirname,
38
38
  json: this.repository.json
39
39
  });
40
40
  if (!mainTask?.children)
@@ -89,16 +89,19 @@ class RunCommand extends multi_task_command_1.MultiTaskCommand {
89
89
  }
90
90
  }
91
91
  async _exec(args, options) {
92
- npmlog_1.default.verbose(this.commandName, chalk_1.default.cyan(args.name), chalk_1.default.cyanBright.bold('executing'), npmlog_1.default.separator, args.command);
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);
93
95
  const t = Date.now();
94
- const r = await (0, exec_1.exec)(args.command, { cwd: args.dirname, stdio: args.stdio });
95
- if (r.error) {
96
- 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());
97
- npmlog_1.default.verbose(this.commandName, '', r.stderr || r.stdout);
98
- }
99
- else
100
- npmlog_1.default.info(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)'));
101
- if (r.error)
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)
102
105
  throw r.error;
103
106
  return r;
104
107
  }
@@ -5,14 +5,15 @@ 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"));
12
+ const power_tasks_1 = require("power-tasks");
13
13
  const run_command_1 = require("./run-command");
14
14
  const git_utils_1 = require("../utils/git-utils");
15
15
  const command_1 = require("../core/command");
16
+ const promises_1 = __importDefault(require("fs/promises"));
16
17
  class VersionCommand extends run_command_1.RunCommand {
17
18
  constructor(repository, bump, options) {
18
19
  super(repository, 'version', options);
@@ -33,7 +34,7 @@ class VersionCommand extends run_command_1.RunCommand {
33
34
  let message = '';
34
35
  let newVer = '';
35
36
  const logPkgName = chalk_1.default.yellow(p.name);
36
- if (!this.options.forceDirty) {
37
+ if (!this.options.noTag) {
37
38
  const isDirty = dirtyFiles.find(f => !path_1.default.relative(relDir, f).startsWith('..'));
38
39
  if (isDirty) {
39
40
  if (!this.options.ignoreDirty)
@@ -71,13 +72,30 @@ class VersionCommand extends run_command_1.RunCommand {
71
72
  }
72
73
  if (errorCount)
73
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');
74
78
  if (this.options.unified) {
75
- const maxVer = Object.values(newVersions).reduce((m, v) => {
76
- return semver_1.default.gt(m, v) ? m : v;
77
- }, '0.0.0');
78
79
  Object.keys(newVersions).forEach(k => newVersions[k] = maxVer);
79
80
  }
80
- return super._prepareTasks(selectedPackages, { newVersions });
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 }));
98
+ return tasks;
81
99
  }
82
100
  async _exec(args, options) {
83
101
  if (args.name === 'root')
@@ -88,9 +106,18 @@ class VersionCommand extends run_command_1.RunCommand {
88
106
  const newVer = newVersions[args.name];
89
107
  args.json.version = newVer;
90
108
  delete args.json.scripts.version;
91
- const f = path_1.default.join(args.dirname, 'package.json');
109
+ const f = path_1.default.join(args.cwd, 'package.json');
92
110
  const data = JSON.stringify(args.json, undefined, 2);
93
- fs_1.default.writeFileSync(f, data, 'utf-8');
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
+ }
94
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));
95
122
  return { code: 0 };
96
123
  }
@@ -113,12 +140,12 @@ VersionCommand.commandName = 'version';
113
140
  },
114
141
  'ignore-dirty': {
115
142
  alias: 'i',
116
- describe: '# Ignore dirty packages',
143
+ describe: '# Do not bump version for dirty packages',
117
144
  type: 'boolean'
118
145
  },
119
- 'force-dirty': {
120
- alias: 'f',
121
- describe: '# Force bump version for dirty packages',
146
+ 'no-tag': {
147
+ alias: 'n',
148
+ describe: '# Do not crate git version tag. (Ignores dirty check)',
122
149
  type: 'boolean'
123
150
  }
124
151
  };
@@ -12,7 +12,7 @@ export declare class CleanInstallCommand extends RunCommand<CleanInstallCommand.
12
12
  protected _exec(args: {
13
13
  name: string;
14
14
  json: any;
15
- dirname: string;
15
+ cwd: string;
16
16
  dependencies?: string[];
17
17
  command: string;
18
18
  }, ctx?: any): Promise<ExecuteCommandResult>;
@@ -23,7 +23,7 @@ export class CleanInstallCommand extends RunCommand {
23
23
  logger.info(this.commandName, chalk.yellow('installing'), 'Running ' + client + ' install');
24
24
  return super._exec({
25
25
  name: 'root',
26
- dirname: this.repository.dirname,
26
+ cwd: this.repository.dirname,
27
27
  json: { ...this.repository.json },
28
28
  command: client + ' install',
29
29
  stdio: 'inherit'
@@ -35,10 +35,10 @@ export class CleanInstallCommand extends RunCommand {
35
35
  if (args.command === '#') {
36
36
  if (args.name === 'root')
37
37
  return { code: 0 };
38
- const { dirname } = args;
39
- await this._fsDelete(path.join(dirname, 'node_modules'));
40
- await this._fsDelete(path.join(dirname, 'package-lock.json'));
41
- await this._fsDelete(path.join(dirname, 'yarn-lock.json'));
38
+ const { cwd } = args;
39
+ await this._fsDelete(path.join(cwd, 'node_modules'));
40
+ await this._fsDelete(path.join(cwd, 'package-lock.json'));
41
+ await this._fsDelete(path.join(cwd, 'yarn-lock.json'));
42
42
  return { code: 0 };
43
43
  }
44
44
  return super._exec(args, ctx);
@@ -12,7 +12,7 @@ export declare class PublishCommand extends RunCommand<PublishCommand.Options> {
12
12
  protected _exec(args: {
13
13
  name: string;
14
14
  json: any;
15
- dirname: string;
15
+ cwd: string;
16
16
  dependencies?: string[];
17
17
  command: string;
18
18
  }, options?: any): Promise<ExecuteCommandResult>;
@@ -13,16 +13,18 @@ export declare class RunCommand<TOptions extends RunCommand.Options> extends Mul
13
13
  protected _prepareScriptTask(args: {
14
14
  name: string;
15
15
  json: any;
16
- dirname: string;
16
+ cwd: string;
17
17
  dependencies?: string[];
18
18
  }, ctx?: any): Task | undefined;
19
19
  protected _exec(args: {
20
20
  name: string;
21
- json: any;
22
- dirname: string;
21
+ cwd: string;
23
22
  dependencies?: string[];
24
23
  command: string;
25
24
  stdio?: 'inherit' | 'pipe';
25
+ json?: any;
26
+ logLevel?: string;
27
+ noThrow?: boolean;
26
28
  }, options?: any): Promise<ExecuteCommandResult>;
27
29
  }
28
30
  export declare namespace RunCommand {
@@ -17,7 +17,7 @@ export class RunCommand extends MultiTaskCommand {
17
17
  if (p.json.scripts) {
18
18
  const childTask = this._prepareScriptTask({
19
19
  name: p.name,
20
- dirname: p.dirname,
20
+ cwd: p.dirname,
21
21
  json: p.json,
22
22
  dependencies: p.dependencies
23
23
  }, options);
@@ -28,7 +28,7 @@ export class RunCommand extends MultiTaskCommand {
28
28
  }
29
29
  const mainTask = this._prepareScriptTask({
30
30
  name: 'root',
31
- dirname: this.repository.dirname,
31
+ cwd: this.repository.dirname,
32
32
  json: this.repository.json
33
33
  });
34
34
  if (!mainTask?.children)
@@ -83,16 +83,19 @@ export class RunCommand extends MultiTaskCommand {
83
83
  }
84
84
  }
85
85
  async _exec(args, options) {
86
- logger.verbose(this.commandName, chalk.cyan(args.name), chalk.cyanBright.bold('executing'), logger.separator, args.command);
86
+ const logLevel = args.logLevel == null ? 'info' : args.logLevel;
87
+ if (logLevel)
88
+ logger.log(logLevel, this.commandName, chalk.cyan(args.name), chalk.cyanBright.bold('executing'), logger.separator, args.command);
87
89
  const t = Date.now();
88
- const r = await exec(args.command, { cwd: args.dirname, stdio: args.stdio });
89
- if (r.error) {
90
- logger.error(this.commandName, chalk.cyan(args.name), chalk.red.bold('failed'), logger.separator, args.command, logger.separator, r.error.message.trim());
91
- logger.verbose(this.commandName, '', r.stderr || r.stdout);
92
- }
93
- else
94
- logger.info(this.commandName, chalk.cyan(args.name), chalk.green.bold('executed'), logger.separator, args.command, chalk.yellow(' (' + (Date.now() - t) + ' ms)'));
95
- if (r.error)
90
+ const r = await exec(args.command, { cwd: args.cwd, stdio: args.stdio });
91
+ if (logLevel)
92
+ if (r.error) {
93
+ logger.error(this.commandName, chalk.cyan(args.name), chalk.red.bold('failed'), logger.separator, args.command, logger.separator, r.error.message.trim());
94
+ logger.verbose(this.commandName, '', r.stderr || r.stdout);
95
+ }
96
+ else
97
+ logger.log(logLevel, this.commandName, chalk.cyan(args.name), chalk.green.bold('executed'), logger.separator, args.command, chalk.yellow(' (' + (Date.now() - t) + ' ms)'));
98
+ if (r.error && !args.noThrow)
96
99
  throw r.error;
97
100
  return r;
98
101
  }
@@ -13,7 +13,7 @@ export declare class VersionCommand extends RunCommand<VersionCommand.Options> {
13
13
  protected _exec(args: {
14
14
  name: string;
15
15
  json: any;
16
- dirname: string;
16
+ cwd: string;
17
17
  dependencies?: string[];
18
18
  command: string;
19
19
  }, options?: any): Promise<ExecuteCommandResult>;
@@ -23,7 +23,7 @@ export declare namespace VersionCommand {
23
23
  unified?: boolean;
24
24
  all?: boolean;
25
25
  ignoreDirty?: boolean;
26
- forceDirty?: boolean;
26
+ noTag?: boolean;
27
27
  }
28
28
  const cliCommandOptions: Record<string, yargs.Options>;
29
29
  function initCli(repository: Repository, program: yargs.Argv): void;
@@ -1,12 +1,13 @@
1
1
  import path from 'path';
2
- import fs from 'fs';
3
2
  import chalk from 'chalk';
4
3
  import semver from 'semver';
5
4
  import logger from 'npmlog';
6
5
  import stripColor from 'strip-color';
6
+ import { Task } from 'power-tasks';
7
7
  import { RunCommand } from './run-command.mjs';
8
8
  import { GitHelper } from './../utils/git-utils.mjs';
9
9
  import { Command } from './../core/command.mjs';
10
+ import fs from 'fs/promises';
10
11
  export class VersionCommand extends RunCommand {
11
12
  constructor(repository, bump, options) {
12
13
  super(repository, 'version', options);
@@ -27,7 +28,7 @@ export class VersionCommand extends RunCommand {
27
28
  let message = '';
28
29
  let newVer = '';
29
30
  const logPkgName = chalk.yellow(p.name);
30
- if (!this.options.forceDirty) {
31
+ if (!this.options.noTag) {
31
32
  const isDirty = dirtyFiles.find(f => !path.relative(relDir, f).startsWith('..'));
32
33
  if (isDirty) {
33
34
  if (!this.options.ignoreDirty)
@@ -65,13 +66,30 @@ export class VersionCommand extends RunCommand {
65
66
  }
66
67
  if (errorCount)
67
68
  throw new Error('Unable to bump version due to error(s)');
69
+ const maxVer = Object.values(newVersions).reduce((m, v) => {
70
+ return semver.gt(m, v) ? m : v;
71
+ }, '0.0.0');
68
72
  if (this.options.unified) {
69
- const maxVer = Object.values(newVersions).reduce((m, v) => {
70
- return semver.gt(m, v) ? m : v;
71
- }, '0.0.0');
72
73
  Object.keys(newVersions).forEach(k => newVersions[k] = maxVer);
73
74
  }
74
- return super._prepareTasks(selectedPackages, { newVersions });
75
+ const tasks = await super._prepareTasks(selectedPackages, { newVersions });
76
+ tasks.forEach(t => t.options.exclusive = true);
77
+ if (this.options.unified)
78
+ tasks.push(new Task(async () => {
79
+ try {
80
+ await super._exec({
81
+ name: 'rman',
82
+ command: 'git tag -a "v' + maxVer + '" -m "version ' + maxVer + '"',
83
+ cwd: this.repository.dirname,
84
+ stdio: logger.levelIndex <= 1000 ? 'inherit' : 'pipe',
85
+ logLevel: 'silly'
86
+ });
87
+ }
88
+ catch {
89
+ //
90
+ }
91
+ }, { exclusive: true }));
92
+ return tasks;
75
93
  }
76
94
  async _exec(args, options) {
77
95
  if (args.name === 'root')
@@ -82,9 +100,18 @@ export class VersionCommand extends RunCommand {
82
100
  const newVer = newVersions[args.name];
83
101
  args.json.version = newVer;
84
102
  delete args.json.scripts.version;
85
- const f = path.join(args.dirname, 'package.json');
103
+ const f = path.join(args.cwd, 'package.json');
86
104
  const data = JSON.stringify(args.json, undefined, 2);
87
- fs.writeFileSync(f, data, 'utf-8');
105
+ await fs.writeFile(f, data, 'utf-8');
106
+ if (!this.options.noTag) {
107
+ await super._exec({
108
+ name: args.name,
109
+ command: 'git commit -m "' + newVer + '" package.json',
110
+ cwd: args.cwd,
111
+ stdio: logger.levelIndex <= 1000 ? 'inherit' : 'pipe',
112
+ logLevel: 'silly'
113
+ });
114
+ }
88
115
  logger.info(this.commandName, args.name, logger.separator, 'Version changed from ' + chalk.cyan(oldVer) + ' to ' + chalk.cyan(newVer));
89
116
  return { code: 0 };
90
117
  }
@@ -106,12 +133,12 @@ VersionCommand.commandName = 'version';
106
133
  },
107
134
  'ignore-dirty': {
108
135
  alias: 'i',
109
- describe: '# Ignore dirty packages',
136
+ describe: '# Do not bump version for dirty packages',
110
137
  type: 'boolean'
111
138
  },
112
- 'force-dirty': {
113
- alias: 'f',
114
- describe: '# Force bump version for dirty packages',
139
+ 'no-tag': {
140
+ alias: 'n',
141
+ describe: '# Do not crate git version tag. (Ignores dirty check)',
115
142
  type: 'boolean'
116
143
  }
117
144
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Monorepo repository manager",
4
- "version": "0.5.1",
4
+ "version": "0.6.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "contributors": [