@swarm-control/cli 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # swarmctl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Connects this machine to [swarm-control](https://swarmcontrol.dev) and
4
+ runs its agents.
5
+
6
+ ```sh
7
+ npx @swarm-control/cli --help
8
+ ```
9
+
10
+ This package is a small launcher. The `swarmctl` binary itself comes from a platform package
11
+ installed as an optional dependency: macOS and Linux, arm64 and x64.
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ // Finds the prebuilt swarmctl binary for this machine and runs it. The binary lives in a
3
+ // platform package (<this package's name>-<os>-<arch>) that npm installs as an optional
4
+ // dependency; there is no postinstall step.
5
+ "use strict";
6
+
7
+ const { spawn } = require("node:child_process");
8
+ const path = require("node:path");
9
+
10
+ const self = require("../package.json");
11
+ const supported = Object.keys(self.optionalDependencies || {});
12
+ const platformPackage = `${self.name}-${process.platform}-${process.arch}`;
13
+
14
+ function fail(message) {
15
+ process.stderr.write(`swarmctl: ${message}\n`);
16
+ process.exit(1);
17
+ }
18
+
19
+ function findBinary() {
20
+ if (supported.length > 0 && !supported.includes(platformPackage)) {
21
+ fail(
22
+ `no prebuilt binary for ${process.platform}-${process.arch}.\n` +
23
+ `Supported: ${supported.map((name) => name.slice(self.name.length + 1)).join(", ")}.`,
24
+ );
25
+ }
26
+ try {
27
+ const manifest = require.resolve(`${platformPackage}/package.json`);
28
+ return path.join(path.dirname(manifest), "bin", "swarmctl");
29
+ } catch {
30
+ fail(
31
+ `the platform package ${platformPackage} is not installed.\n` +
32
+ `npm installs it as an optional dependency of ${self.name}; it is skipped by\n` +
33
+ `--omit=optional / --no-optional, or when node_modules was copied from another machine.\n` +
34
+ `Fix: npm install ${platformPackage}@${self.version}`,
35
+ );
36
+ }
37
+ }
38
+
39
+ const child = spawn(findBinary(), process.argv.slice(2), { stdio: "inherit" });
40
+
41
+ child.on("error", (err) => fail(`could not start ${platformPackage}: ${err.message}`));
42
+
43
+ // Pass signals on, so stopping this process stops swarmctl. From a terminal, Ctrl-C and hangup
44
+ // already reach the binary directly (same foreground process group); then this process only
45
+ // has to stay alive until the binary exits, and must not deliver the signal a second time.
46
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"]) {
47
+ process.on(signal, () => {
48
+ const fromTerminal = signal !== "SIGTERM" && process.stdin.isTTY;
49
+ if (!fromTerminal) child.kill(signal);
50
+ });
51
+ }
52
+
53
+ child.on("exit", (code, signal) => {
54
+ if (signal) {
55
+ // Die of the same signal, so the caller sees what really happened.
56
+ process.removeAllListeners(signal);
57
+ process.kill(process.pid, signal);
58
+ return;
59
+ }
60
+ process.exit(code ?? 1);
61
+ });
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "@swarm-control/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "swarmctl: connects this machine to swarm-control and runs its agents",
5
+ "bin": {
6
+ "swarmctl": "bin/swarmctl.js"
7
+ },
8
+ "files": [
9
+ "bin"
10
+ ],
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "optionalDependencies": {
15
+ "@swarm-control/cli-darwin-arm64": "0.1.0",
16
+ "@swarm-control/cli-darwin-x64": "0.1.0",
17
+ "@swarm-control/cli-linux-x64": "0.1.0",
18
+ "@swarm-control/cli-linux-arm64": "0.1.0"
19
+ }
20
+ }