satoridb 1.1.1 → 1.1.3

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/package.json +1 -1
  2. package/postinstall.js +114 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoridb",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Install satori",
5
5
  "bin" : {
6
6
  "satori" : "cli.js"
package/postinstall.js CHANGED
@@ -15,63 +15,160 @@ if (platform === "linux") fileName = "lin/satori-linux.zip";
15
15
  else if (platform === "darwin") fileName = "mac/satori-mac.zip";
16
16
  else if (platform === "win32") fileName = "win/satori-win.zip";
17
17
  else {
18
- console.error("❌ Plataforma no soportada:", platform);
18
+ console.error("❌ Not supported platform:", platform);
19
19
  process.exit(1);
20
20
  }
21
21
 
22
22
  const tmpDir = path.join(os.tmpdir(), "satori-temp");
23
- fs.mkdirSync(tmpDir, { recursive: true });
24
-
25
23
  const zipPath = path.join(tmpDir, fileName);
26
24
  const installDir = path.join(os.homedir(), ".satori", "bin");
27
25
  const binName = platform === "win32" ? "satori.exe" : "satori";
28
26
  const binFullPath = path.join(installDir, binName);
29
27
 
30
- // Descargar ZIP
28
+ console.log(`📁 Temp directory: ${tmpDir}`);
29
+ console.log(`📁 Install directory: ${installDir}`);
30
+ console.log(`📁 Zip path: ${zipPath}`);
31
+
32
+ // Crear directorio temporal y subdirectorios con mejor manejo de errores
33
+ try {
34
+ fs.mkdirSync(tmpDir, { recursive: true });
35
+ console.log(`✅ Temp directory created/verified`);
36
+
37
+ // Crear el subdirectorio específico de la plataforma si es necesario
38
+ const platformSubDir = path.dirname(zipPath);
39
+ if (platformSubDir !== tmpDir) {
40
+ fs.mkdirSync(platformSubDir, { recursive: true });
41
+ console.log(`✅ Platform subdirectory created: ${platformSubDir}`);
42
+ }
43
+ } catch (err) {
44
+ console.error("❌ Error creating directories:", err.message);
45
+ process.exit(1);
46
+ }
47
+
48
+ // Descargar ZIP con mejor manejo de errores
31
49
  function downloadZip(url, dest, cb) {
50
+ console.log(`🔽 Downloading from: ${url}`);
51
+
32
52
  const file = fs.createWriteStream(dest);
33
- https.get(url, response => {
53
+
54
+ const request = https.get(url, response => {
55
+ console.log(`📡 Response status: ${response.statusCode}`);
56
+
34
57
  if (response.statusCode !== 200) {
35
- console.error("❌ Fallo al descargar el binario:", response.statusCode);
58
+ console.error("❌ Download failed:", response.statusCode);
59
+ file.close();
60
+ fs.unlink(dest, () => {}); // Limpiar archivo parcial
36
61
  process.exit(1);
37
62
  }
38
63
 
39
64
  response.pipe(file);
65
+
40
66
  file.on("finish", () => {
41
- file.close(cb);
67
+ file.close(() => {
68
+ console.log(`✅ Download completed: ${dest}`);
69
+ // Verificar que el archivo existe y tiene contenido
70
+ try {
71
+ const stats = fs.statSync(dest);
72
+ console.log(`📊 File size: ${stats.size} bytes`);
73
+ if (stats.size === 0) {
74
+ console.error("❌ Downloaded file is empty");
75
+ fs.unlink(dest, () => {});
76
+ process.exit(1);
77
+ }
78
+ cb();
79
+ } catch (err) {
80
+ console.error("❌ Error verifying downloaded file:", err.message);
81
+ process.exit(1);
82
+ }
83
+ });
42
84
  });
43
- }).on('error', err => {
44
- console.error("❌ Error de red:", err.message);
85
+
86
+ file.on("error", err => {
87
+ console.error("❌ Error writing file:", err.message);
88
+ fs.unlink(dest, () => {});
89
+ process.exit(1);
90
+ });
91
+ });
92
+
93
+ request.on('error', err => {
94
+ console.error("❌ Network error:", err.message);
95
+ file.close();
96
+ fs.unlink(dest, () => {});
97
+ process.exit(1);
98
+ });
99
+
100
+ request.setTimeout(30000, () => {
101
+ console.error("❌ Download timeout");
102
+ request.destroy();
103
+ file.close();
104
+ fs.unlink(dest, () => {});
45
105
  process.exit(1);
46
106
  });
47
107
  }
48
108
 
49
- // Extraer ZIP
109
+ // Extraer ZIP con mejor manejo de errores
50
110
  function extractZip(src, dest) {
111
+ console.log(`📦 Extracting from: ${src}`);
112
+ console.log(`📦 Extracting to: ${dest}`);
113
+
51
114
  try {
115
+ // Verificar que el archivo ZIP existe
116
+ if (!fs.existsSync(src)) {
117
+ console.error(`❌ ZIP file not found: ${src}`);
118
+ process.exit(1);
119
+ }
120
+
52
121
  const zip = new AdmZip(src);
53
122
  zip.extractAllTo(dest, true);
54
- if (platform !== "win32") chmodSync(path.join(dest, binName), 0o755);
123
+
124
+ // Verificar que el binario fue extraído
125
+ const binPath = path.join(dest, binName);
126
+ if (!fs.existsSync(binPath)) {
127
+ console.error(`❌ Binary not found after extraction: ${binPath}`);
128
+ process.exit(1);
129
+ }
130
+
131
+ if (platform !== "win32") {
132
+ chmodSync(binPath, 0o755);
133
+ console.log(`✅ Set executable permissions on: ${binPath}`);
134
+ }
135
+
136
+ console.log(`✅ Extraction completed`);
55
137
  } catch (err) {
56
- console.error("❌ Error al extraer el zip:", err.message);
138
+ console.error("❌ Error extracting zip:", err.message);
57
139
  process.exit(1);
58
140
  }
59
141
  }
60
142
 
61
143
  // Ejecutar
62
- console.log(`🔽 Descargando Satori para ${platform}/${arch}...`);
144
+ console.log(`🔽 Downloading Satori ${platform}/${arch}...`);
63
145
 
64
146
  downloadZip(`${baseURL}/${fileName}`, zipPath, () => {
65
- fs.mkdirSync(installDir, { recursive: true });
147
+ try {
148
+ fs.mkdirSync(installDir, { recursive: true });
149
+ console.log(`✅ Install directory created/verified`);
150
+ } catch (err) {
151
+ console.error("❌ Error creating install directory:", err.message);
152
+ process.exit(1);
153
+ }
154
+
66
155
  extractZip(zipPath, installDir);
67
- console.log(`✅ Binario instalado en: ${binFullPath}\n`);
156
+ console.log(`✅ Binary installed in: ${binFullPath}\n`);
157
+
158
+ // Limpiar archivo temporal
159
+ try {
160
+ fs.unlinkSync(zipPath);
161
+ console.log(`🧹 Cleaned up temporary file: ${zipPath}`);
162
+ } catch (err) {
163
+ console.warn(`⚠️ Could not clean up temporary file: ${err.message}`);
164
+ }
68
165
 
69
166
  const shell = process.env.SHELL || "";
70
167
  const profileFile = shell.includes("zsh") ? ".zshrc" : ".bashrc";
71
168
 
72
169
  const exportLine = `export PATH="$HOME/.satori/bin:$PATH"`;
73
170
 
74
- console.log(`💡 Añade esto a tu ~/${profileFile}:\n`);
171
+ console.log(`💡 Add this to your ~/${profileFile}:\n`);
75
172
  console.log(` ${exportLine}\n`);
76
- console.log(`Luego ejecuta: source ~/${profileFile}\n`);
173
+ console.log(`Then run: source ~/${profileFile}\n`);
77
174
  });