dossiers 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.
Files changed (3) hide show
  1. package/install.js +81 -0
  2. package/package.json +10 -0
  3. package/run.js +17 -0
package/install.js ADDED
@@ -0,0 +1,81 @@
1
+ const os = require("os");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const https = require("https");
5
+
6
+ const platform = `${os.platform()}-${os.arch()}`;
7
+ const version = "0.1.0";
8
+ const targets = {
9
+ "linux-x64": "dossiers-linux-x86_64",
10
+ "linux-arm64": "dossiers-linux-aarch64",
11
+ "darwin-x64": "dossiers-macos-x86_64",
12
+ "darwin-arm64": "dossiers-macos-aarch64",
13
+ "win32-x64": "dossiers-windows-x86_64.exe",
14
+ "win32-arm64": "dossiers-windows-aarch64.exe",
15
+ };
16
+
17
+ const target = targets[platform];
18
+ if (!target) {
19
+ console.error(`Unsupported platform: ${platform}`);
20
+ process.exit(1);
21
+ }
22
+
23
+ const downloadUrl = `https://github.com/dossie-rs/cli/releases/download/v${version}/${target}`;
24
+ const binName = os.platform() === "win32" ? "dossiers.exe" : "dossiers";
25
+ const binPath = path.join(__dirname, binName);
26
+
27
+ if (fs.existsSync(binPath)) {
28
+ process.exit(0);
29
+ }
30
+
31
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "dossiers-"));
32
+ const downloadPath = path.join(tmpDir, target);
33
+
34
+ function download(url, destination) {
35
+ return new Promise((resolve, reject) => {
36
+ const file = fs.createWriteStream(destination);
37
+ const handleResponse = (res) => {
38
+ if (
39
+ res.statusCode >= 300 &&
40
+ res.statusCode < 400 &&
41
+ res.headers.location
42
+ ) {
43
+ // Follow redirects for GitHub release assets
44
+ return download(res.headers.location, destination)
45
+ .then(resolve)
46
+ .catch(reject);
47
+ }
48
+
49
+ if (res.statusCode !== 200) {
50
+ return reject(
51
+ new Error(`Download failed with status ${res.statusCode}`)
52
+ );
53
+ }
54
+
55
+ res.pipe(file);
56
+ file.on("finish", () => file.close(resolve));
57
+ };
58
+
59
+ https
60
+ .get(url, handleResponse)
61
+ .on("error", (err) => {
62
+ fs.rm(destination, { force: true }, () => reject(err));
63
+ });
64
+ });
65
+ }
66
+
67
+ (async () => {
68
+ try {
69
+ console.log(`Downloading ${target}...`);
70
+ await download(downloadUrl, downloadPath);
71
+
72
+ fs.copyFileSync(downloadPath, binPath);
73
+ fs.chmodSync(binPath, 0o755);
74
+ console.log(`Installed binary to ${binPath}`);
75
+ } catch (err) {
76
+ console.error(err.message || err);
77
+ process.exit(1);
78
+ } finally {
79
+ fs.rm(tmpDir, { recursive: true, force: true }, () => {});
80
+ }
81
+ })();
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "dossiers",
3
+ "version": "0.1.0",
4
+ "bin": {
5
+ "dossiers": "run.js"
6
+ },
7
+ "scripts": {
8
+ "postinstall": "node install.js"
9
+ }
10
+ }
package/run.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+
7
+ const binName = process.platform === "win32" ? "dossiers.exe" : "dossiers";
8
+ const bin = path.join(__dirname, binName);
9
+
10
+ if (!fs.existsSync(bin)) {
11
+ console.error("Dossiers binary is missing. Please reinstall the package.");
12
+ process.exit(1);
13
+ }
14
+
15
+ const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
16
+
17
+ process.exit(result.status);