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
package/bin/rman.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import {run} from '../esm/cli.mjs';
2
+ import {runCli} from '../esm/cli.mjs';
3
3
 
4
4
  // eslint-disable-next-line
5
- run().catch(e => console.error(e));
5
+ runCli().catch();
package/cjs/cli.js CHANGED
@@ -3,65 +3,55 @@ 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.run = void 0;
6
+ exports.runCli = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const promises_1 = __importDefault(require("fs/promises"));
9
+ const yargs_1 = __importDefault(require("yargs"));
9
10
  const chalk_1 = __importDefault(require("chalk"));
10
- const commander_1 = require("commander");
11
- const workspace_1 = require("./workspace/workspace");
12
- const url_1 = require("url");
13
- async function run(argv = process.argv) {
14
- const pkgJson = JSON.parse(global.__dirname
15
- ? await promises_1.default.readFile(path_1.default.resolve(__dirname, '../package.json'), 'utf-8')
16
- // @ts-ignore
17
- : await promises_1.default.readFile(new url_1.URL('../package.json', import.meta.url), 'utf-8'));
18
- commander_1.program.version(pkgJson.version || '');
19
- commander_1.program
20
- .command('run <script>')
21
- .description('Executes given script for every package in repository')
22
- .action(async (script) => runScript(script))
23
- .allowUnknownOption();
24
- commander_1.program
25
- .command('build')
26
- .description('Executes "build" script for every package in repository')
27
- .action(async () => runScript('build'))
28
- .allowUnknownOption();
29
- commander_1.program
30
- .command('lint')
31
- .description('Executes "lint" script for every package in repository')
32
- .action(async () => runScript('lint'))
33
- .allowUnknownOption();
34
- commander_1.program
35
- .command('test')
36
- .description('Executes "test" script for every package in repository')
37
- .action(async () => runScript('lint'))
38
- .allowUnknownOption();
39
- commander_1.program.parse(argv);
40
- }
41
- exports.run = run;
42
- async function runScript(script) {
43
- const workspace = workspace_1.Workspace.create();
44
- const result = await workspace.runScript(script, {
45
- gauge: true
46
- });
47
- if (!result.commands.length) {
48
- console.warn(chalk_1.default.cyanBright('There is nothing to do for "') +
49
- chalk_1.default.yellowBright(script) + chalk_1.default.cyanBright('" script.'));
50
- return;
51
- }
52
- if (result.errorCount) {
53
- console.error('\n' + chalk_1.default.yellow(result.errorCount) + chalk_1.default.white(' error(s)'));
54
- let s = '';
55
- for (let i = 0; i < result.commands.length; i++) {
56
- const cmd = result.commands[i];
57
- if (cmd.error) {
58
- s += '\n' + (i + 1) + ') ' +
59
- chalk_1.default.cyanBright(cmd.package) + '\n' +
60
- chalk_1.default.white(cmd.command) + '\n' +
61
- chalk_1.default.red('Error: ' + cmd.error.message) + '\n' +
62
- chalk_1.default.red(cmd.stderr) + '\n';
63
- }
64
- }
65
- console.error(s);
66
- }
11
+ const utils_1 = require("./utils");
12
+ const repository_1 = require("./core/repository");
13
+ const info_command_1 = require("./commands/info-command");
14
+ const command_1 = require("./core/command");
15
+ const list_command_1 = require("./commands/list-command");
16
+ const changed_command_1 = require("./commands/changed-command");
17
+ const execute_command_1 = require("./commands/execute-command");
18
+ const run_command_1 = require("./commands/run-command");
19
+ const version_command_1 = require("./commands/version-command");
20
+ const publish_command_1 = require("./commands/publish-command");
21
+ async function runCli(options) {
22
+ const s = path_1.default.resolve((0, utils_1.getDirname)(), '../package.json');
23
+ const pkgJson = JSON.parse(await promises_1.default.readFile(s, 'utf-8'));
24
+ const repository = repository_1.Repository.create(options?.cwd);
25
+ const _argv = options?.argv || process.argv.slice(2);
26
+ const globalKeys = Object.keys(command_1.Command.globalOptions).concat(["help", "version"]);
27
+ const program = (0, yargs_1.default)(_argv)
28
+ // .scriptName('rman')
29
+ .strict()
30
+ .version(pkgJson.version || '').alias('version', 'v')
31
+ .usage('$0 <cmd> [options...]')
32
+ .help('help').alias('help', 'h')
33
+ .showHelpOnFail(false, 'Run with --help for available options')
34
+ .fail((msg, err) => {
35
+ const text = (msg
36
+ ? msg + '\n\n' + chalk_1.default.whiteBright('Run with --help for available options')
37
+ : (err ? err.message : ''));
38
+ console.log('\n' + chalk_1.default.red(text));
39
+ throw msg;
40
+ })
41
+ // group options under "Global Options:" header
42
+ .options(command_1.Command.globalOptions)
43
+ .group(globalKeys, "Global Options:");
44
+ info_command_1.InfoCommand.initCli(repository, program);
45
+ list_command_1.ListCommand.initCli(repository, program);
46
+ changed_command_1.ChangedCommand.initCli(repository, program);
47
+ execute_command_1.ExecuteCommand.initCli(repository, program);
48
+ run_command_1.RunCommand.initCli(repository, program);
49
+ version_command_1.VersionCommand.initCli(repository, program);
50
+ publish_command_1.PublishCommand.initCli(repository, program);
51
+ if (!_argv.length)
52
+ program.showHelp();
53
+ else
54
+ await program.parseAsync()
55
+ .catch(() => false);
67
56
  }
57
+ exports.runCli = runCli;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChangedCommand = void 0;
4
+ const list_command_1 = require("./list-command");
5
+ const command_1 = require("../core/command");
6
+ class ChangedCommand extends list_command_1.ListCommand {
7
+ constructor(repository, options) {
8
+ super(repository, options);
9
+ this.repository = repository;
10
+ }
11
+ _filter(pkg, inf) {
12
+ if (!super._filter(pkg, inf))
13
+ return false;
14
+ return !!(inf.isDirty || inf.isCommitted);
15
+ }
16
+ }
17
+ exports.ChangedCommand = ChangedCommand;
18
+ ChangedCommand.commandName = 'changed';
19
+ (function (ChangedCommand) {
20
+ function initCli(repository, program) {
21
+ program.command({
22
+ command: 'changed [options...]',
23
+ describe: 'List local packages that have changed since the last tagged release',
24
+ builder: (cmd) => {
25
+ return cmd
26
+ .example("$0 changed", "# List changed packages")
27
+ .example('$0 changed --json', '# List changed packages in JSON format')
28
+ .option(list_command_1.ListCommand.cliCommandOptions);
29
+ },
30
+ handler: async (args) => {
31
+ const options = command_1.Command.composeOptions(ChangedCommand.commandName, args, repository.config);
32
+ await new ChangedCommand(repository, options)
33
+ .execute();
34
+ }
35
+ });
36
+ }
37
+ ChangedCommand.initCli = initCli;
38
+ })(ChangedCommand = exports.ChangedCommand || (exports.ChangedCommand = {}));
@@ -0,0 +1,79 @@
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.ExecuteCommand = void 0;
7
+ const npmlog_1 = __importDefault(require("npmlog"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const figures_1 = __importDefault(require("figures"));
10
+ const multi_task_command_1 = require("./multi-task-command");
11
+ const power_tasks_1 = require("power-tasks");
12
+ const exec_1 = require("../utils/exec");
13
+ const command_1 = require("../core/command");
14
+ class ExecuteCommand extends multi_task_command_1.MultiTaskCommand {
15
+ constructor(repository, cmd, argv, options) {
16
+ super(repository, options);
17
+ this.repository = repository;
18
+ this.cmd = cmd;
19
+ this.argv = argv;
20
+ }
21
+ _prepareTasks() {
22
+ const packages = this.repository.getPackages({ toposort: !this.options.parallel });
23
+ const tasks = [];
24
+ for (const p of packages) {
25
+ const task = new power_tasks_1.Task(async () => {
26
+ const t = Date.now();
27
+ npmlog_1.default.verbose(this.commandName, p.name, chalk_1.default.gray(figures_1.default.lineVerticalDashed0), chalk_1.default.cyanBright.bold('executing'), chalk_1.default.gray(figures_1.default.lineVerticalDashed0), this.cmd + ' ' + (this.argv?.join(' ') || ''));
28
+ const r = await (0, exec_1.exec)(this.cmd, {
29
+ cwd: p.dirname,
30
+ argv: this.argv
31
+ });
32
+ npmlog_1.default.log((r.error ? 'error' : 'verbose'), this.commandName, chalk_1.default.gray(figures_1.default.lineVerticalDashed0), p.name, chalk_1.default.gray(figures_1.default.lineVerticalDashed0), (r.error ? chalk_1.default.red.bold('failed') : chalk_1.default.green.bold('success')), chalk_1.default.gray(figures_1.default.lineVerticalDashed0), 'Completed in ' + chalk_1.default.yellow('' + (Date.now() - t) + ' ms'));
33
+ }, {
34
+ name: p.name,
35
+ dependencies: this.options.parallel ? undefined : p.dependencies,
36
+ bail: this.options.bail,
37
+ concurrency: this.options.concurrency
38
+ });
39
+ tasks.push(task);
40
+ }
41
+ return tasks;
42
+ }
43
+ }
44
+ exports.ExecuteCommand = ExecuteCommand;
45
+ ExecuteCommand.commandName = 'exec';
46
+ (function (ExecuteCommand) {
47
+ ExecuteCommand.cliCommandOptions = {
48
+ ...multi_task_command_1.MultiTaskCommand.cliCommandOptions
49
+ };
50
+ function initCli(repository, program) {
51
+ program.command({
52
+ command: 'exec [cmd] [args..]',
53
+ describe: 'Execute an arbitrary command in each package',
54
+ builder: (cmd) => {
55
+ return cmd
56
+ .example("$0 exec -- ls", '')
57
+ .example('$0 exec -- rm -rf ./node_modules', '')
58
+ .parserConfiguration({
59
+ "populate--": true,
60
+ })
61
+ .positional("cmd", {
62
+ describe: "The command to execute. Any command flags must be passed after --",
63
+ type: "string",
64
+ })
65
+ .positional("args", {
66
+ describe: "Positional arguments to send to command",
67
+ type: "string",
68
+ })
69
+ .option(ExecuteCommand.cliCommandOptions);
70
+ },
71
+ handler: async (args) => {
72
+ const argv = args['--'] || [];
73
+ const options = command_1.Command.composeOptions(ExecuteCommand.commandName, args, repository.config);
74
+ await new ExecuteCommand(repository, '' + argv.shift(), argv, options).execute();
75
+ }
76
+ });
77
+ }
78
+ ExecuteCommand.initCli = initCli;
79
+ })(ExecuteCommand = exports.ExecuteCommand || (exports.ExecuteCommand = {}));
@@ -0,0 +1,66 @@
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.InfoCommand = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const envinfo_1 = __importDefault(require("envinfo"));
9
+ const semver_1 = __importDefault(require("semver"));
10
+ const command_1 = require("../core/command");
11
+ class InfoCommand extends command_1.Command {
12
+ async _execute() {
13
+ const systemInfo = JSON.parse(await envinfo_1.default.run({
14
+ System: ['OS', 'CPU', 'Memory', 'Shell'],
15
+ Binaries: ['Node', 'Yarn', 'npm'],
16
+ Utilities: ['Git'],
17
+ npmPackages: ['rman', 'typescript'],
18
+ npmGlobalPackages: ['typescript']
19
+ }, { json: true }));
20
+ if (this.options.json) {
21
+ this.logger.output('', '%j', systemInfo);
22
+ return;
23
+ }
24
+ const maxName = Object.keys(systemInfo).reduce((l, p) => Object.keys(systemInfo[p]).reduce((i, x) => l = Math.max(i, x.length), l), 0);
25
+ for (const [categoryName, category] of Object.entries(systemInfo)) {
26
+ this.logger.output('', '', chalk_1.default.whiteBright(categoryName) + ':');
27
+ for (const [n, v] of Object.entries(category)) {
28
+ const label = ' ' + chalk_1.default.reset(n) +
29
+ ' '.repeat(maxName - n.length) + ' :';
30
+ if (typeof v === 'string') {
31
+ this.logger.output('', label, chalk_1.default.yellowBright(v));
32
+ continue;
33
+ }
34
+ if (v.version)
35
+ this.logger.output('', label, chalk_1.default.yellowBright(v.version), (v.path ? ' ' + chalk_1.default.yellow(v.path) : ''));
36
+ if (v.installed) {
37
+ if (v.wanted === 'latest' || semver_1.default.intersects(v.installed, v.wanted))
38
+ this.logger.output('', label, chalk_1.default.yellowBright(v.installed));
39
+ else
40
+ this.logger.output('', label, chalk_1.default.red(v.installed), ' => ', chalk_1.default.yellowBright(v.wanted));
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ exports.InfoCommand = InfoCommand;
47
+ InfoCommand.commandName = 'info';
48
+ (function (InfoCommand) {
49
+ function initCli(repository, program) {
50
+ program.command({
51
+ command: 'info [options...]',
52
+ describe: 'Prints local environment information',
53
+ builder: (cmd) => {
54
+ return cmd
55
+ .example("$0 info", "# Prints information")
56
+ .example('$0 info --json', '# Prints information in JSON format');
57
+ },
58
+ handler: async (args) => {
59
+ const options = command_1.Command.composeOptions(InfoCommand.commandName, args, repository.config);
60
+ await new InfoCommand(options)
61
+ .execute();
62
+ }
63
+ });
64
+ }
65
+ InfoCommand.initCli = initCli;
66
+ })(InfoCommand = exports.InfoCommand || (exports.InfoCommand = {}));
@@ -0,0 +1,141 @@
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.ListCommand = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const easy_table_1 = __importDefault(require("easy-table"));
10
+ const npmlog_1 = __importDefault(require("npmlog"));
11
+ const command_1 = require("../core/command");
12
+ const git_utils_1 = require("../utils/git-utils");
13
+ class ListCommand extends command_1.Command {
14
+ constructor(repository, options) {
15
+ super(options);
16
+ this.repository = repository;
17
+ }
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
+ _filter(pkg, inf) {
20
+ return true;
21
+ }
22
+ async _execute() {
23
+ const { repository } = this;
24
+ const packages = repository.getPackages({ toposort: this.options.toposort });
25
+ const git = new git_utils_1.GitHelper({ cwd: repository.dirname });
26
+ const dirtyFiles = await git.listDirtyFiles({ absolute: true });
27
+ const committedFiles = await git.listCommittedFiles({ absolute: true });
28
+ const table = new easy_table_1.default();
29
+ const arr = [];
30
+ const obj = {};
31
+ let count = 0;
32
+ for (const p of packages) {
33
+ const isDirty = !!dirtyFiles.find(f => !path_1.default.relative(p.dirname, f).startsWith('..'));
34
+ const isCommitted = !!committedFiles.find(f => !path_1.default.relative(p.dirname, f).startsWith('..'));
35
+ if (!this._filter(p, { isDirty, isCommitted }))
36
+ continue;
37
+ if (this.options.graph) {
38
+ count++;
39
+ obj[p.name] = [...p.dependencies];
40
+ continue;
41
+ }
42
+ const location = path_1.default.relative(repository.dirname, p.dirname);
43
+ let o = {
44
+ name: p.name,
45
+ version: p.version,
46
+ location,
47
+ private: p.isPrivate,
48
+ isDirty,
49
+ isCommitted
50
+ };
51
+ o = this.onPrepare ? this.onPrepare(p, o) : o;
52
+ if (!o)
53
+ continue;
54
+ arr.push(o);
55
+ count++;
56
+ if (!this.options.json) {
57
+ if (this.options.parseable) {
58
+ const a = [location, p.name, p.version,
59
+ (p.isPrivate ? 'PRIVATE' : ''),
60
+ (isDirty ? 'DIRTY' : (isCommitted ? ':COMMITTED' : ''))
61
+ ];
62
+ npmlog_1.default.output('', a.join('::'));
63
+ }
64
+ else if (this.options.short) {
65
+ npmlog_1.default.output('', p.name);
66
+ }
67
+ else {
68
+ if (this.onPrintTable)
69
+ this.onPrintTable(p, o, table);
70
+ else {
71
+ table.cell('Package', chalk_1.default.yellowBright(p.name));
72
+ table.cell('Version', chalk_1.default.yellow(p.version));
73
+ table.cell('Private', p.isPrivate ? chalk_1.default.magentaBright('yes') : '');
74
+ table.cell('Changed', isDirty ? chalk_1.default.magenta('dirty') :
75
+ (isCommitted ? chalk_1.default.yellow('committed') : ''));
76
+ table.cell('Path', path_1.default.relative(repository.dirname, p.dirname));
77
+ table.newRow();
78
+ }
79
+ }
80
+ }
81
+ }
82
+ if (this.options.graph) {
83
+ npmlog_1.default.output('', '%j', obj);
84
+ return obj;
85
+ }
86
+ else if (this.options.json) {
87
+ npmlog_1.default.output('', '%j', arr);
88
+ return arr;
89
+ }
90
+ else if (table.rows.length) {
91
+ npmlog_1.default.output('', '%s', table.toString().trim());
92
+ console.log('');
93
+ npmlog_1.default.info('list', '%i Package(s) found', count);
94
+ return arr;
95
+ }
96
+ return arr;
97
+ }
98
+ }
99
+ exports.ListCommand = ListCommand;
100
+ ListCommand.commandName = 'list';
101
+ (function (ListCommand) {
102
+ ListCommand.cliCommandOptions = {
103
+ 'short': {
104
+ alias: 's',
105
+ describe: '# Do not show extended information'
106
+ },
107
+ 'parseable': {
108
+ alias: 'p',
109
+ describe: '# Show parseable output'
110
+ },
111
+ 'toposort': {
112
+ alias: 't',
113
+ describe: '# Sort packages in topological order (dependencies before dependents) instead of lexical by directory'
114
+ },
115
+ 'graph': {
116
+ alias: 'g',
117
+ describe: '# Show dependency graph as a JSON-formatted adjacency list'
118
+ }
119
+ };
120
+ function initCli(repository, program) {
121
+ program.command({
122
+ command: 'list [options...]',
123
+ describe: 'Lists packages in repository',
124
+ aliases: ['ls'],
125
+ builder: (cmd) => {
126
+ return cmd
127
+ .example("$0 list", "# List all packages")
128
+ .example('$0 list --json', '# List all packages in JSON format')
129
+ .conflicts('graph', ['parseable', 'json'])
130
+ .conflicts('short', ['parseable', 'json'])
131
+ .option(ListCommand.cliCommandOptions);
132
+ },
133
+ handler: async (args) => {
134
+ const options = command_1.Command.composeOptions(ListCommand.commandName, args, repository.config);
135
+ await new ListCommand(repository, options)
136
+ .execute();
137
+ }
138
+ });
139
+ }
140
+ ListCommand.initCli = initCli;
141
+ })(ListCommand = exports.ListCommand || (exports.ListCommand = {}));
@@ -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.MultiTaskCommand = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const npmlog_1 = __importDefault(require("npmlog"));
10
+ const figures_1 = __importDefault(require("figures"));
11
+ const power_tasks_1 = require("power-tasks");
12
+ const command_1 = require("../core/command");
13
+ const constants_1 = require("../utils/constants");
14
+ const logSeparator = chalk_1.default.gray(figures_1.default.lineVerticalDashed0);
15
+ class MultiTaskCommand extends command_1.Command {
16
+ constructor(repository, options) {
17
+ super(options);
18
+ this.repository = repository;
19
+ if (this.options.ci || !constants_1.isTTY)
20
+ this.options.progress = false;
21
+ // noinspection SuspiciousTypeOfGuard
22
+ this.options.concurrency = typeof options?.concurrency === 'string' ?
23
+ parseInt(options.concurrency, 10) : undefined;
24
+ if (this.options.bail == null)
25
+ this.options.bail = true;
26
+ }
27
+ async _execute() {
28
+ const childTasks = await this._prepareTasks();
29
+ if (!(childTasks && childTasks.length)) {
30
+ npmlog_1.default.info(this.commandName, logSeparator, 'There is no task to process');
31
+ return;
32
+ }
33
+ // this.enableProgress();
34
+ this._task = new power_tasks_1.Task(childTasks, {
35
+ concurrency: this.options.concurrency || os_1.default.cpus().length,
36
+ bail: this.options.bail,
37
+ });
38
+ await this._task;
39
+ }
40
+ }
41
+ exports.MultiTaskCommand = MultiTaskCommand;
42
+ (function (MultiTaskCommand) {
43
+ MultiTaskCommand.cliCommandOptions = {
44
+ 'concurrency': {
45
+ describe: '# Set processes count to parallelize tasks. (CPU count if not defined)',
46
+ type: 'number'
47
+ },
48
+ 'parallel': {
49
+ describe: '# Disregards dependency checking and runs the command for every package at same time.',
50
+ type: 'boolean'
51
+ },
52
+ 'no-bail': {
53
+ describe: '# Continue execution even one fails.',
54
+ type: 'boolean'
55
+ },
56
+ 'bail': {
57
+ hidden: true,
58
+ type: 'boolean'
59
+ },
60
+ 'no-progress': {
61
+ describe: "Disable progress bars",
62
+ type: 'boolean',
63
+ },
64
+ 'progress': {
65
+ hidden: true,
66
+ type: 'boolean',
67
+ default: true
68
+ }
69
+ };
70
+ })(MultiTaskCommand = exports.MultiTaskCommand || (exports.MultiTaskCommand = {}));
@@ -0,0 +1,74 @@
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.PublishCommand = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const package_json_1 = __importDefault(require("package-json"));
9
+ const npmlog_1 = __importDefault(require("npmlog"));
10
+ const figures_1 = __importDefault(require("figures"));
11
+ const command_1 = require("../core/command");
12
+ const run_command_1 = require("./run-command");
13
+ class PublishCommand extends run_command_1.RunCommand {
14
+ constructor(repository, options) {
15
+ super(repository, 'publish', options);
16
+ this.repository = repository;
17
+ }
18
+ async _prepareTasks() {
19
+ const { repository } = this;
20
+ const packages = repository.getPackages({ toposort: true });
21
+ const newVersions = {};
22
+ const selectedPackages = [];
23
+ for (const p of packages) {
24
+ const logPkgName = chalk_1.default.yellow(p.name);
25
+ const r = await (0, package_json_1.default)(p.json.name);
26
+ if (r.version === p.version) {
27
+ npmlog_1.default.info(this.commandName, logPkgName, chalk_1.default.gray(figures_1.default.lineVerticalDashed0), `Ignored. Same version (${p.version}) in repository`);
28
+ continue;
29
+ }
30
+ selectedPackages.push(p);
31
+ }
32
+ const tasks = [];
33
+ for (const p of selectedPackages) {
34
+ const json = { ...p.json };
35
+ json.scripts = json.scripts || {};
36
+ json.scripts.publish = json.scripts.publish || 'npm publish';
37
+ const _p = { json };
38
+ Object.setPrototypeOf(_p, p);
39
+ const childTask = this._preparePackageTask(_p, { newVersions });
40
+ if (childTask) {
41
+ tasks.push(childTask);
42
+ }
43
+ }
44
+ return tasks;
45
+ }
46
+ }
47
+ exports.PublishCommand = PublishCommand;
48
+ PublishCommand.commandName = 'publish';
49
+ (function (PublishCommand) {
50
+ PublishCommand.cliCommandOptions = {
51
+ ...run_command_1.RunCommand.cliCommandOptions,
52
+ 'contents': {
53
+ describe: '# Subdirectory to publish',
54
+ type: 'string'
55
+ }
56
+ };
57
+ function initCli(repository, program) {
58
+ program.command({
59
+ command: 'publish [...options]',
60
+ describe: 'Publish packages in the current project',
61
+ builder: (cmd) => {
62
+ return cmd
63
+ .example("$0 publish", '')
64
+ .example("$0 publish --contents dist", '# publish package from built directory')
65
+ .option(PublishCommand.cliCommandOptions);
66
+ },
67
+ handler: async (args) => {
68
+ const options = command_1.Command.composeOptions(PublishCommand.commandName, args, repository.config);
69
+ await new PublishCommand(repository, options).execute();
70
+ }
71
+ });
72
+ }
73
+ PublishCommand.initCli = initCli;
74
+ })(PublishCommand = exports.PublishCommand || (exports.PublishCommand = {}));