@oatnil/ud 0.33.0 → 0.49.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @oatnil/ud
2
2
 
3
- UnderControl CLI - task and expense management from the terminal.
3
+ UnDercontrol CLI - task and expense management from the terminal.
4
4
 
5
5
  ## Install
6
6
 
Binary file
Binary file
Binary file
Binary file
Binary file
package/install.js CHANGED
@@ -1,13 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const https = require("https");
4
3
  const fs = require("fs");
5
4
  const path = require("path");
6
- const { execSync } = require("child_process");
7
- const zlib = require("zlib");
8
-
9
- const CDN_BASE =
10
- "https://pub-35d77f83ee8a41798bb4b2e1831ac70a.r2.dev/cli/releases";
11
5
 
12
6
  const PLATFORM_MAP = {
13
7
  darwin: "darwin",
@@ -20,98 +14,7 @@ const ARCH_MAP = {
20
14
  arm64: "arm64",
21
15
  };
22
16
 
23
- function getBinaryName(version, goos, goarch) {
24
- const name = `ud_${version}_${goos}_${goarch}`;
25
- return goos === "windows" ? `${name}.exe` : name;
26
- }
27
-
28
- function getArchiveName(version, goos, goarch) {
29
- const base = `ud_${version}_${goos}_${goarch}`;
30
- return goos === "windows" ? `${base}.zip` : `${base}.tar.gz`;
31
- }
32
-
33
- function fetch(url) {
34
- return new Promise((resolve, reject) => {
35
- https
36
- .get(url, (res) => {
37
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
38
- return fetch(res.headers.location).then(resolve, reject);
39
- }
40
- if (res.statusCode !== 200) {
41
- return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
42
- }
43
- const chunks = [];
44
- res.on("data", (chunk) => chunks.push(chunk));
45
- res.on("end", () => resolve(Buffer.concat(chunks)));
46
- res.on("error", reject);
47
- })
48
- .on("error", reject);
49
- });
50
- }
51
-
52
- function extractTarGz(buffer, binaryName, destPath) {
53
- // tar.gz: use tar command for simplicity
54
- const tmpDir = path.join(path.dirname(destPath), ".ud-tmp");
55
- fs.mkdirSync(tmpDir, { recursive: true });
56
-
57
- const archivePath = path.join(tmpDir, "archive.tar.gz");
58
- fs.writeFileSync(archivePath, buffer);
59
-
60
- try {
61
- execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "pipe" });
62
-
63
- const extractedBinary = path.join(tmpDir, binaryName);
64
- if (!fs.existsSync(extractedBinary)) {
65
- // try finding any file in tmpDir
66
- const files = fs.readdirSync(tmpDir).filter((f) => f !== "archive.tar.gz");
67
- if (files.length === 0) {
68
- throw new Error(`No binary found in archive`);
69
- }
70
- fs.renameSync(path.join(tmpDir, files[0]), destPath);
71
- } else {
72
- fs.renameSync(extractedBinary, destPath);
73
- }
74
- } finally {
75
- fs.rmSync(tmpDir, { recursive: true, force: true });
76
- }
77
- }
78
-
79
- function extractZip(buffer, binaryName, destPath) {
80
- const tmpDir = path.join(path.dirname(destPath), ".ud-tmp");
81
- fs.mkdirSync(tmpDir, { recursive: true });
82
-
83
- const archivePath = path.join(tmpDir, "archive.zip");
84
- fs.writeFileSync(archivePath, buffer);
85
-
86
- try {
87
- // Use PowerShell on Windows, unzip on others
88
- if (process.platform === "win32") {
89
- execSync(
90
- `powershell -command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
91
- { stdio: "pipe" }
92
- );
93
- } else {
94
- execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`, { stdio: "pipe" });
95
- }
96
-
97
- const extractedBinary = path.join(tmpDir, binaryName);
98
- if (!fs.existsSync(extractedBinary)) {
99
- const files = fs
100
- .readdirSync(tmpDir)
101
- .filter((f) => f !== "archive.zip");
102
- if (files.length === 0) {
103
- throw new Error(`No binary found in archive`);
104
- }
105
- fs.renameSync(path.join(tmpDir, files[0]), destPath);
106
- } else {
107
- fs.renameSync(extractedBinary, destPath);
108
- }
109
- } finally {
110
- fs.rmSync(tmpDir, { recursive: true, force: true });
111
- }
112
- }
113
-
114
- async function main() {
17
+ function main() {
115
18
  const pkg = require("./package.json");
116
19
  const version = pkg.version;
117
20
 
@@ -128,43 +31,48 @@ async function main() {
128
31
  }
129
32
 
130
33
  const binDir = path.join(__dirname, "bin");
131
- fs.mkdirSync(binDir, { recursive: true });
132
-
133
34
  const binaryExt = goos === "windows" ? ".exe" : "";
134
35
  const destPath = path.join(binDir, `ud${binaryExt}`);
135
36
 
136
- // Skip if binary already exists
37
+ // Skip if already set up
137
38
  if (fs.existsSync(destPath)) {
138
- console.log(`ud binary already exists at ${destPath}`);
139
39
  return;
140
40
  }
141
41
 
142
- const archiveName = getArchiveName(version, goos, goarch);
143
- const binaryName = getBinaryName(version, goos, goarch);
144
- const url = `${CDN_BASE}/${version}/${archiveName}`;
145
-
146
- console.log(`Downloading ud v${version} for ${goos}/${goarch}...`);
147
- console.log(` ${url}`);
42
+ // Find the matching bundled binary
43
+ const binaryName = `ud_${version}_${goos}_${goarch}${binaryExt}`;
44
+ const sourcePath = path.join(binDir, binaryName);
45
+
46
+ if (!fs.existsSync(sourcePath)) {
47
+ console.error(
48
+ `Binary not found for ${process.platform}/${process.arch}: ${binaryName}`
49
+ );
50
+ console.error(`Available binaries in ${binDir}:`);
51
+ if (fs.existsSync(binDir)) {
52
+ fs.readdirSync(binDir).forEach((f) => console.error(` ${f}`));
53
+ }
54
+ process.exit(1);
55
+ }
148
56
 
149
- try {
150
- const buffer = await fetch(url);
57
+ // Rename the matching binary to 'ud'
58
+ fs.renameSync(sourcePath, destPath);
151
59
 
152
- if (archiveName.endsWith(".zip")) {
153
- extractZip(buffer, binaryName, destPath);
154
- } else {
155
- extractTarGz(buffer, binaryName, destPath);
156
- }
60
+ // Make executable on unix
61
+ if (goos !== "windows") {
62
+ fs.chmodSync(destPath, 0o755);
63
+ }
157
64
 
158
- // Make executable
159
- if (goos !== "windows") {
160
- fs.chmodSync(destPath, 0o755);
65
+ // Clean up other platform binaries
66
+ if (fs.existsSync(binDir)) {
67
+ for (const file of fs.readdirSync(binDir)) {
68
+ const filePath = path.join(binDir, file);
69
+ if (filePath !== destPath) {
70
+ fs.unlinkSync(filePath);
71
+ }
161
72
  }
162
-
163
- console.log(`ud v${version} installed successfully!`);
164
- } catch (err) {
165
- console.error(`Failed to install ud: ${err.message}`);
166
- process.exit(1);
167
73
  }
74
+
75
+ console.log(`ud v${version} installed for ${goos}/${goarch}`);
168
76
  }
169
77
 
170
78
  main();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oatnil/ud",
3
- "version": "0.33.0",
4
- "description": "UnderControl CLI - task and expense management from the terminal",
3
+ "version": "0.49.2",
4
+ "description": "UnDercontrol CLI - task and expense management from the terminal",
5
5
  "homepage": "https://github.com/oatnil-top/ud",
6
6
  "repository": {
7
7
  "type": "git",
@@ -33,6 +33,7 @@
33
33
  "files": [
34
34
  "install.js",
35
35
  "run.js",
36
+ "bin/",
36
37
  "README.md"
37
38
  ]
38
39
  }