automagik-forge 0.1.10 → 0.1.12

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/bin/cli.js +69 -6
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -3,6 +3,52 @@
3
3
  const { execSync, spawn } = require("child_process");
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
+ const zlib = require("zlib");
7
+
8
+ // Fallback ZIP extraction using Node.js when unzip is not available
9
+ function extractZipWithNode(zipPath, extractDir) {
10
+ const buffer = fs.readFileSync(zipPath);
11
+ let offset = 0;
12
+
13
+ // Simple ZIP parser - look for file entries
14
+ while (offset < buffer.length - 30) {
15
+ // Look for local file header signature (0x04034b50)
16
+ if (buffer.readUInt32LE(offset) === 0x04034b50) {
17
+ const filenameLength = buffer.readUInt16LE(offset + 26);
18
+ const extraFieldLength = buffer.readUInt16LE(offset + 28);
19
+ const compressedSize = buffer.readUInt32LE(offset + 18);
20
+ const uncompressedSize = buffer.readUInt32LE(offset + 22);
21
+ const compressionMethod = buffer.readUInt16LE(offset + 8);
22
+
23
+ offset += 30; // Skip local file header
24
+
25
+ const filename = buffer.toString('utf8', offset, offset + filenameLength);
26
+ offset += filenameLength + extraFieldLength;
27
+
28
+ const fileData = buffer.slice(offset, offset + compressedSize);
29
+ offset += compressedSize;
30
+
31
+ // Skip directories
32
+ if (filename.endsWith('/')) continue;
33
+
34
+ const outputPath = path.join(extractDir, filename);
35
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
36
+
37
+ if (compressionMethod === 0) {
38
+ // No compression
39
+ fs.writeFileSync(outputPath, fileData);
40
+ } else if (compressionMethod === 8) {
41
+ // Deflate compression
42
+ const decompressed = zlib.inflateRawSync(fileData);
43
+ fs.writeFileSync(outputPath, decompressed);
44
+ } else {
45
+ throw new Error(`Unsupported compression method: ${compressionMethod}`);
46
+ }
47
+ } else {
48
+ offset++;
49
+ }
50
+ }
51
+ }
6
52
 
7
53
  // Load .env file from current working directory
8
54
  function loadEnvFile() {
@@ -105,12 +151,29 @@ function extractAndRun(baseName, launch) {
105
151
  process.exit(1);
106
152
  }
107
153
 
108
- // extract
109
- const unzipCmd =
110
- platform === "win32"
111
- ? `powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`
112
- : `unzip -qq -o "${zipPath}" -d "${extractDir}"`;
113
- execSync(unzipCmd, { stdio: "inherit" });
154
+ // extract with fallback methods
155
+ if (platform === "win32") {
156
+ const unzipCmd = `powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`;
157
+ execSync(unzipCmd, { stdio: "inherit" });
158
+ } else {
159
+ // Try unzip first, fallback to Node.js extraction if not available
160
+ try {
161
+ execSync(`unzip -qq -o "${zipPath}" -d "${extractDir}"`, { stdio: "inherit" });
162
+ } catch (unzipError) {
163
+ console.log("⚠️ unzip not found, using Node.js extraction...");
164
+ try {
165
+ // Fallback to Node.js extraction using yauzl if available, or basic implementation
166
+ extractZipWithNode(zipPath, extractDir);
167
+ } catch (nodeError) {
168
+ console.error("❌ Extraction failed. Please install unzip:");
169
+ console.error(" Ubuntu/Debian: sudo apt-get install unzip");
170
+ console.error(" RHEL/CentOS: sudo yum install unzip");
171
+ console.error(" Alpine: apk add unzip");
172
+ console.error("\nOriginal error:", unzipError.message);
173
+ process.exit(1);
174
+ }
175
+ }
176
+ }
114
177
 
115
178
  // perms & launch
116
179
  if (platform !== "win32") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "automagik-forge",
3
3
  "private": false,
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "automagik-forge": "bin/cli.js"