printobserver-cli 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.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run the `printobserver` program this install resolved for the caller's platform.
4
+ *
5
+ * This launcher carries no program of its own. It declares one package per
6
+ * supported platform as an optional dependency, and the caller's package
7
+ * manager installs exactly the one their operating system and processor
8
+ * select; this finds that package and runs the program inside it.
9
+ *
10
+ * Nothing here compiles anything. The host this is installed on is the small
11
+ * machine beside the printer, and the whole reason the program is shipped
12
+ * already built is that that machine is the worst place to build it.
13
+ */
14
+
15
+ import { spawnSync } from "node:child_process";
16
+ import { createRequire } from "node:module";
17
+
18
+ /** What each supported platform's package is called, by what Node reports. */
19
+ const PACKAGES = {
20
+ "linux-x64": "@printobserver/cli-linux-x64",
21
+ "linux-arm64": "@printobserver/cli-linux-arm64",
22
+ };
23
+
24
+ const platform = `${process.platform}-${process.arch}`;
25
+ const name = PACKAGES[platform];
26
+ if (name === undefined) {
27
+ process.stderr.write(
28
+ `printobserver: this package ships no program for ${platform}. The platforms it ` +
29
+ `ships for are ${Object.keys(PACKAGES).join(", ")}. Install printobserver with ` +
30
+ `the bundled install script instead, or build it from source.\n`,
31
+ );
32
+ process.exit(1);
33
+ }
34
+
35
+ const require = createRequire(import.meta.url);
36
+ let program;
37
+ try {
38
+ program = require.resolve(`${name}/bin/printobserver`);
39
+ } catch {
40
+ process.stderr.write(
41
+ `printobserver: the program for ${platform} is not installed. Its package is ` +
42
+ `${name}, which this package declares as an optional dependency; an install ` +
43
+ `run with optional dependencies disabled leaves it out. Reinstall with them ` +
44
+ `enabled.\n`,
45
+ );
46
+ process.exit(1);
47
+ }
48
+
49
+ const ran = spawnSync(program, process.argv.slice(2), { stdio: "inherit" });
50
+ if (ran.error !== undefined) {
51
+ process.stderr.write(`printobserver: ${program} could not be run: ${ran.error.message}\n`);
52
+ process.exit(1);
53
+ }
54
+ process.exit(ran.status === null ? 1 : ran.status);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "bin": {
3
+ "printobserver": "bin/printobserver.mjs"
4
+ },
5
+ "description": "The printobserver command, already built for your platform.",
6
+ "files": [
7
+ "bin"
8
+ ],
9
+ "license": "MIT",
10
+ "name": "printobserver-cli",
11
+ "optionalDependencies": {
12
+ "@printobserver/cli-linux-arm64": "0.2.0",
13
+ "@printobserver/cli-linux-x64": "0.2.0"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/nickderobertis/printobserver"
18
+ },
19
+ "type": "module",
20
+ "version": "0.2.0"
21
+ }