rman 0.0.3 → 0.2.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.
Files changed (84) hide show
  1. package/README.md +22 -90
  2. package/bin/rman.js +2 -2
  3. package/cjs/cli.js +57 -0
  4. package/cjs/commands/changed-command.js +38 -0
  5. package/cjs/commands/execute-command.js +79 -0
  6. package/cjs/commands/info-command.js +66 -0
  7. package/cjs/commands/list-command.js +141 -0
  8. package/cjs/commands/multi-task-command.js +70 -0
  9. package/cjs/commands/publish-command.js +74 -0
  10. package/cjs/commands/run-command.js +103 -0
  11. package/cjs/commands/version-command.js +155 -0
  12. package/cjs/core/command.js +110 -0
  13. package/cjs/core/config.js +73 -0
  14. package/cjs/core/logger.js +8 -0
  15. package/cjs/core/package.js +33 -0
  16. package/cjs/core/repository.js +133 -0
  17. package/{dist/workspace → cjs/core}/types.js +0 -0
  18. package/cjs/debug.js +5 -0
  19. package/{dist → cjs}/index.js +1 -1
  20. package/cjs/package.json +3 -0
  21. package/cjs/utils/constants.js +5 -0
  22. package/cjs/utils/exec.js +115 -0
  23. package/cjs/utils/git-utils.js +70 -0
  24. package/cjs/utils/npm-run-path.js +63 -0
  25. package/cjs/utils.js +36 -0
  26. package/esm/cli.d.ts +4 -0
  27. package/esm/cli.mjs +50 -0
  28. package/esm/commands/changed-command.d.ts +16 -0
  29. package/esm/commands/changed-command.mjs +34 -0
  30. package/esm/commands/execute-command.d.ts +18 -0
  31. package/esm/commands/execute-command.mjs +72 -0
  32. package/esm/commands/info-command.d.ts +10 -0
  33. package/esm/commands/info-command.mjs +59 -0
  34. package/esm/commands/list-command.d.ts +38 -0
  35. package/esm/commands/list-command.mjs +134 -0
  36. package/esm/commands/multi-task-command.d.ts +20 -0
  37. package/esm/commands/multi-task-command.mjs +63 -0
  38. package/esm/commands/publish-command.d.ts +17 -0
  39. package/esm/commands/publish-command.mjs +67 -0
  40. package/esm/commands/run-command.d.ts +22 -0
  41. package/esm/commands/run-command.mjs +96 -0
  42. package/esm/commands/version-command.d.ts +24 -0
  43. package/esm/commands/version-command.mjs +148 -0
  44. package/esm/core/command.d.ts +35 -0
  45. package/esm/core/command.mjs +103 -0
  46. package/esm/core/config.d.ts +9 -0
  47. package/esm/core/config.mjs +66 -0
  48. package/esm/core/logger.d.ts +10 -0
  49. package/esm/core/logger.mjs +3 -0
  50. package/esm/core/package.d.ts +11 -0
  51. package/esm/core/package.mjs +26 -0
  52. package/esm/core/repository.d.ts +18 -0
  53. package/esm/core/repository.mjs +126 -0
  54. package/esm/core/types.d.ts +14 -0
  55. package/esm/core/types.mjs +1 -0
  56. package/esm/debug.d.ts +1 -0
  57. package/esm/debug.mjs +3 -0
  58. package/esm/index.d.ts +1 -0
  59. package/esm/index.mjs +1 -0
  60. package/esm/utils/constants.d.ts +2 -0
  61. package/esm/utils/constants.mjs +2 -0
  62. package/{dist/workspace/executor.d.ts → esm/utils/exec.d.ts} +5 -8
  63. package/esm/utils/exec.mjs +108 -0
  64. package/esm/utils/git-utils.d.ts +25 -0
  65. package/esm/utils/git-utils.mjs +63 -0
  66. package/esm/utils/npm-run-path.d.ts +67 -0
  67. package/esm/utils/npm-run-path.mjs +55 -0
  68. package/esm/utils.d.ts +2 -0
  69. package/esm/utils.mjs +28 -0
  70. package/package.json +64 -31
  71. package/bin/debug.ts +0 -4
  72. package/dist/cli.d.ts +0 -1
  73. package/dist/cli.js +0 -71
  74. package/dist/index.d.ts +0 -1
  75. package/dist/workspace/executor.js +0 -120
  76. package/dist/workspace/package.d.ts +0 -27
  77. package/dist/workspace/package.js +0 -43
  78. package/dist/workspace/providers/npm-provider.d.ts +0 -4
  79. package/dist/workspace/providers/npm-provider.js +0 -16
  80. package/dist/workspace/types.d.ts +0 -10
  81. package/dist/workspace/utils.d.ts +0 -6
  82. package/dist/workspace/utils.js +0 -31
  83. package/dist/workspace/workspace.d.ts +0 -17
  84. package/dist/workspace/workspace.js +0 -240
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## postgresql-client
1
+ ## rman
2
2
 
3
3
  [![NPM Version][npm-image]][npm-url]
4
4
  [![NPM Downloads][downloads-image]][downloads-url]
@@ -6,96 +6,28 @@
6
6
  [![Test Coverage][coveralls-image]][coveralls-url]
7
7
 
8
8
 
9
- Professional PostgreSQL client written in TypeScript.
10
-
11
- ## Features
12
-
13
- - Pure JavaScript library completely written in TypeScript
14
- - Supports both single connection and pooling
15
- - Named Prepared Statements
16
- - Extended cursor support with fast double-link cache
17
- - Extensible data-types and type mapping
18
- - Extended bind parameters
19
- - Multidimensional arrays with fast binary encoding/decoding
20
- - Low memory utilization and boosted performance with Shared Buffers
21
- - Full binary and text wire protocol support for all data types
22
- - Supports Clear text, MD5 and SASL password algorithms
23
- - Can return both array and object rows
24
- - Asynchronous Promise based api
25
- - Strictly typed
26
-
27
- ## Installation
28
-
29
- ```bash
30
- $ npm install postgresql-client --save
31
- ```
32
-
33
- ## Documentation
34
- Documentation for detailed usage is [here](DOCUMENTATION.md)
35
-
36
- ```ts
37
- import {Connection} from 'postgresql-client';
38
-
39
- const connection = new Connection('postgres://localhost');
40
- await connection.connect();
41
- const result = await connection.query(
42
- 'select * from cities where name like $1',
43
- {params: ['%york%']});
44
- const rows = result.rows;
45
- await connection.close(); // Disconnect
46
- ```
47
-
48
- ```ts
49
- import {Pool} from 'postgresql-client';
50
-
51
- const db = new Pool({
52
- host: 'postgres://localhost',
53
- pool: {
54
- min: 1,
55
- max: 10,
56
- idleTimeoutMillis: 5000
57
- }
58
- });
59
-
60
- const result = await db.query(
61
- 'select * from cities where name like $1',
62
- {params: ['%york%'], cursor: true});
63
- const cursor = result.cursor;
64
- let row;
65
- while ((row = cursor.next())) {
66
- console.log(row);
67
- }
68
-
69
- await db.close(); // Disconnect all connections and shutdown pool
70
- ```
71
-
72
-
73
- ## Support
74
- You can report bugs and discuss features on the [GitHub issues](https://github.com/panates/postgresql-client/issues) page
75
- When you open an issue please provide version of NodeJS and PostgreSQL server.
76
-
9
+ Monorepo repository manager
77
10
 
78
11
  ## Node Compatibility
79
12
 
80
- - node >= 10.x
81
-
82
-
83
- ### License
84
- postgresql-client is available under [MIT](LICENSE) license.
13
+ - node >= 14.x
85
14
 
86
- [npm-image]: https://img.shields.io/npm/v/postgresql-client.svg
87
- [npm-url]: https://npmjs.org/package/postgresql-client
88
- [travis-image]: https://img.shields.io/travis/panates/postgresql-client/master.svg
89
- [travis-url]: https://travis-ci.com/panates/postgresql-client
90
- [coveralls-image]: https://img.shields.io/coveralls/panates/postgresql-client/master.svg
91
- [coveralls-url]: https://coveralls.io/r/panates/postgresql-client
92
- [downloads-image]: https://img.shields.io/npm/dm/postgresql-client.svg
93
- [downloads-url]: https://npmjs.org/package/postgresql-client
94
- [gitter-image]: https://badges.gitter.im/panates/postgresql-client.svg
95
- [gitter-url]: https://gitter.im/panates/postgresql-client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
96
- [dependencies-image]: https://david-dm.org/panates/postgresql-client/status.svg
97
- [dependencies-url]:https://david-dm.org/panates/postgresql-client
98
- [devdependencies-image]: https://david-dm.org/panates/postgresql-client/dev-status.svg
99
- [devdependencies-url]:https://david-dm.org/panates/postgresql-client?type=dev
100
- [quality-image]: http://npm.packagequality.com/shield/postgresql-client.png
101
- [quality-url]: http://packagequality.com/#?package=postgresql-client
15
+ ### License
16
+ rman is available under [MIT](LICENSE) license.
17
+
18
+ [npm-image]: https://img.shields.io/npm/v/rman.svg
19
+ [npm-url]: https://npmjs.org/package/rman
20
+ [travis-image]: https://img.shields.io/travis/panates/rman/master.svg
21
+ [travis-url]: https://travis-ci.com/panates/rman
22
+ [coveralls-image]: https://img.shields.io/coveralls/panates/rman/master.svg
23
+ [coveralls-url]: https://coveralls.io/r/panates/rman
24
+ [downloads-image]: https://img.shields.io/npm/dm/rman.svg
25
+ [downloads-url]: https://npmjs.org/package/rman
26
+ [gitter-image]: https://badges.gitter.im/panates/rman.svg
27
+ [gitter-url]: https://gitter.im/panates/rman?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
28
+ [dependencies-image]: https://david-dm.org/panates/rman/status.svg
29
+ [dependencies-url]:https://david-dm.org/panates/rman
30
+ [devdependencies-image]: https://david-dm.org/panates/rman/dev-status.svg
31
+ [devdependencies-url]:https://david-dm.org/panates/rman?type=dev
32
+ [quality-image]: http://npm.packagequality.com/shield/rman.png
33
+ [quality-url]: http://packagequality.com/#?package=rman
package/bin/rman.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import {run} from '../dist/cli.js';
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 ADDED
@@ -0,0 +1,57 @@
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.runCli = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const promises_1 = __importDefault(require("fs/promises"));
9
+ const yargs_1 = __importDefault(require("yargs"));
10
+ const chalk_1 = __importDefault(require("chalk"));
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);
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 = {}));