backlog.md 0.1.15 → 0.1.17
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 +142 -132
- package/package.json +1 -2
package/cli.js
CHANGED
|
@@ -1,147 +1,157 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { spawn } = require(
|
|
4
|
-
const { join } = require(
|
|
5
|
-
const fs = require(
|
|
6
|
-
const https = require(
|
|
7
|
-
const { createWriteStream, chmodSync } = require(
|
|
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");
|
|
8
8
|
|
|
9
9
|
// Determine the correct binary based on platform and architecture
|
|
10
10
|
function getBinaryName() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
11
|
+
const platform = process.platform;
|
|
12
|
+
const arch = process.arch;
|
|
13
|
+
|
|
14
|
+
let binaryName = "backlog-";
|
|
15
|
+
|
|
16
|
+
// Map Node.js platform names to Bun target names
|
|
17
|
+
switch (platform) {
|
|
18
|
+
case "linux":
|
|
19
|
+
binaryName += "bun-linux-";
|
|
20
|
+
break;
|
|
21
|
+
case "darwin":
|
|
22
|
+
binaryName += "bun-darwin-";
|
|
23
|
+
break;
|
|
24
|
+
case "win32":
|
|
25
|
+
binaryName += "bun-windows-";
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
console.error(`Unsupported platform: ${platform}`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Map Node.js arch names to Bun target names
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case "x64":
|
|
35
|
+
binaryName += "x64";
|
|
36
|
+
break;
|
|
37
|
+
case "arm64":
|
|
38
|
+
binaryName += "arm64";
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
console.error(`Unsupported architecture: ${arch}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Windows executables have .exe extension
|
|
46
|
+
if (platform === "win32") {
|
|
47
|
+
binaryName += ".exe";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return binaryName;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Download binary from GitHub releases
|
|
54
54
|
async function downloadBinary(binaryName, binaryPath) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
55
|
+
const packageJson = require(join(__dirname, "package.json"));
|
|
56
|
+
const version = packageJson.version;
|
|
57
|
+
const url = `https://github.com/MrLesk/Backlog.md/releases/download/v${version}/${binaryName}`;
|
|
58
|
+
|
|
59
|
+
console.log(`Downloading ${binaryName} for your platform...`);
|
|
60
|
+
console.log("This is a one-time download.");
|
|
61
|
+
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
https
|
|
64
|
+
.get(url, (response) => {
|
|
65
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
66
|
+
// Follow redirect
|
|
67
|
+
https
|
|
68
|
+
.get(response.headers.location, (redirectResponse) => {
|
|
69
|
+
if (redirectResponse.statusCode !== 200) {
|
|
70
|
+
reject(new Error(`Failed to download: ${redirectResponse.statusCode}`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const file = createWriteStream(binaryPath);
|
|
75
|
+
redirectResponse.pipe(file);
|
|
76
|
+
|
|
77
|
+
file.on("finish", () => {
|
|
78
|
+
file.close();
|
|
79
|
+
// Make executable on Unix
|
|
80
|
+
if (process.platform !== 'win32') {
|
|
81
|
+
chmodSync(binaryPath, 0o755);
|
|
82
|
+
}
|
|
83
|
+
console.log("Download complete!");
|
|
84
|
+
resolve();
|
|
85
|
+
});
|
|
86
|
+
})
|
|
87
|
+
.on("error", reject);
|
|
88
|
+
} else if (response.statusCode !== 200) {
|
|
89
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
90
|
+
} else {
|
|
91
|
+
const file = createWriteStream(binaryPath);
|
|
92
|
+
response.pipe(file);
|
|
93
|
+
|
|
94
|
+
file.on("finish", () => {
|
|
95
|
+
file.close();
|
|
96
|
+
// Make executable on Unix
|
|
97
|
+
if (process.platform !== 'win32') {
|
|
98
|
+
chmodSync(binaryPath, 0o755);
|
|
99
|
+
}
|
|
100
|
+
console.log("Download complete!");
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.on("error", reject);
|
|
106
|
+
});
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
// Main execution
|
|
100
110
|
async function main() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
const binaryName = getBinaryName();
|
|
112
|
+
const binDir = join(__dirname, ".bin");
|
|
113
|
+
const binaryPath = join(binDir, binaryName);
|
|
114
|
+
|
|
115
|
+
// Create bin directory if it doesn't exist
|
|
116
|
+
if (!fs.existsSync(binDir)) {
|
|
117
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check if binary exists
|
|
121
|
+
if (!fs.existsSync(binaryPath)) {
|
|
122
|
+
try {
|
|
123
|
+
await downloadBinary(binaryName, binaryPath);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error("Failed to download binary:", err.message);
|
|
126
|
+
console.error("Please download manually from: https://github.com/MrLesk/Backlog.md/releases");
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Spawn the binary with all arguments
|
|
132
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
133
|
+
stdio: "inherit",
|
|
134
|
+
windowsHide: true,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Handle exit
|
|
138
|
+
child.on("exit", (code) => {
|
|
139
|
+
process.exit(code || 0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Handle errors
|
|
143
|
+
child.on("error", (err) => {
|
|
144
|
+
if (err.code === "ENOENT") {
|
|
145
|
+
console.error(`Binary not found: ${binaryPath}`);
|
|
146
|
+
console.error(`Please delete ${binDir} and try again.`);
|
|
147
|
+
} else {
|
|
148
|
+
console.error("Failed to start backlog:", err);
|
|
149
|
+
}
|
|
150
|
+
process.exit(1);
|
|
151
|
+
});
|
|
142
152
|
}
|
|
143
153
|
|
|
144
|
-
main().catch(err => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
154
|
+
main().catch((err) => {
|
|
155
|
+
console.error(err);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|