santui 0.2.11 → 0.2.13
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/index.js +37 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,7 +9,8 @@ const http = require('http');
|
|
|
9
9
|
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
|
10
10
|
const version = pkg.version;
|
|
11
11
|
const repo = 'sonyarianto/santui';
|
|
12
|
-
const
|
|
12
|
+
const isWin = process.platform === 'win32';
|
|
13
|
+
const binaryName = isWin ? 'santui.exe' : 'santui';
|
|
13
14
|
const binaryPath = path.join(__dirname, binaryName);
|
|
14
15
|
|
|
15
16
|
// ── Download helpers ──
|
|
@@ -64,30 +65,48 @@ async function downloadBinary() {
|
|
|
64
65
|
|
|
65
66
|
if (ext === 'zip') {
|
|
66
67
|
execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}' -Force"`, { stdio: 'pipe' });
|
|
67
|
-
const files = fs.readdirSync(tmpDir);
|
|
68
|
-
const exeFile = files.find(f => f.endsWith('.exe'));
|
|
69
|
-
if (!exeFile) throw new Error('santui.exe not found in archive');
|
|
70
|
-
fs.copyFileSync(path.join(tmpDir, exeFile), binaryPath);
|
|
71
68
|
} else {
|
|
72
69
|
execSync(`tar xzf '${archivePath}' -C '${tmpDir}'`, { stdio: 'pipe' });
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Determine extracted root (some archives wrap in a top-level folder)
|
|
73
|
+
const entries = fs.readdirSync(tmpDir).filter(e => e !== path.basename(archivePath));
|
|
74
|
+
let extractedRoot = tmpDir;
|
|
75
|
+
if (entries.length === 1 && fs.statSync(path.join(tmpDir, entries[0])).isDirectory()) {
|
|
76
|
+
extractedRoot = path.join(tmpDir, entries[0]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Validate main binary exists
|
|
80
|
+
if (!fs.existsSync(path.join(extractedRoot, binaryName))) {
|
|
81
|
+
throw new Error(`${binaryName} not found in archive`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Copy all extracted files (binaries + native deps) to package directory
|
|
85
|
+
for (const item of fs.readdirSync(extractedRoot)) {
|
|
86
|
+
const src = path.join(extractedRoot, item);
|
|
87
|
+
const dest = path.join(__dirname, item);
|
|
88
|
+
const stat = fs.statSync(src);
|
|
89
|
+
if (stat.isDirectory()) {
|
|
90
|
+
if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true, force: true });
|
|
91
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
92
|
+
for (const f of fs.readdirSync(src)) {
|
|
93
|
+
fs.copyFileSync(path.join(src, f), path.join(dest, f));
|
|
94
|
+
}
|
|
76
95
|
} else {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
fs.copyFileSync(src, dest);
|
|
97
|
+
if (!isWin) fs.chmodSync(dest, 0o755);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!isWin) {
|
|
102
|
+
// Ensure all plugin binaries are executable
|
|
103
|
+
for (const bin of fs.readdirSync(__dirname)) {
|
|
104
|
+
if (bin.startsWith('santui') && !bin.endsWith('.js') && !bin.endsWith('.json') && !bin.endsWith('.md')) {
|
|
105
|
+
fs.chmodSync(path.join(__dirname, bin), 0o755);
|
|
85
106
|
}
|
|
86
|
-
if (!found) throw new Error(`${binaryName} not found in archive`);
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
109
|
|
|
90
|
-
if (process.platform !== 'win32') execSync(`chmod +x '${binaryPath}'`, { stdio: 'pipe' });
|
|
91
110
|
console.error('');
|
|
92
111
|
console.error(' ✅ Santui v' + version + ' ready!');
|
|
93
112
|
console.error(' Type "santui" to launch your terminal home base.');
|