@colony2/c2 0.0.4 → 0.0.6
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 +10 -1
- package/bin/c2.cjs +90 -0
- package/package.json +16 -12
- package/scripts/install-tools.mjs +42 -0
- package/scripts/require-global-install.mjs +7 -0
- package/bin/c2j.cjs +0 -2
- package/bin/c2m.cjs +0 -2
- package/bin/c2r.cjs +0 -2
- package/bin/jobdb.cjs +0 -2
- package/bin/run-dependency-bin.cjs +0 -58
- package/bin/shai.cjs +0 -2
package/README.md
CHANGED
|
@@ -20,4 +20,13 @@ GitHub: [colony-2/metapackage](https://github.com/colony-2/metapackage)
|
|
|
20
20
|
npm install -g @colony2/c2
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
This installs the package set and exposes the `c2r`, `c2m`, `c2j`, `jobdb`, and `shai` commands on your `PATH`.
|
|
23
|
+
This installs the package set globally and exposes the `c2r`, `c2m`, `c2j`, `jobdb`, and `shai` commands on your `PATH`.
|
|
24
|
+
|
|
25
|
+
Only global installation is supported.
|
|
26
|
+
|
|
27
|
+
The package also provides a `c2` helper:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
c2 versions
|
|
31
|
+
c2 install
|
|
32
|
+
```
|
package/bin/c2.cjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const { existsSync, readFileSync } = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const packagePath = path.resolve(__dirname, "..", "package.json");
|
|
7
|
+
const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
8
|
+
const tools = pkg.colony2?.tools ?? {};
|
|
9
|
+
const toolCommands = Object.keys(tools).map((name) => name.split("/").pop());
|
|
10
|
+
|
|
11
|
+
function printHelp() {
|
|
12
|
+
console.log(`Usage: c2 <command>
|
|
13
|
+
|
|
14
|
+
Commands:
|
|
15
|
+
install Install or update the bundled Colony 2 tools globally
|
|
16
|
+
versions Show bundled tool versions
|
|
17
|
+
help Show this help
|
|
18
|
+
|
|
19
|
+
Bundled tools:
|
|
20
|
+
${toolCommands.join(", ")}
|
|
21
|
+
|
|
22
|
+
You can also run a bundled tool through c2, for example:
|
|
23
|
+
c2 shai --help`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function run(command, args, options = {}) {
|
|
27
|
+
const result = spawnSync(command, args, {
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
shell: process.platform === "win32",
|
|
30
|
+
...options
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (result.error) {
|
|
34
|
+
console.error(result.error.message);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
process.exit(result.status ?? 1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function localBin(command) {
|
|
42
|
+
const names = process.platform === "win32" ? [`${command}.cmd`, command] : [command];
|
|
43
|
+
let current = process.cwd();
|
|
44
|
+
|
|
45
|
+
while (true) {
|
|
46
|
+
for (const name of names) {
|
|
47
|
+
const candidate = path.join(current, "node_modules", ".bin", name);
|
|
48
|
+
if (existsSync(candidate)) {
|
|
49
|
+
return candidate;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const parent = path.dirname(current);
|
|
54
|
+
if (parent === current) {
|
|
55
|
+
return command;
|
|
56
|
+
}
|
|
57
|
+
current = parent;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const [command, ...args] = process.argv.slice(2);
|
|
62
|
+
|
|
63
|
+
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
64
|
+
printHelp();
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (command === "versions") {
|
|
69
|
+
for (const [tool, version] of Object.entries(tools)) {
|
|
70
|
+
console.log(`${tool}@${version}`);
|
|
71
|
+
}
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (command === "install") {
|
|
76
|
+
run(process.execPath, [path.resolve(__dirname, "..", "scripts", "install-tools.mjs")], {
|
|
77
|
+
env: {
|
|
78
|
+
...process.env,
|
|
79
|
+
C2_INSTALL_TOOLS: "1"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (toolCommands.includes(command)) {
|
|
85
|
+
run(localBin(command), args);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.error(`Unknown command: ${command}`);
|
|
89
|
+
printHelp();
|
|
90
|
+
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colony2/c2",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Metapackage for the Colony 2 packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,25 +12,29 @@
|
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/colony-2/metapackage#readme",
|
|
14
14
|
"bin": {
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
15
|
+
"c2": "bin/c2.cjs"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"preinstall": "node scripts/require-global-install.mjs",
|
|
19
|
+
"postinstall": "node scripts/install-tools.mjs"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"bin",
|
|
26
|
+
"scripts/install-tools.mjs",
|
|
27
|
+
"scripts/require-global-install.mjs",
|
|
26
28
|
"LICENSE",
|
|
27
29
|
"README.md"
|
|
28
30
|
],
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
"colony2": {
|
|
32
|
+
"tools": {
|
|
33
|
+
"@colony2/c2j": "0.0.41",
|
|
34
|
+
"@colony2/c2m": "0.0.3",
|
|
35
|
+
"@colony2/c2r": "0.0.2",
|
|
36
|
+
"@colony2/jobdb": "0.0.13",
|
|
37
|
+
"@colony2/shai": "0.0.11"
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
const packageJsonPath = new URL("../package.json", import.meta.url);
|
|
5
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
6
|
+
const tools = pkg.colony2?.tools ?? {};
|
|
7
|
+
const specs = Object.entries(tools).map(([name, version]) => `${name}@${version}`);
|
|
8
|
+
|
|
9
|
+
const forceInstall = process.env.C2_INSTALL_TOOLS === "1";
|
|
10
|
+
const globalLifecycle = process.env.npm_config_global === "true";
|
|
11
|
+
|
|
12
|
+
if (!forceInstall && !globalLifecycle) {
|
|
13
|
+
console.log("@colony2/c2 tool installation is skipped for non-global installs.");
|
|
14
|
+
process.exit(0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (specs.length === 0) {
|
|
18
|
+
console.log("No Colony 2 tools are configured.");
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function npmPrefix() {
|
|
23
|
+
if (process.env.npm_config_prefix) {
|
|
24
|
+
return process.env.npm_config_prefix;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return execFileSync("npm", ["prefix", "-g"], {
|
|
28
|
+
encoding: "utf8",
|
|
29
|
+
stdio: ["ignore", "pipe", "inherit"]
|
|
30
|
+
}).trim();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const prefix = npmPrefix();
|
|
34
|
+
|
|
35
|
+
console.log(`Installing Colony 2 tools into ${prefix}`);
|
|
36
|
+
for (const spec of specs) {
|
|
37
|
+
console.log(` ${spec}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
execFileSync("npm", ["install", "-g", "--prefix", prefix, ...specs], {
|
|
41
|
+
stdio: "inherit"
|
|
42
|
+
});
|
package/bin/c2j.cjs
DELETED
package/bin/c2m.cjs
DELETED
package/bin/c2r.cjs
DELETED
package/bin/jobdb.cjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const { spawn } = require("child_process");
|
|
2
|
-
const { existsSync } = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
function resolveDependencyBin(packageName, binPath) {
|
|
6
|
-
const candidates = [];
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
candidates.push(require.resolve(`${packageName}/${binPath}`));
|
|
10
|
-
} catch (_error) {
|
|
11
|
-
// Some packages may restrict subpath resolution through exports.
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
candidates.push(path.join(path.dirname(require.resolve(`${packageName}/package.json`)), binPath));
|
|
16
|
-
} catch (_error) {
|
|
17
|
-
// Fall back to the normal nested dependency layout below.
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
candidates.push(path.resolve(__dirname, "..", "node_modules", ...packageName.split("/"), binPath));
|
|
21
|
-
|
|
22
|
-
for (const candidate of candidates) {
|
|
23
|
-
if (existsSync(candidate)) {
|
|
24
|
-
return candidate;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
throw new Error(`Unable to find ${packageName}/${binPath}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = function runDependencyBin(packageName, binPath) {
|
|
32
|
-
let script;
|
|
33
|
-
try {
|
|
34
|
-
script = resolveDependencyBin(packageName, binPath);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error(error.message);
|
|
37
|
-
console.error("Try reinstalling @colony2/c2.");
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const child = spawn(process.execPath, [script, ...process.argv.slice(2)], {
|
|
42
|
-
stdio: "inherit"
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
child.on("error", (error) => {
|
|
46
|
-
console.error(error.message);
|
|
47
|
-
process.exit(1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
child.on("exit", (code, signal) => {
|
|
51
|
-
if (signal) {
|
|
52
|
-
process.kill(process.pid, signal);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
process.exit(code ?? 1);
|
|
57
|
-
});
|
|
58
|
-
};
|
package/bin/shai.cjs
DELETED