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.
Files changed (82) hide show
  1. package/bin/rman.js +2 -2
  2. package/cjs/cli.js +48 -58
  3. package/cjs/commands/changed-command.js +38 -0
  4. package/cjs/commands/execute-command.js +79 -0
  5. package/cjs/commands/info-command.js +66 -0
  6. package/cjs/commands/list-command.js +141 -0
  7. package/cjs/commands/multi-task-command.js +70 -0
  8. package/cjs/commands/publish-command.js +74 -0
  9. package/cjs/commands/run-command.js +103 -0
  10. package/cjs/commands/version-command.js +155 -0
  11. package/cjs/core/command.js +110 -0
  12. package/cjs/core/config.js +73 -0
  13. package/cjs/core/logger.js +8 -0
  14. package/cjs/core/package.js +33 -0
  15. package/cjs/core/repository.js +133 -0
  16. package/cjs/{workspace → core}/types.js +0 -0
  17. package/cjs/debug.js +5 -0
  18. package/cjs/index.js +1 -1
  19. package/cjs/utils/constants.js +5 -0
  20. package/cjs/{workspace/executor.js → utils/exec.js} +20 -19
  21. package/cjs/utils/git-utils.js +70 -0
  22. package/cjs/utils/npm-run-path.js +63 -0
  23. package/cjs/utils.js +36 -0
  24. package/esm/cli.d.ts +4 -1
  25. package/esm/cli.mjs +46 -56
  26. package/esm/commands/changed-command.d.ts +16 -0
  27. package/esm/commands/changed-command.mjs +34 -0
  28. package/esm/commands/execute-command.d.ts +18 -0
  29. package/esm/commands/execute-command.mjs +72 -0
  30. package/esm/commands/info-command.d.ts +10 -0
  31. package/esm/commands/info-command.mjs +59 -0
  32. package/esm/commands/list-command.d.ts +38 -0
  33. package/esm/commands/list-command.mjs +134 -0
  34. package/esm/commands/multi-task-command.d.ts +20 -0
  35. package/esm/commands/multi-task-command.mjs +63 -0
  36. package/esm/commands/publish-command.d.ts +17 -0
  37. package/esm/commands/publish-command.mjs +67 -0
  38. package/esm/commands/run-command.d.ts +22 -0
  39. package/esm/commands/run-command.mjs +96 -0
  40. package/esm/commands/version-command.d.ts +24 -0
  41. package/esm/commands/version-command.mjs +148 -0
  42. package/esm/core/command.d.ts +35 -0
  43. package/esm/core/command.mjs +103 -0
  44. package/esm/core/config.d.ts +9 -0
  45. package/esm/core/config.mjs +66 -0
  46. package/esm/core/logger.d.ts +10 -0
  47. package/esm/core/logger.mjs +3 -0
  48. package/esm/core/package.d.ts +11 -0
  49. package/esm/core/package.mjs +26 -0
  50. package/esm/core/repository.d.ts +18 -0
  51. package/esm/core/repository.mjs +126 -0
  52. package/esm/core/types.d.ts +14 -0
  53. package/esm/{workspace → core}/types.mjs +0 -0
  54. package/esm/debug.d.ts +1 -0
  55. package/esm/debug.mjs +3 -0
  56. package/esm/index.d.ts +1 -1
  57. package/esm/index.mjs +1 -1
  58. package/esm/utils/constants.d.ts +2 -0
  59. package/esm/utils/constants.mjs +2 -0
  60. package/esm/{workspace/executor.d.ts → utils/exec.d.ts} +5 -8
  61. package/esm/{workspace/executor.mjs → utils/exec.mjs} +18 -17
  62. package/esm/utils/git-utils.d.ts +25 -0
  63. package/esm/utils/git-utils.mjs +63 -0
  64. package/esm/utils/npm-run-path.d.ts +67 -0
  65. package/esm/utils/npm-run-path.mjs +55 -0
  66. package/esm/utils.d.ts +2 -0
  67. package/esm/utils.mjs +28 -0
  68. package/package.json +44 -24
  69. package/bin/debug.ts +0 -4
  70. package/cjs/workspace/package.js +0 -43
  71. package/cjs/workspace/providers/npm-provider.js +0 -16
  72. package/cjs/workspace/utils.js +0 -31
  73. package/cjs/workspace/workspace.js +0 -245
  74. package/esm/workspace/package.d.ts +0 -27
  75. package/esm/workspace/package.mjs +0 -36
  76. package/esm/workspace/providers/npm-provider.d.ts +0 -4
  77. package/esm/workspace/providers/npm-provider.mjs +0 -12
  78. package/esm/workspace/types.d.ts +0 -10
  79. package/esm/workspace/utils.d.ts +0 -6
  80. package/esm/workspace/utils.mjs +0 -22
  81. package/esm/workspace/workspace.d.ts +0 -17
  82. 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.executeCommand = void 0;
6
+ exports.exec = void 0;
7
7
  const child_process_1 = require("child_process");
8
- const npm_run_path_1 = __importDefault(require("npm-run-path"));
9
- const chalk_1 = __importDefault(require("chalk"));
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 executeCommand(command, options) {
11
+ async function exec(command, options) {
13
12
  const opts = {
14
- ...options
13
+ shell: true,
14
+ throwOnError: true,
15
+ ...options,
15
16
  };
16
17
  opts.env = {
17
- ...npm_run_path_1.default.env({ cwd: options?.cwd }),
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: options?.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
- result.error = err;
83
- if (!result.error) {
81
+ if (!err) {
84
82
  const text = `Command failed (${result.code})`;
85
- result.error =
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((opts.color ? chalk_1.default.red(text) : text));
104
+ result.error = new Error(text);
104
105
  }
105
106
  return resolve(result);
106
107
  });
107
108
  });
108
109
  }
109
- exports.executeCommand = executeCommand;
110
- (0, utils_1.onProcessExit)(() => {
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
@@ -1 +1,4 @@
1
- export declare function run(argv?: string[]): Promise<void>;
1
+ export declare function runCli(options?: {
2
+ argv?: string[];
3
+ cwd?: string;
4
+ }): Promise<void>;
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 { program } from "commander";
5
- import { Workspace } from './workspace/workspace.mjs';
6
- import { URL } from 'url';
7
- export async function run(argv = process.argv) {
8
- const pkgJson = JSON.parse(global.__dirname
9
- ? await fs.readFile(path.resolve(__dirname, '../package.json'), 'utf-8')
10
- // @ts-ignore
11
- : await fs.readFile(new URL('../package.json', import.meta.url), 'utf-8'));
12
- program.version(pkgJson.version || '');
13
- program
14
- .command('run <script>')
15
- .description('Executes given script for every package in repository')
16
- .action(async (script) => runScript(script))
17
- .allowUnknownOption();
18
- program
19
- .command('build')
20
- .description('Executes "build" script for every package in repository')
21
- .action(async () => runScript('build'))
22
- .allowUnknownOption();
23
- program
24
- .command('lint')
25
- .description('Executes "lint" script for every package in repository')
26
- .action(async () => runScript('lint'))
27
- .allowUnknownOption();
28
- program
29
- .command('test')
30
- .description('Executes "test" script for every package in repository')
31
- .action(async () => runScript('lint'))
32
- .allowUnknownOption();
33
- program.parse(argv);
34
- }
35
- async function runScript(script) {
36
- const workspace = Workspace.create();
37
- const result = await workspace.runScript(script, {
38
- gauge: true
39
- });
40
- if (!result.commands.length) {
41
- console.warn(chalk.cyanBright('There is nothing to do for "') +
42
- chalk.yellowBright(script) + chalk.cyanBright('" script.'));
43
- return;
44
- }
45
- if (result.errorCount) {
46
- console.error('\n' + chalk.yellow(result.errorCount) + chalk.white(' error(s)'));
47
- let s = '';
48
- for (let i = 0; i < result.commands.length; i++) {
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
+ }