rman 0.0.1 → 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/cjs/index.js +13 -0
- package/cjs/package.json +3 -0
- package/cjs/workspace/executor.js +114 -0
- package/cjs/workspace/package.js +43 -0
- package/cjs/workspace/providers/npm-provider.js +16 -0
- package/cjs/workspace/types.js +2 -0
- package/cjs/workspace/utils.js +31 -0
- package/cjs/workspace/workspace.js +245 -0
- package/{dist → esm}/cli.d.ts +0 -0
- package/{dist/cli.js → esm/cli.mjs} +13 -4
- package/{dist → esm}/index.d.ts +0 -0
- package/esm/index.mjs +1 -0
- package/{dist → esm}/workspace/executor.d.ts +0 -0
- package/{dist/workspace/executor.js → esm/workspace/executor.mjs} +1 -1
- package/{dist → esm}/workspace/package.d.ts +0 -0
- package/{dist/workspace/package.js → esm/workspace/package.mjs} +0 -0
- package/{dist → esm}/workspace/providers/npm-provider.d.ts +1 -1
- package/{dist/workspace/providers/npm-provider.js → esm/workspace/providers/npm-provider.mjs} +2 -2
- package/{dist → esm}/workspace/types.d.ts +1 -2
- package/{dist/workspace/types.js → esm/workspace/types.mjs} +0 -0
- package/{dist → esm}/workspace/utils.d.ts +0 -0
- package/{dist/workspace/utils.js → esm/workspace/utils.mjs} +0 -0
- package/esm/workspace/workspace.d.ts +17 -0
- package/{dist/workspace/workspace.js → esm/workspace/workspace.mjs} +70 -59
- package/package.json +26 -14
- package/dist/index.js +0 -1
- package/dist/workspace/workspace.d.ts +0 -16
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/cjs/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./workspace/workspace"), exports);
|
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
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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.Package = void 0;
|
|
7
|
+
const parse_npm_script_1 = __importDefault(require("@netlify/parse-npm-script"));
|
|
8
|
+
class Package {
|
|
9
|
+
constructor(dirname, def) {
|
|
10
|
+
this.dirname = dirname;
|
|
11
|
+
this.dependencies = [];
|
|
12
|
+
Object.defineProperty(this, 'def', {
|
|
13
|
+
enumerable: false,
|
|
14
|
+
value: def,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
get name() {
|
|
18
|
+
return this.def.name;
|
|
19
|
+
}
|
|
20
|
+
getScriptCommands(script) {
|
|
21
|
+
const result = [];
|
|
22
|
+
let scriptInfo;
|
|
23
|
+
try {
|
|
24
|
+
scriptInfo = (0, parse_npm_script_1.default)(this.def, 'npm run ' + script);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (scriptInfo && scriptInfo.raw)
|
|
30
|
+
for (const step of scriptInfo.steps) {
|
|
31
|
+
const parsed = Array.isArray(step.parsed) ? step.parsed : [step.parsed];
|
|
32
|
+
for (const cmd of parsed) {
|
|
33
|
+
result.push({
|
|
34
|
+
name: cmd.split(' ')[0],
|
|
35
|
+
command: cmd,
|
|
36
|
+
step: step.name
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Package = Package;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NpmProvider = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class NpmProvider {
|
|
6
|
+
parse(root) {
|
|
7
|
+
const pkg = (0, utils_1.getPackageJson)(root);
|
|
8
|
+
if (pkg && typeof pkg.workspaces === 'object') {
|
|
9
|
+
if (Array.isArray(pkg.workspaces))
|
|
10
|
+
return { root, packages: pkg.workspaces };
|
|
11
|
+
if (Array.isArray(pkg.workspaces.packages))
|
|
12
|
+
return { root, packages: pkg.workspaces.packages };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NpmProvider = NpmProvider;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.setFind = exports.onProcessExit = exports.getPackageJson = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
function getPackageJson(dirname) {
|
|
10
|
+
const f = path_1.default.resolve(dirname, 'package.json');
|
|
11
|
+
if (!fs_1.default.existsSync(f))
|
|
12
|
+
return;
|
|
13
|
+
return JSON.parse(fs_1.default.readFileSync(f, 'utf-8'));
|
|
14
|
+
}
|
|
15
|
+
exports.getPackageJson = getPackageJson;
|
|
16
|
+
function onProcessExit(listener, forceExit = true) {
|
|
17
|
+
["SIGTERM", "SIGINT"].forEach((event) => process.once(event, (signal) => {
|
|
18
|
+
listener(signal);
|
|
19
|
+
if (forceExit)
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}));
|
|
22
|
+
process.once("exit", () => listener("exit"));
|
|
23
|
+
}
|
|
24
|
+
exports.onProcessExit = onProcessExit;
|
|
25
|
+
function setFind(set, cb) {
|
|
26
|
+
for (const e of set) {
|
|
27
|
+
if (cb(e))
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.setFind = setFind;
|
|
@@ -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
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import path from 'path';
|
|
1
2
|
import fs from 'fs/promises';
|
|
2
|
-
import { URL } from 'url';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { program } from "commander";
|
|
5
|
-
import { Workspace } from './workspace/workspace.
|
|
5
|
+
import { Workspace } from './workspace/workspace.mjs';
|
|
6
|
+
import { URL } from 'url';
|
|
6
7
|
export async function run(argv = process.argv) {
|
|
7
|
-
const pkgJson = JSON.parse(
|
|
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'));
|
|
8
12
|
program.version(pkgJson.version || '');
|
|
9
13
|
program
|
|
10
14
|
.command('run <script>')
|
|
@@ -29,10 +33,15 @@ export async function run(argv = process.argv) {
|
|
|
29
33
|
program.parse(argv);
|
|
30
34
|
}
|
|
31
35
|
async function runScript(script) {
|
|
32
|
-
const workspace =
|
|
36
|
+
const workspace = Workspace.create();
|
|
33
37
|
const result = await workspace.runScript(script, {
|
|
34
38
|
gauge: true
|
|
35
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
|
+
}
|
|
36
45
|
if (result.errorCount) {
|
|
37
46
|
console.error('\n' + chalk.yellow(result.errorCount) + chalk.white(' error(s)'));
|
|
38
47
|
let s = '';
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import npmRubPath from 'npm-run-path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import { onProcessExit } from './utils.
|
|
4
|
+
import { onProcessExit } from './utils.mjs';
|
|
5
5
|
const runningChildren = new Map();
|
|
6
6
|
export async function executeCommand(command, options) {
|
|
7
7
|
const opts = {
|
|
File without changes
|
|
File without changes
|
package/{dist/workspace/providers/npm-provider.js → esm/workspace/providers/npm-provider.mjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getPackageJson } from '
|
|
1
|
+
import { getPackageJson } from './../utils.mjs';
|
|
2
2
|
export class NpmProvider {
|
|
3
|
-
|
|
3
|
+
parse(root) {
|
|
4
4
|
const pkg = getPackageJson(root);
|
|
5
5
|
if (pkg && typeof pkg.workspaces === 'object') {
|
|
6
6
|
if (Array.isArray(pkg.workspaces))
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export interface IWorkspaceOptions {
|
|
2
2
|
packageOrder?: string[];
|
|
3
|
-
scripts?: Record<string, {}>;
|
|
4
3
|
}
|
|
5
4
|
export interface IWorkspaceProvider {
|
|
6
|
-
parse: (root: string) =>
|
|
5
|
+
parse: (root: string) => IParsedWorkspaceInfo | undefined;
|
|
7
6
|
}
|
|
8
7
|
export interface IParsedWorkspaceInfo {
|
|
9
8
|
root: string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IRunScriptOptions } from './executor';
|
|
2
|
+
import { Package, RunScriptResult } from './package';
|
|
3
|
+
import { IWorkspaceOptions } from './types';
|
|
4
|
+
export declare class Workspace {
|
|
5
|
+
readonly root: string;
|
|
6
|
+
private _options;
|
|
7
|
+
private _packages;
|
|
8
|
+
protected constructor(root: string, packages: Package[], options?: IWorkspaceOptions);
|
|
9
|
+
get packages(): Package[];
|
|
10
|
+
getPackage(name: string): Package | undefined;
|
|
11
|
+
runScript(script: string, options?: IRunScriptOptions): Promise<RunScriptResult>;
|
|
12
|
+
static create(root?: string, options?: {
|
|
13
|
+
deep?: number;
|
|
14
|
+
}): Workspace;
|
|
15
|
+
private _determineDependencies;
|
|
16
|
+
private _sortPackages;
|
|
17
|
+
}
|
|
@@ -3,19 +3,23 @@ import glob from 'fast-glob';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { MultiBar, Presets } from 'cli-progress';
|
|
6
|
-
import { getPackageJson, setFind } from './utils.
|
|
7
|
-
import { executeCommand } from './executor.
|
|
8
|
-
import { Package } from './package.
|
|
9
|
-
import { NpmProvider } from './providers/npm-provider.
|
|
6
|
+
import { getPackageJson, setFind } from './utils.mjs';
|
|
7
|
+
import { executeCommand } from './executor.mjs';
|
|
8
|
+
import { Package } from './package.mjs';
|
|
9
|
+
import { NpmProvider } from './providers/npm-provider.mjs';
|
|
10
10
|
const providers = [
|
|
11
11
|
new NpmProvider()
|
|
12
12
|
];
|
|
13
13
|
export class Workspace {
|
|
14
14
|
constructor(root, packages, options) {
|
|
15
15
|
this.root = root;
|
|
16
|
-
this.packages = packages;
|
|
17
16
|
this._options = { ...options };
|
|
17
|
+
this._packages = packages;
|
|
18
18
|
this._determineDependencies();
|
|
19
|
+
this._sortPackages();
|
|
20
|
+
}
|
|
21
|
+
get packages() {
|
|
22
|
+
return this._packages;
|
|
19
23
|
}
|
|
20
24
|
getPackage(name) {
|
|
21
25
|
return this.packages.find(p => p.name === name);
|
|
@@ -28,31 +32,38 @@ export class Workspace {
|
|
|
28
32
|
commands: []
|
|
29
33
|
};
|
|
30
34
|
options.gauge = options.gauge == null ? true : options.gauge;
|
|
31
|
-
const progressBars = options.gauge && new MultiBar({
|
|
32
|
-
format: '[' + chalk.cyan('{bar}') + '] {percentage}% | {value}/{total} | ' +
|
|
33
|
-
chalk.yellowBright('{package}') + ' | ' + chalk.yellow('{command}'),
|
|
34
|
-
barsize: 30,
|
|
35
|
-
hideCursor: true
|
|
36
|
-
}, Presets.rect);
|
|
37
|
-
const overallProgress = progressBars && progressBars.create(0, 0);
|
|
38
35
|
let totalCommands = 0;
|
|
39
|
-
for (const p of this.
|
|
36
|
+
for (const p of this.packages) {
|
|
40
37
|
const commands = p.getScriptCommands(script);
|
|
41
|
-
|
|
38
|
+
totalCommands += commands.length;
|
|
42
39
|
packages[p.name] = {
|
|
43
40
|
package: p,
|
|
44
|
-
commands: [...commands]
|
|
45
|
-
progress
|
|
41
|
+
commands: [...commands]
|
|
46
42
|
};
|
|
47
|
-
totalCommands += commands.length;
|
|
48
|
-
if (progress)
|
|
49
|
-
progress.start(commands.length, 0, {
|
|
50
|
-
package: p.name,
|
|
51
|
-
command: 'Waiting'
|
|
52
|
-
});
|
|
53
43
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
44
|
+
if (!totalCommands)
|
|
45
|
+
return result;
|
|
46
|
+
let overallProgress;
|
|
47
|
+
const progressBars = options.gauge && new MultiBar({
|
|
48
|
+
format: '[' + chalk.cyan('{bar}') + '] {percentage}% | {value}/{total} | ' +
|
|
49
|
+
chalk.yellowBright('{package}') + ' | ' + chalk.yellow('{command}'),
|
|
50
|
+
barsize: 30,
|
|
51
|
+
hideCursor: true,
|
|
52
|
+
barCompleteChar: '\u2588',
|
|
53
|
+
barIncompleteChar: '\u2591',
|
|
54
|
+
}, Presets.rect);
|
|
55
|
+
if (progressBars) {
|
|
56
|
+
overallProgress = progressBars.create(totalCommands, 0);
|
|
57
|
+
overallProgress.start(totalCommands, 0, { package: '=== OVERALL ===', command: '' });
|
|
58
|
+
for (const p of Object.values(packages)) {
|
|
59
|
+
if (p.commands.length) {
|
|
60
|
+
p.progress = progressBars.create(p.commands.length, 0);
|
|
61
|
+
p.progress.start(p.commands.length, 0, {
|
|
62
|
+
package: p.name,
|
|
63
|
+
command: 'Waiting'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
56
67
|
}
|
|
57
68
|
const t = Date.now();
|
|
58
69
|
return new Promise((resolve) => {
|
|
@@ -129,6 +140,38 @@ export class Workspace {
|
|
|
129
140
|
runScripts();
|
|
130
141
|
});
|
|
131
142
|
}
|
|
143
|
+
static create(root, options) {
|
|
144
|
+
root = root || process.cwd();
|
|
145
|
+
let deep = options?.deep || 0;
|
|
146
|
+
while (deep-- >= 0 && fs.existsSync(root)) {
|
|
147
|
+
for (let i = providers.length - 1; i >= 0; i--) {
|
|
148
|
+
const provider = providers[i];
|
|
149
|
+
const inf = provider.parse(root);
|
|
150
|
+
if (!inf)
|
|
151
|
+
continue;
|
|
152
|
+
const pkgJson = getPackageJson(inf.root);
|
|
153
|
+
if (!pkgJson)
|
|
154
|
+
continue;
|
|
155
|
+
const packages = [];
|
|
156
|
+
for (const pattern of inf.packages) {
|
|
157
|
+
const dirs = glob.sync(pattern, {
|
|
158
|
+
cwd: inf.root,
|
|
159
|
+
absolute: true,
|
|
160
|
+
deep: 0,
|
|
161
|
+
onlyDirectories: true
|
|
162
|
+
});
|
|
163
|
+
for (const dir of dirs) {
|
|
164
|
+
const p = detectPackage(dir);
|
|
165
|
+
if (p && !packages.find(x => x.name === p.name))
|
|
166
|
+
packages.push(p);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return new Workspace(inf.root, packages, pkgJson.rman);
|
|
170
|
+
}
|
|
171
|
+
root = path.resolve(root, '..');
|
|
172
|
+
}
|
|
173
|
+
throw new Error('No project workspace detected');
|
|
174
|
+
}
|
|
132
175
|
_determineDependencies() {
|
|
133
176
|
const deps = {};
|
|
134
177
|
for (const pkg of this.packages) {
|
|
@@ -167,7 +210,7 @@ export class Workspace {
|
|
|
167
210
|
deepFindDependencies(pkg, pkg.dependencies);
|
|
168
211
|
}
|
|
169
212
|
}
|
|
170
|
-
|
|
213
|
+
_sortPackages() {
|
|
171
214
|
const packages = [...this.packages];
|
|
172
215
|
const packageOrder = this._options.packageOrder;
|
|
173
216
|
packages.sort((a, b) => {
|
|
@@ -184,42 +227,10 @@ export class Workspace {
|
|
|
184
227
|
return 1;
|
|
185
228
|
return 0;
|
|
186
229
|
});
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
static async resolve(root, options) {
|
|
190
|
-
root = root || process.cwd();
|
|
191
|
-
let deep = options?.deep || 0;
|
|
192
|
-
while (deep-- >= 0 && fs.existsSync(root)) {
|
|
193
|
-
for (let i = providers.length - 1; i >= 0; i--) {
|
|
194
|
-
const provider = providers[i];
|
|
195
|
-
const inf = await provider.parse(root);
|
|
196
|
-
if (!inf)
|
|
197
|
-
continue;
|
|
198
|
-
const pkgJson = getPackageJson(inf.root);
|
|
199
|
-
if (!pkgJson)
|
|
200
|
-
continue;
|
|
201
|
-
const packages = [];
|
|
202
|
-
for (const pattern of inf.packages) {
|
|
203
|
-
const dirs = await glob(pattern, {
|
|
204
|
-
cwd: inf.root,
|
|
205
|
-
absolute: true,
|
|
206
|
-
deep: 0,
|
|
207
|
-
onlyDirectories: true
|
|
208
|
-
});
|
|
209
|
-
for (const dir of dirs) {
|
|
210
|
-
const p = await detectPackage(dir);
|
|
211
|
-
if (p && !packages.find(x => x.name === p.name))
|
|
212
|
-
packages.push(p);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return new Workspace(inf.root, packages, pkgJson.rman);
|
|
216
|
-
}
|
|
217
|
-
root = path.resolve(root, '..');
|
|
218
|
-
}
|
|
219
|
-
throw new Error('No project workspace detected');
|
|
230
|
+
this._packages = packages;
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
|
-
|
|
233
|
+
function detectPackage(dirname) {
|
|
223
234
|
const pkgJson = getPackageJson(dirname);
|
|
224
235
|
if (pkgJson && pkgJson.name) {
|
|
225
236
|
return new Package(dirname, pkgJson);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rman",
|
|
3
3
|
"description": "Monorepo repository manager",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"contributors": [
|
|
@@ -23,23 +23,29 @@
|
|
|
23
23
|
"rman": "bin/rman.js"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"main": "cjs/index.js",
|
|
27
|
+
"module": "esm/index.mjs",
|
|
28
|
+
"types": "esm/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./cjs/index.js",
|
|
31
|
+
"./cjs": "./cjs/index.js",
|
|
32
|
+
"./esm": "./esm/index.mjs"
|
|
33
|
+
},
|
|
28
34
|
"dependencies": {
|
|
35
|
+
"@netlify/parse-npm-script": "^0.1.2",
|
|
29
36
|
"chalk": "^4.1.2",
|
|
37
|
+
"cli-progress": "^3.9.1",
|
|
30
38
|
"commander": "^8.3.0",
|
|
31
39
|
"fast-glob": "^3.2.7",
|
|
32
|
-
"npm-run-path": "^4.0.1"
|
|
33
|
-
"@netlify/parse-npm-script": "^0.1.2",
|
|
34
|
-
"cli-progress": "^3.9.1"
|
|
40
|
+
"npm-run-path": "^4.0.1"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
43
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
44
|
+
"@types/cli-progress": "^3.9.2",
|
|
37
45
|
"@types/mocha": "^9.0.0",
|
|
38
46
|
"@types/node": "^16.4.8",
|
|
39
|
-
"@types/cli-progress": "^3.9.2",
|
|
40
47
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
41
48
|
"@typescript-eslint/parser": "^5.0.0",
|
|
42
|
-
"@babel/eslint-parser": "^7.16.3",
|
|
43
49
|
"eslint": "^8.0.0",
|
|
44
50
|
"eslint-config-google": "^0.14.0",
|
|
45
51
|
"mocha": "^9.0.1",
|
|
@@ -48,14 +54,17 @@
|
|
|
48
54
|
"ts-loader": "^9.0.0",
|
|
49
55
|
"ts-node": "^10.0.0",
|
|
50
56
|
"tsconfig-paths": "^3.9.0",
|
|
51
|
-
"typescript": "^4.5.2"
|
|
57
|
+
"typescript": "^4.5.2",
|
|
58
|
+
"typescript-esm": "^2.0.0"
|
|
52
59
|
},
|
|
53
60
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
61
|
+
"node": ">=14.0",
|
|
62
|
+
"npm": ">=7.0.0"
|
|
55
63
|
},
|
|
56
64
|
"files": [
|
|
57
|
-
"dist/",
|
|
58
65
|
"bin/",
|
|
66
|
+
"cjs/",
|
|
67
|
+
"esm/",
|
|
59
68
|
"LICENSE",
|
|
60
69
|
"README.md"
|
|
61
70
|
],
|
|
@@ -63,10 +72,13 @@
|
|
|
63
72
|
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register --reporter spec test/**/*.spec.ts",
|
|
64
73
|
"cover": "nyc --reporter=cobertura --reporter html --reporter text npm run test",
|
|
65
74
|
"clean": "npm run clean:src && npm run clean:dist",
|
|
66
|
-
"clean:dist": "
|
|
75
|
+
"clean:dist": "rimraf cjs esm",
|
|
67
76
|
"clean:src": "ts-cleanup -s src --all | ts-cleanup -s test",
|
|
68
|
-
"prebuild": "npm run clean && npm run lint",
|
|
69
|
-
"build": "
|
|
77
|
+
"prebuild": "npm run clean:dist && npm run lint",
|
|
78
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
79
|
+
"build:cjs": "tsc -b tsconfig.build-cjs.json",
|
|
80
|
+
"build:esm": "tsc -b tsconfig.build-esm.json && tsc-esm -p tsconfig.build-esm.json",
|
|
81
|
+
"postbuild": "cp ./src/package.cjs.json ./cjs/package.json",
|
|
70
82
|
"compile": "tsc -b tsconfig.json",
|
|
71
83
|
"lint": "eslint src/** --no-error-on-unmatched-pattern",
|
|
72
84
|
"travis-cover": "nyc --reporter lcovonly npm run test"
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './workspace/workspace';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IRunScriptOptions } from './executor.js';
|
|
2
|
-
import { Package, RunScriptResult } from './package.js';
|
|
3
|
-
import { IWorkspaceOptions } from './types.js';
|
|
4
|
-
export declare class Workspace {
|
|
5
|
-
readonly root: string;
|
|
6
|
-
readonly packages: Package[];
|
|
7
|
-
private _options;
|
|
8
|
-
constructor(root: string, packages: Package[], options?: IWorkspaceOptions);
|
|
9
|
-
getPackage(name: string): Package | undefined;
|
|
10
|
-
runScript(script: string, options?: IRunScriptOptions): Promise<RunScriptResult>;
|
|
11
|
-
private _determineDependencies;
|
|
12
|
-
private _getSortedPackages;
|
|
13
|
-
static resolve(root?: string, options?: {
|
|
14
|
-
deep?: number;
|
|
15
|
-
}): Promise<Workspace>;
|
|
16
|
-
}
|