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.
Files changed (2) hide show
  1. package/cli.js +142 -132
  2. 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('child_process');
4
- const { join } = require('path');
5
- const fs = require('fs');
6
- const https = require('https');
7
- const { createWriteStream, chmodSync } = require('fs');
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
- 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;
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
- 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.get(url, (response) => {
64
- if (response.statusCode === 302 || response.statusCode === 301) {
65
- // Follow redirect
66
- https.get(response.headers.location, (redirectResponse) => {
67
- if (redirectResponse.statusCode !== 200) {
68
- reject(new Error(`Failed to download: ${redirectResponse.statusCode}`));
69
- return;
70
- }
71
-
72
- const file = createWriteStream(binaryPath);
73
- redirectResponse.pipe(file);
74
-
75
- file.on('finish', () => {
76
- file.close();
77
- chmodSync(binaryPath, 0o755);
78
- console.log('Download complete!');
79
- resolve();
80
- });
81
- }).on('error', reject);
82
- } else if (response.statusCode !== 200) {
83
- reject(new Error(`Failed to download: ${response.statusCode}`));
84
- } else {
85
- const file = createWriteStream(binaryPath);
86
- response.pipe(file);
87
-
88
- file.on('finish', () => {
89
- file.close();
90
- chmodSync(binaryPath, 0o755);
91
- console.log('Download complete!');
92
- resolve();
93
- });
94
- }
95
- }).on('error', reject);
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
- const binaryName = getBinaryName();
102
- const binDir = join(__dirname, '.bin');
103
- const binaryPath = join(binDir, binaryName);
104
-
105
- // Create bin directory if it doesn't exist
106
- if (!fs.existsSync(binDir)) {
107
- fs.mkdirSync(binDir, { recursive: true });
108
- }
109
-
110
- // Check if binary exists
111
- if (!fs.existsSync(binaryPath)) {
112
- try {
113
- await downloadBinary(binaryName, binaryPath);
114
- } catch (err) {
115
- console.error('Failed to download binary:', err.message);
116
- console.error(`Please download manually from: https://github.com/MrLesk/Backlog.md/releases`);
117
- process.exit(1);
118
- }
119
- }
120
-
121
- // Spawn the binary with all arguments
122
- const child = spawn(binaryPath, process.argv.slice(2), {
123
- stdio: 'inherit',
124
- windowsHide: true
125
- });
126
-
127
- // Handle exit
128
- child.on('exit', (code) => {
129
- process.exit(code || 0);
130
- });
131
-
132
- // Handle errors
133
- child.on('error', (err) => {
134
- if (err.code === 'ENOENT') {
135
- console.error(`Binary not found: ${binaryPath}`);
136
- console.error(`Please delete ${binDir} and try again.`);
137
- } else {
138
- console.error('Failed to start backlog:', err);
139
- }
140
- process.exit(1);
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
- console.error(err);
146
- process.exit(1);
147
- });
154
+ main().catch((err) => {
155
+ console.error(err);
156
+ process.exit(1);
157
+ });
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "backlog.md",
3
- "version": "0.1.15",
4
- "type": "module",
3
+ "version": "0.1.17",
5
4
  "bin": {
6
5
  "backlog": "cli.js"
7
6
  },