satoridb 1.1.0

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 (3) hide show
  1. package/cli.js +30 -0
  2. package/package.json +16 -0
  3. package/postinstall.js +62 -0
package/cli.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const os = require("os");
5
+ const fs = require("fs");
6
+ const { spawnSync } = require("child_process");
7
+
8
+ const binName = os.platform() === "win32" ? "satori.exe" : "satori";
9
+ const binPath = path.join(os.homedir(), ".satori", "bin", binName);
10
+
11
+ function run(args) {
12
+ if (!fs.existsSync(binPath)) {
13
+ console.error("❌ Satori no está instalado. Intenta reinstalar el paquete.");
14
+ process.exit(1);
15
+ }
16
+
17
+ const result = spawnSync(binPath, args, { stdio: "inherit" });
18
+ if (result.error) {
19
+ console.error("❌ Error ejecutando:", result.error.message);
20
+ process.exit(1);
21
+ }
22
+ }
23
+
24
+ const args = process.argv.slice(2);
25
+ if (args[0] === "update") {
26
+ console.log("🔄 Ejecutando actualización...");
27
+ require("./postinstall");
28
+ } else {
29
+ run(args);
30
+ }
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "satoridb",
3
+ "version": "1.1.0",
4
+ "description": "Install satori",
5
+ "bin" : {
6
+ "satori" : "cli.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall" : "node postinstall.js"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "adm-zip": "^0.5.16"
15
+ }
16
+ }
package/postinstall.js ADDED
@@ -0,0 +1,62 @@
1
+ const os = require("os");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const https = require("https");
5
+ const AdmZip = require("adm-zip");
6
+ const { chmodSync } = require("fs");
7
+
8
+ const platform = os.platform();
9
+ const arch = os.arch();
10
+
11
+ const baseURL = "https://www.satoridb.com/";
12
+ let fileName;
13
+
14
+ if (platform === "linux") fileName = "lin/satori-linux.zip";
15
+ else if (platform === "darwin") fileName = "mac/satori-mac.zip";
16
+ else if (platform === "win32") fileName = "win/satori-win.zip";
17
+ else {
18
+ console.error("❌ Plataforma no soportada:", platform);
19
+ process.exit(1);
20
+ }
21
+
22
+ const installDir = path.join(os.homedir(), ".satori", "bin");
23
+ const zipPath = path.join(os.tmpdir(), fileName);
24
+ const binName = platform === "win32" ? "satori.exe" : "satori";
25
+ const binFullPath = path.join(installDir, binName);
26
+
27
+ // Descargar ZIP
28
+ function downloadZip(url, dest, cb) {
29
+ const file = fs.createWriteStream(dest);
30
+ https.get(url, response => {
31
+ if (response.statusCode !== 200) {
32
+ console.error("❌ Fallo al descargar el binario:", response.statusCode);
33
+ process.exit(1);
34
+ }
35
+ response.pipe(file);
36
+ file.on("finish", () => {
37
+ file.close(cb);
38
+ });
39
+ });
40
+ }
41
+
42
+ // Extraer ZIP
43
+ function extractZip(src, dest) {
44
+ const zip = new AdmZip(src);
45
+ zip.extractAllTo(dest, true);
46
+ if (platform !== "win32") chmodSync(path.join(dest, binName), 0o755);
47
+ }
48
+
49
+ // Iniciar
50
+ console.log("🔽 Descargando Satori...");
51
+ downloadZip(`${baseURL}/${fileName}`, zipPath, () => {
52
+ fs.mkdirSync(installDir, { recursive: true });
53
+ extractZip(zipPath, installDir);
54
+ console.log(`✅ Binario instalado en: ${binFullPath}`);
55
+
56
+ const shell = process.env.SHELL || "";
57
+ const profileFile = shell.includes("zsh") ? ".zshrc" : ".bashrc";
58
+
59
+ console.log(`💡 Añade esto a tu ~/.${profileFile} si no lo tienes aún:\n`);
60
+ console.log(` export PATH="$HOME/.satori/bin:$PATH"\n`);
61
+ console.log("Luego ejecuta: source ~/" + profileFile);
62
+ });