backlog.md 0.1.24 → 0.1.26

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/cli.js CHANGED
@@ -1,115 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { spawn } = require("node:child_process");
4
- const { join } = require("node:path");
5
- const fs = require("node:fs");
6
- const https = require("node:https");
7
- const { createWriteStream, chmodSync } = require("node:fs");
4
+ const { resolveBinaryPath } = require("./resolveBinary.cjs");
8
5
 
9
- const { getBinaryName } = require("./getBinaryName.cjs");
10
-
11
- // Download binary from GitHub releases
12
- async function downloadBinary(binaryName, binaryPath) {
13
- const packageJson = require(join(__dirname, "package.json"));
14
- const version = packageJson.version;
15
- const url = `https://github.com/MrLesk/Backlog.md/releases/download/v${version}/${binaryName}`;
16
-
17
- console.log(`Downloading ${binaryName} for your platform...`);
18
- console.log("This is a one-time download.");
19
-
20
- return new Promise((resolve, reject) => {
21
- https
22
- .get(url, (response) => {
23
- if (response.statusCode === 302 || response.statusCode === 301) {
24
- // Follow redirect
25
- https
26
- .get(response.headers.location, (redirectResponse) => {
27
- if (redirectResponse.statusCode !== 200) {
28
- reject(new Error(`Failed to download: ${redirectResponse.statusCode}`));
29
- return;
30
- }
31
-
32
- const file = createWriteStream(binaryPath);
33
- redirectResponse.pipe(file);
34
-
35
- file.on("finish", () => {
36
- file.close();
37
- // Make executable on Unix
38
- if (process.platform !== "win32") {
39
- chmodSync(binaryPath, 0o755);
40
- }
41
- console.log("Download complete!");
42
- resolve();
43
- });
44
- })
45
- .on("error", reject);
46
- } else if (response.statusCode !== 200) {
47
- reject(new Error(`Failed to download: ${response.statusCode}`));
48
- } else {
49
- const file = createWriteStream(binaryPath);
50
- response.pipe(file);
51
-
52
- file.on("finish", () => {
53
- file.close();
54
- // Make executable on Unix
55
- if (process.platform !== "win32") {
56
- chmodSync(binaryPath, 0o755);
57
- }
58
- console.log("Download complete!");
59
- resolve();
60
- });
61
- }
62
- })
63
- .on("error", reject);
64
- });
6
+ let binaryPath;
7
+ try {
8
+ binaryPath = resolveBinaryPath();
9
+ } catch {
10
+ console.error(`Binary package not installed for ${process.platform}-${process.arch}.`);
11
+ process.exit(1);
65
12
  }
66
13
 
67
- // Main execution
68
- async function main() {
69
- const binaryName = getBinaryName();
70
- const binDir = join(__dirname, ".bin");
71
- const binaryPath = join(binDir, binaryName);
14
+ // Spawn the binary with all arguments
15
+ const child = spawn(binaryPath, process.argv.slice(2), {
16
+ stdio: "inherit",
17
+ windowsHide: true,
18
+ });
72
19
 
73
- // Create bin directory if it doesn't exist
74
- if (!fs.existsSync(binDir)) {
75
- fs.mkdirSync(binDir, { recursive: true });
76
- }
20
+ // Handle exit
21
+ child.on("exit", (code) => {
22
+ process.exit(code || 0);
23
+ });
77
24
 
78
- // Check if binary exists
79
- if (!fs.existsSync(binaryPath)) {
80
- try {
81
- await downloadBinary(binaryName, binaryPath);
82
- } catch (err) {
83
- console.error("Failed to download binary:", err.message);
84
- console.error("Please download manually from: https://github.com/MrLesk/Backlog.md/releases");
85
- process.exit(1);
86
- }
25
+ // Handle errors
26
+ child.on("error", (err) => {
27
+ if (err.code === "ENOENT") {
28
+ console.error(`Binary not found: ${binaryPath}`);
29
+ console.error(`Please ensure you have the correct version for your platform (${process.platform}-${process.arch})`);
30
+ } else {
31
+ console.error("Failed to start backlog:", err);
87
32
  }
88
-
89
- // Spawn the binary with all arguments
90
- const child = spawn(binaryPath, process.argv.slice(2), {
91
- stdio: "inherit",
92
- windowsHide: true,
93
- });
94
-
95
- // Handle exit
96
- child.on("exit", (code) => {
97
- process.exit(code || 0);
98
- });
99
-
100
- // Handle errors
101
- child.on("error", (err) => {
102
- if (err.code === "ENOENT") {
103
- console.error(`Binary not found: ${binaryPath}`);
104
- console.error(`Please delete ${binDir} and try again.`);
105
- } else {
106
- console.error("Failed to start backlog:", err);
107
- }
108
- process.exit(1);
109
- });
110
- }
111
-
112
- main().catch((err) => {
113
- console.error(err);
114
33
  process.exit(1);
115
34
  });
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "backlog.md",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "bin": {
5
5
  "backlog": "cli.js"
6
6
  },
7
+ "optionalDependencies": {
8
+ "backlog.md-linux-x64": "*",
9
+ "backlog.md-linux-arm64": "*",
10
+ "backlog.md-darwin-x64": "*",
11
+ "backlog.md-darwin-arm64": "*",
12
+ "backlog.md-windows-x64": "*"
13
+ },
7
14
  "scripts": {
8
15
  "test": "bun test",
9
16
  "format": "biome format --write .",
@@ -44,7 +51,7 @@
44
51
  ],
45
52
  "files": [
46
53
  "cli.js",
47
- "getBinaryName.cjs",
54
+ "resolveBinary.cjs",
48
55
  "package.json",
49
56
  "README.md",
50
57
  "LICENSE"
@@ -0,0 +1,33 @@
1
+ function mapPlatform(platform = process.platform) {
2
+ switch (platform) {
3
+ case "win32":
4
+ return "windows";
5
+ case "darwin":
6
+ case "linux":
7
+ return platform;
8
+ default:
9
+ return platform;
10
+ }
11
+ }
12
+
13
+ function mapArch(arch = process.arch) {
14
+ switch (arch) {
15
+ case "x64":
16
+ case "arm64":
17
+ return arch;
18
+ default:
19
+ return arch;
20
+ }
21
+ }
22
+
23
+ function getPackageName(platform = process.platform, arch = process.arch) {
24
+ return `backlog.md-${mapPlatform(platform)}-${mapArch(arch)}`;
25
+ }
26
+
27
+ function resolveBinaryPath(platform = process.platform, arch = process.arch) {
28
+ const packageName = getPackageName(platform, arch);
29
+ const binary = `backlog${platform === "win32" ? ".exe" : ""}`;
30
+ return require.resolve(`${packageName}/${binary}`);
31
+ }
32
+
33
+ module.exports = { getPackageName, resolveBinaryPath };
package/getBinaryName.cjs DELETED
@@ -1,39 +0,0 @@
1
- function getBinaryName(platform = process.platform, arch = process.arch) {
2
- let binaryName = "backlog-";
3
-
4
- // Map Node.js platform names to Bun target names
5
- switch (platform) {
6
- case "linux":
7
- binaryName += "bun-linux-";
8
- break;
9
- case "darwin":
10
- binaryName += "bun-darwin-";
11
- break;
12
- case "win32":
13
- binaryName += "bun-windows-";
14
- break;
15
- default:
16
- throw new Error(`Unsupported platform: ${platform}`);
17
- }
18
-
19
- // Map Node.js arch names to Bun target names
20
- switch (arch) {
21
- case "x64":
22
- binaryName += "x64";
23
- break;
24
- case "arm64":
25
- binaryName += "arm64";
26
- break;
27
- default:
28
- throw new Error(`Unsupported architecture: ${arch}`);
29
- }
30
-
31
- // Windows executables have .exe extension
32
- if (platform === "win32") {
33
- binaryName += ".exe";
34
- }
35
-
36
- return binaryName;
37
- }
38
-
39
- module.exports = { getBinaryName };