rman 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -90
- package/bin/debug.ts +1 -1
- package/bin/rman.js +1 -1
- package/cjs/cli.js +67 -0
- package/{dist → cjs}/index.js +0 -0
- package/cjs/package.json +3 -0
- package/cjs/workspace/executor.js +114 -0
- package/{dist → cjs}/workspace/package.js +1 -1
- package/{dist → cjs}/workspace/providers/npm-provider.js +2 -2
- package/{dist → cjs}/workspace/types.js +0 -0
- package/{dist → cjs}/workspace/utils.js +0 -0
- package/cjs/workspace/workspace.js +245 -0
- package/{dist → esm}/cli.d.ts +0 -0
- package/esm/cli.mjs +60 -0
- package/{dist → esm}/index.d.ts +0 -0
- package/esm/index.mjs +1 -0
- package/{dist → esm}/workspace/executor.d.ts +0 -0
- package/esm/workspace/executor.mjs +107 -0
- package/{dist → esm}/workspace/package.d.ts +0 -0
- package/esm/workspace/package.mjs +36 -0
- package/{dist → esm}/workspace/providers/npm-provider.d.ts +0 -0
- package/esm/workspace/providers/npm-provider.mjs +12 -0
- package/{dist → esm}/workspace/types.d.ts +0 -0
- package/esm/workspace/types.mjs +1 -0
- package/{dist → esm}/workspace/utils.d.ts +0 -0
- package/esm/workspace/utils.mjs +22 -0
- package/{dist → esm}/workspace/workspace.d.ts +3 -3
- package/esm/workspace/workspace.mjs +238 -0
- package/package.json +27 -14
- package/dist/cli.js +0 -71
- package/dist/workspace/executor.js +0 -120
- package/dist/workspace/workspace.js +0 -240
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
##
|
|
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
|
-
|
|
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 >=
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### License
|
|
84
|
-
postgresql-client is available under [MIT](LICENSE) license.
|
|
13
|
+
- node >= 14.x
|
|
85
14
|
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
[
|
|
98
|
-
[
|
|
99
|
-
[
|
|
100
|
-
[
|
|
101
|
-
[
|
|
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/debug.ts
CHANGED
package/bin/rman.js
CHANGED
package/cjs/cli.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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.run = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
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
|
+
}
|
|
67
|
+
}
|
package/{dist → cjs}/index.js
RENAMED
|
File without changes
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
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 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");
|
|
11
|
+
const runningChildren = new Map();
|
|
12
|
+
async function executeCommand(command, options) {
|
|
13
|
+
const opts = {
|
|
14
|
+
...options
|
|
15
|
+
};
|
|
16
|
+
opts.env = {
|
|
17
|
+
...npm_run_path_1.default.env({ cwd: options?.cwd }),
|
|
18
|
+
// FORCE_COLOR: `${chalk.level}`,
|
|
19
|
+
...opts.env
|
|
20
|
+
};
|
|
21
|
+
opts.cwd = opts.cwd || process.cwd();
|
|
22
|
+
opts.color = opts.color == null ? true : opts.color;
|
|
23
|
+
const spawnOptions = {
|
|
24
|
+
stdio: opts.stdio || 'pipe',
|
|
25
|
+
env: opts.env,
|
|
26
|
+
cwd: opts.cwd,
|
|
27
|
+
shell: options?.shell,
|
|
28
|
+
windowsHide: true
|
|
29
|
+
};
|
|
30
|
+
const result = {
|
|
31
|
+
code: undefined,
|
|
32
|
+
stderr: '',
|
|
33
|
+
stdout: ''
|
|
34
|
+
};
|
|
35
|
+
const buffer = {
|
|
36
|
+
stdout: '',
|
|
37
|
+
stderr: ''
|
|
38
|
+
};
|
|
39
|
+
const processData = (data, stdio) => {
|
|
40
|
+
buffer[stdio] += data;
|
|
41
|
+
result[stdio] += data;
|
|
42
|
+
if (opts.onData)
|
|
43
|
+
opts.onData(data, stdio);
|
|
44
|
+
};
|
|
45
|
+
const processLines = (stdio, flush) => {
|
|
46
|
+
let chunk = buffer[stdio];
|
|
47
|
+
let i;
|
|
48
|
+
if (flush && !chunk.endsWith('\n'))
|
|
49
|
+
chunk += '\n';
|
|
50
|
+
while ((i = chunk.indexOf('\n')) >= 0) {
|
|
51
|
+
const line = chunk.substring(0, i);
|
|
52
|
+
chunk = chunk.substring(i + 1);
|
|
53
|
+
if (opts.onLine)
|
|
54
|
+
opts.onLine(line, stdio);
|
|
55
|
+
}
|
|
56
|
+
buffer[stdio] = chunk;
|
|
57
|
+
};
|
|
58
|
+
const child = (0, child_process_1.spawn)(command, opts.argv || [], spawnOptions);
|
|
59
|
+
if (child.pid) {
|
|
60
|
+
runningChildren.set(child.pid, child);
|
|
61
|
+
if (opts.onSpawn)
|
|
62
|
+
opts.onSpawn(child);
|
|
63
|
+
}
|
|
64
|
+
child.stdout?.on('data', (data) => {
|
|
65
|
+
processData(data, 'stdout');
|
|
66
|
+
processLines('stdout');
|
|
67
|
+
});
|
|
68
|
+
child.stderr?.on('data', (data) => {
|
|
69
|
+
processData(data, 'stderr');
|
|
70
|
+
processLines('stderr');
|
|
71
|
+
});
|
|
72
|
+
return new Promise(resolve => {
|
|
73
|
+
let resolved;
|
|
74
|
+
child.on('error', (err) => {
|
|
75
|
+
if (child.pid)
|
|
76
|
+
runningChildren.delete(child.pid);
|
|
77
|
+
processLines('stdout', true);
|
|
78
|
+
processLines('stderr', true);
|
|
79
|
+
if (resolved)
|
|
80
|
+
return;
|
|
81
|
+
result.code = err.code || 1;
|
|
82
|
+
result.error = err;
|
|
83
|
+
if (!result.error) {
|
|
84
|
+
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);
|
|
88
|
+
}
|
|
89
|
+
resolved = true;
|
|
90
|
+
resolve(result);
|
|
91
|
+
});
|
|
92
|
+
child.on('close', (code) => {
|
|
93
|
+
if (child.pid)
|
|
94
|
+
runningChildren.delete(child.pid);
|
|
95
|
+
processLines('stdout', true);
|
|
96
|
+
processLines('stderr', true);
|
|
97
|
+
if (resolved)
|
|
98
|
+
return;
|
|
99
|
+
result.code = code;
|
|
100
|
+
resolved = true;
|
|
101
|
+
if (code) {
|
|
102
|
+
const text = `Command failed (${result.code})`;
|
|
103
|
+
result.error = new Error((opts.color ? chalk_1.default.red(text) : text));
|
|
104
|
+
}
|
|
105
|
+
return resolve(result);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.executeCommand = executeCommand;
|
|
110
|
+
(0, utils_1.onProcessExit)(() => {
|
|
111
|
+
runningChildren.forEach((child) => {
|
|
112
|
+
child.kill();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NpmProvider = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
class NpmProvider {
|
|
6
6
|
parse(root) {
|
|
7
|
-
const pkg = (0,
|
|
7
|
+
const pkg = (0, utils_1.getPackageJson)(root);
|
|
8
8
|
if (pkg && typeof pkg.workspaces === 'object') {
|
|
9
9
|
if (Array.isArray(pkg.workspaces))
|
|
10
10
|
return { root, packages: pkg.workspaces };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,245 @@
|
|
|
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.Workspace = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const cli_progress_1 = require("cli-progress");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const executor_1 = require("./executor");
|
|
14
|
+
const package_1 = require("./package");
|
|
15
|
+
const npm_provider_1 = require("./providers/npm-provider");
|
|
16
|
+
const providers = [
|
|
17
|
+
new npm_provider_1.NpmProvider()
|
|
18
|
+
];
|
|
19
|
+
class Workspace {
|
|
20
|
+
constructor(root, packages, options) {
|
|
21
|
+
this.root = root;
|
|
22
|
+
this._options = { ...options };
|
|
23
|
+
this._packages = packages;
|
|
24
|
+
this._determineDependencies();
|
|
25
|
+
this._sortPackages();
|
|
26
|
+
}
|
|
27
|
+
get packages() {
|
|
28
|
+
return this._packages;
|
|
29
|
+
}
|
|
30
|
+
getPackage(name) {
|
|
31
|
+
return this.packages.find(p => p.name === name);
|
|
32
|
+
}
|
|
33
|
+
async runScript(script, options = {}) {
|
|
34
|
+
const packages = {};
|
|
35
|
+
const result = {
|
|
36
|
+
script,
|
|
37
|
+
errorCount: 0,
|
|
38
|
+
commands: []
|
|
39
|
+
};
|
|
40
|
+
options.gauge = options.gauge == null ? true : options.gauge;
|
|
41
|
+
let totalCommands = 0;
|
|
42
|
+
for (const p of this.packages) {
|
|
43
|
+
const commands = p.getScriptCommands(script);
|
|
44
|
+
totalCommands += commands.length;
|
|
45
|
+
packages[p.name] = {
|
|
46
|
+
package: p,
|
|
47
|
+
commands: [...commands]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!totalCommands)
|
|
51
|
+
return result;
|
|
52
|
+
let overallProgress;
|
|
53
|
+
const progressBars = options.gauge && new cli_progress_1.MultiBar({
|
|
54
|
+
format: '[' + chalk_1.default.cyan('{bar}') + '] {percentage}% | {value}/{total} | ' +
|
|
55
|
+
chalk_1.default.yellowBright('{package}') + ' | ' + chalk_1.default.yellow('{command}'),
|
|
56
|
+
barsize: 30,
|
|
57
|
+
hideCursor: true,
|
|
58
|
+
barCompleteChar: '\u2588',
|
|
59
|
+
barIncompleteChar: '\u2591',
|
|
60
|
+
}, cli_progress_1.Presets.rect);
|
|
61
|
+
if (progressBars) {
|
|
62
|
+
overallProgress = progressBars.create(totalCommands, 0);
|
|
63
|
+
overallProgress.start(totalCommands, 0, { package: '=== OVERALL ===', command: '' });
|
|
64
|
+
for (const p of Object.values(packages)) {
|
|
65
|
+
if (p.commands.length) {
|
|
66
|
+
p.progress = progressBars.create(p.commands.length, 0);
|
|
67
|
+
p.progress.start(p.commands.length, 0, {
|
|
68
|
+
package: p.name,
|
|
69
|
+
command: 'Waiting'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const t = Date.now();
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
const remaining = new Set(Object.keys(packages));
|
|
77
|
+
const runScripts = () => {
|
|
78
|
+
for (const pkgName of remaining) {
|
|
79
|
+
const pkgInfo = packages[pkgName];
|
|
80
|
+
const pkg = pkgInfo.package;
|
|
81
|
+
const progress = pkgInfo.progress;
|
|
82
|
+
for (let k = 0; k < pkgInfo.commands.length; k++) {
|
|
83
|
+
const cmd = pkgInfo.commands[k];
|
|
84
|
+
if (cmd.status === 'running')
|
|
85
|
+
break;
|
|
86
|
+
if (!cmd.status) {
|
|
87
|
+
const concurrent = cmd.step.startsWith('pre');
|
|
88
|
+
if (!concurrent &&
|
|
89
|
+
pkg.dependencies.find(dep => (0, utils_1.setFind)(remaining, p => p === dep))) {
|
|
90
|
+
cmd.status = '';
|
|
91
|
+
if (progress)
|
|
92
|
+
progress.update({ command: chalk_1.default.bgYellow.white('Waiting dependencies') });
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
cmd.status = 'running';
|
|
96
|
+
if (progress)
|
|
97
|
+
progress.update({ command: cmd.name });
|
|
98
|
+
else
|
|
99
|
+
console.log('[' + chalk_1.default.whiteBright(pkg.name) + '] ' +
|
|
100
|
+
chalk_1.default.yellow(cmd.command), (chalk_1.default.cyanBright(' +' + (Date.now() - t))));
|
|
101
|
+
void (0, executor_1.executeCommand)(cmd.command, {
|
|
102
|
+
...options,
|
|
103
|
+
cwd: pkg.dirname,
|
|
104
|
+
shell: true
|
|
105
|
+
}).then(r => {
|
|
106
|
+
if (overallProgress)
|
|
107
|
+
overallProgress.increment(1);
|
|
108
|
+
if (progress)
|
|
109
|
+
progress.increment(1);
|
|
110
|
+
const cr = {
|
|
111
|
+
package: pkg.name,
|
|
112
|
+
command: cmd,
|
|
113
|
+
code: r.code || 1,
|
|
114
|
+
error: r.error,
|
|
115
|
+
stdout: r.stdout,
|
|
116
|
+
stderr: r.stderr
|
|
117
|
+
};
|
|
118
|
+
result.code = result.code || r.code;
|
|
119
|
+
if (r.error)
|
|
120
|
+
result.errorCount++;
|
|
121
|
+
result.commands.push(cr);
|
|
122
|
+
cmd.status = 'done';
|
|
123
|
+
if (r.error || k === pkgInfo.commands.length - 1) {
|
|
124
|
+
if (progress) {
|
|
125
|
+
if (r.error)
|
|
126
|
+
progress.update({ command: chalk_1.default.yellow(cmd.name) + chalk_1.default.red(' Filed!') });
|
|
127
|
+
else
|
|
128
|
+
progress.update({ command: chalk_1.default.green(' Completed!') });
|
|
129
|
+
}
|
|
130
|
+
remaining.delete(pkg.name);
|
|
131
|
+
}
|
|
132
|
+
if (!remaining.size) {
|
|
133
|
+
if (progressBars)
|
|
134
|
+
progressBars.stop();
|
|
135
|
+
return resolve(result);
|
|
136
|
+
}
|
|
137
|
+
if (!result.errorCount)
|
|
138
|
+
setTimeout(runScripts, 1);
|
|
139
|
+
});
|
|
140
|
+
if (!concurrent)
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
runScripts();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static create(root, options) {
|
|
150
|
+
root = root || process.cwd();
|
|
151
|
+
let deep = options?.deep || 0;
|
|
152
|
+
while (deep-- >= 0 && fs_1.default.existsSync(root)) {
|
|
153
|
+
for (let i = providers.length - 1; i >= 0; i--) {
|
|
154
|
+
const provider = providers[i];
|
|
155
|
+
const inf = provider.parse(root);
|
|
156
|
+
if (!inf)
|
|
157
|
+
continue;
|
|
158
|
+
const pkgJson = (0, utils_1.getPackageJson)(inf.root);
|
|
159
|
+
if (!pkgJson)
|
|
160
|
+
continue;
|
|
161
|
+
const packages = [];
|
|
162
|
+
for (const pattern of inf.packages) {
|
|
163
|
+
const dirs = fast_glob_1.default.sync(pattern, {
|
|
164
|
+
cwd: inf.root,
|
|
165
|
+
absolute: true,
|
|
166
|
+
deep: 0,
|
|
167
|
+
onlyDirectories: true
|
|
168
|
+
});
|
|
169
|
+
for (const dir of dirs) {
|
|
170
|
+
const p = detectPackage(dir);
|
|
171
|
+
if (p && !packages.find(x => x.name === p.name))
|
|
172
|
+
packages.push(p);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return new Workspace(inf.root, packages, pkgJson.rman);
|
|
176
|
+
}
|
|
177
|
+
root = path_1.default.resolve(root, '..');
|
|
178
|
+
}
|
|
179
|
+
throw new Error('No project workspace detected');
|
|
180
|
+
}
|
|
181
|
+
_determineDependencies() {
|
|
182
|
+
const deps = {};
|
|
183
|
+
for (const pkg of this.packages) {
|
|
184
|
+
const o = {
|
|
185
|
+
...pkg.def.dependencies,
|
|
186
|
+
...pkg.def.devDependencies,
|
|
187
|
+
...pkg.def.peerDependencies,
|
|
188
|
+
...pkg.def.optionalDependencies
|
|
189
|
+
};
|
|
190
|
+
const dependencies = [];
|
|
191
|
+
for (const k of Object.keys(o)) {
|
|
192
|
+
const p = this.getPackage(k);
|
|
193
|
+
if (p)
|
|
194
|
+
dependencies.push(k);
|
|
195
|
+
}
|
|
196
|
+
deps[pkg.name] = dependencies;
|
|
197
|
+
pkg.dependencies = dependencies;
|
|
198
|
+
}
|
|
199
|
+
let circularCheck;
|
|
200
|
+
const deepFindDependencies = (pkg, target) => {
|
|
201
|
+
if (circularCheck.includes(pkg.name))
|
|
202
|
+
return;
|
|
203
|
+
circularCheck.push(pkg.name);
|
|
204
|
+
for (const s of pkg.dependencies) {
|
|
205
|
+
if (!target.includes(s)) {
|
|
206
|
+
target.push(s);
|
|
207
|
+
const p = this.getPackage(s);
|
|
208
|
+
if (p) {
|
|
209
|
+
deepFindDependencies(p, target);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
for (const pkg of this.packages) {
|
|
215
|
+
circularCheck = [];
|
|
216
|
+
deepFindDependencies(pkg, pkg.dependencies);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
_sortPackages() {
|
|
220
|
+
const packages = [...this.packages];
|
|
221
|
+
const packageOrder = this._options.packageOrder;
|
|
222
|
+
packages.sort((a, b) => {
|
|
223
|
+
if (packageOrder) {
|
|
224
|
+
const a1 = packageOrder.indexOf(a.name);
|
|
225
|
+
const b1 = packageOrder.indexOf(b.name);
|
|
226
|
+
const i = (a1 >= 0 ? a1 : Number.MAX_SAFE_INTEGER) - (b1 >= 0 ? b1 : Number.MAX_SAFE_INTEGER);
|
|
227
|
+
if (i !== 0)
|
|
228
|
+
return i;
|
|
229
|
+
}
|
|
230
|
+
if (b.dependencies.includes(a.name))
|
|
231
|
+
return -1;
|
|
232
|
+
if (a.dependencies.includes(b.name))
|
|
233
|
+
return 1;
|
|
234
|
+
return 0;
|
|
235
|
+
});
|
|
236
|
+
this._packages = packages;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.Workspace = Workspace;
|
|
240
|
+
function detectPackage(dirname) {
|
|
241
|
+
const pkgJson = (0, utils_1.getPackageJson)(dirname);
|
|
242
|
+
if (pkgJson && pkgJson.name) {
|
|
243
|
+
return new package_1.Package(dirname, pkgJson);
|
|
244
|
+
}
|
|
245
|
+
}
|
package/{dist → esm}/cli.d.ts
RENAMED
|
File without changes
|
package/esm/cli.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
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
|
+
}
|
|
60
|
+
}
|
package/{dist → esm}/index.d.ts
RENAMED
|
File without changes
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './workspace/workspace.mjs';
|
|
File without changes
|