xypriss 9.0.0 → 9.0.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/package.json CHANGED
@@ -264,7 +264,7 @@
264
264
  "build:memory": "NODE_OPTIONS='--max-old-space-size=6144' npx rollup -c rollup.config.js",
265
265
  "install-memory-cli": "node scripts/install-memory-cli.js",
266
266
  "install-xsys": "node scripts/postinstall-xsys.js",
267
- "postinstall": "node scripts/postinstall-xsys.js && node scripts/install-xems.js && node scripts/postinstall.js",
267
+ "postinstall": "node scripts/postinstall.js",
268
268
  "prepublishOnly": "npm run build",
269
269
  "test": "jest",
270
270
  "test:coverage": "jest --coverage",
@@ -274,5 +274,6 @@
274
274
  "support": "https://github.com/Nehonix-Team/XyPriss/issues",
275
275
  "type": "module",
276
276
  "types": "dist/index.d.ts",
277
- "version": "9.0.0"
277
+ "version": "9.0.2"
278
278
  }
279
+
@@ -15,9 +15,8 @@ const __filename = fileURLToPath(import.meta.url);
15
15
  const __dirname = path.dirname(__filename);
16
16
 
17
17
  const CDN_BASE_URL = "https://dll.nehonix.com/dl/mds/xypriss/bin";
18
- // Install binary in the package's own bin directory, not user's project
19
18
  const BIN_DIR = path.join(__dirname, "..", "bin");
20
- const TIMEOUT = 40000; // 40 seconds
19
+ const TIMEOUT = 40000;
21
20
 
22
21
  /**
23
22
  * Get platform-specific binary information
@@ -26,124 +25,76 @@ function getPlatformBinary() {
26
25
  const platform = process.platform;
27
26
  const arch = process.arch;
28
27
 
29
- let binaryName;
30
- let downloadName;
31
-
28
+ let binaryTarget;
32
29
  if (platform === "win32") {
33
- binaryName =
34
- arch === "arm64"
35
- ? "memory-cli-windows-arm64.exe"
36
- : "memory-cli-windows-x64.exe";
37
- downloadName = binaryName;
30
+ binaryTarget = arch === "arm64" ? "windows-arm64" : "windows-x64";
38
31
  } else if (platform === "darwin") {
39
- binaryName =
40
- arch === "arm64"
41
- ? "memory-cli-darwin-arm64"
42
- : "memory-cli-darwin-x64";
43
- downloadName = binaryName;
32
+ binaryTarget = arch === "arm64" ? "darwin-arm64" : "darwin-x64";
44
33
  } else if (platform === "linux") {
45
- binaryName = "memory-cli-linux-x64";
46
- downloadName = binaryName;
34
+ binaryTarget = arch === "arm64" ? "linux-arm64" : "linux-x64";
47
35
  } else {
48
- console.warn(
49
- `⚠️ Unsupported platform: ${platform}-${arch}. Memory CLI will use fallback mode.`
50
- );
51
36
  return null;
52
37
  }
53
38
 
39
+ const binaryName = `memory-cli-${binaryTarget}${platform === "win32" ? ".exe" : ""}`;
40
+
54
41
  return {
55
42
  binaryName,
56
- downloadName,
57
- url: `${CDN_BASE_URL}/${downloadName}`,
43
+ url: `${CDN_BASE_URL}/${binaryName}`,
58
44
  localPath: path.join(BIN_DIR, binaryName),
59
45
  genericPath: path.join(
60
46
  BIN_DIR,
61
- "memory-cli" + (platform === "win32" ? ".exe" : "")
47
+ "memory-cli" + (platform === "win32" ? ".exe" : ""),
62
48
  ),
63
49
  };
64
50
  }
65
51
 
66
52
  /**
67
- * Download file from URL
53
+ * Download file from URL with Redirect support
68
54
  */
69
55
  function downloadFile(url, destination) {
70
56
  return new Promise((resolve, reject) => {
71
- console.log(`📥 Downloading ${url}...`);
72
-
73
57
  const file = fs.createWriteStream(destination);
74
58
  const request = https.get(url, { timeout: TIMEOUT }, (response) => {
59
+ if (
60
+ response.statusCode >= 300 &&
61
+ response.statusCode < 400 &&
62
+ response.headers.location
63
+ ) {
64
+ file.close();
65
+ fs.unlinkSync(destination);
66
+ return downloadFile(response.headers.location, destination)
67
+ .then(resolve)
68
+ .catch(reject);
69
+ }
70
+
75
71
  if (response.statusCode === 200) {
76
72
  response.pipe(file);
77
-
78
73
  file.on("finish", () => {
79
74
  file.close();
80
- console.log(`✅ Downloaded to ${destination}`);
81
75
  resolve();
82
76
  });
83
- } else if (
84
- response.statusCode === 302 ||
85
- response.statusCode === 301
86
- ) {
87
- // Handle redirects
88
- file.close();
89
- fs.unlinkSync(destination);
90
- downloadFile(response.headers.location, destination)
91
- .then(resolve)
92
- .catch(reject);
93
77
  } else {
94
78
  file.close();
95
79
  fs.unlinkSync(destination);
96
- reject(
97
- new Error(
98
- `HTTP ${response.statusCode}: ${response.statusMessage}`
99
- )
100
- );
80
+ reject(new Error(`HTTP ${response.statusCode}`));
101
81
  }
102
82
  });
103
83
 
104
84
  request.on("error", (error) => {
105
85
  file.close();
106
- if (fs.existsSync(destination)) {
107
- fs.unlinkSync(destination);
108
- }
86
+ if (fs.existsSync(destination)) fs.unlinkSync(destination);
109
87
  reject(error);
110
88
  });
111
-
112
- request.on("timeout", () => {
113
- request.destroy();
114
- file.close();
115
- if (fs.existsSync(destination)) {
116
- fs.unlinkSync(destination);
117
- }
118
- reject(new Error("Download timeout"));
119
- });
120
89
  });
121
90
  }
122
91
 
123
- /**
124
- * Make file executable (Unix-like systems)
125
- */
126
- function makeExecutable(filePath) {
127
- if (process.platform !== "win32") {
128
- try {
129
- execSync(`chmod +x "${filePath}"`);
130
- console.log(`🔧 Made ${filePath} executable`);
131
- } catch (error) {
132
- console.warn(
133
- `⚠️ Failed to make ${filePath} executable:`,
134
- error.message
135
- );
136
- }
137
- }
138
- }
139
-
140
92
  /**
141
93
  * Verify downloaded binary works
142
94
  */
143
95
  function verifyBinary(filePath) {
144
96
  return new Promise((resolve) => {
145
97
  try {
146
- // spawn is already imported at the top
147
98
  const child = spawn(filePath, ["--help"], {
148
99
  stdio: "pipe",
149
100
  timeout: 5000,
@@ -156,140 +107,74 @@ function verifyBinary(filePath) {
156
107
 
157
108
  child.on("close", (code) => {
158
109
  if (code === 0 && output.includes("XyPriss Memory Info CLI")) {
159
- console.log(`✅ Binary verification successful`);
160
110
  resolve(true);
161
111
  } else {
162
- console.warn(
163
- `⚠️ Binary verification failed (exit code: ${code})`
164
- );
165
112
  resolve(false);
166
113
  }
167
114
  });
168
115
 
169
- child.on("error", () => {
170
- resolve(false);
171
- });
116
+ child.on("error", () => resolve(false));
172
117
  } catch (error) {
173
118
  resolve(false);
174
119
  }
175
120
  });
176
121
  }
177
122
 
178
- /**
179
- * Main installation function
180
- */
181
123
  async function installMemoryCLI() {
182
- console.log("🚀 Installing XyPriss Memory CLI...");
183
-
184
- // Create bin directory if it doesn't exist
185
124
  if (!fs.existsSync(BIN_DIR)) {
186
125
  fs.mkdirSync(BIN_DIR, { recursive: true });
187
- console.log(`📁 Created bin directory: ${BIN_DIR}`);
188
126
  }
189
127
 
190
- const binaryInfo = getPlatformBinary();
191
- if (!binaryInfo) {
128
+ const info = getPlatformBinary();
129
+ if (!info) return;
130
+
131
+ console.log(`📂 Target directory: ${BIN_DIR}`);
132
+ console.log(`📦 Binary: ${info.binaryName}`);
133
+
134
+ if (fs.existsSync(info.genericPath)) {
192
135
  console.log(
193
- "⚠️ No binary available for this platform. Using fallback mode."
136
+ `✨ Memory CLI already present at ${info.genericPath}, skipping.`,
194
137
  );
195
138
  return;
196
139
  }
197
140
 
198
141
  try {
199
- // First, try to copy from development bin if it exists (for development/testing)
200
- const devBinaryPath = path.join(
201
- __dirname,
202
- "..",
203
- "bin",
204
- binaryInfo.downloadName
205
- );
206
- if (fs.existsSync(devBinaryPath)) {
207
- console.log(
208
- `📋 Copying binary from development location: ${devBinaryPath}`
209
- );
210
- fs.copyFileSync(devBinaryPath, binaryInfo.localPath);
211
- } else {
212
- // Download the binary from CDN
213
- await downloadFile(binaryInfo.url, binaryInfo.localPath);
142
+ console.log(`📥 Fetching Memory CLI from: ${info.url}`);
143
+ await downloadFile(info.url, info.localPath);
144
+
145
+ if (process.platform !== "win32") {
146
+ fs.chmodSync(info.localPath, 0o755);
214
147
  }
215
148
 
216
- // Make it executable
217
- makeExecutable(binaryInfo.localPath);
149
+ if (process.platform === "win32") {
150
+ fs.copyFileSync(info.localPath, info.genericPath);
151
+ } else {
152
+ if (fs.existsSync(info.genericPath))
153
+ fs.unlinkSync(info.genericPath);
154
+ fs.symlinkSync(path.basename(info.localPath), info.genericPath);
155
+ }
218
156
 
219
- // Create a generic symlink/copy for easier access
220
- if (!fs.existsSync(binaryInfo.genericPath)) {
221
- if (process.platform === "win32") {
222
- // On Windows, copy the file
223
- fs.copyFileSync(binaryInfo.localPath, binaryInfo.genericPath);
224
- } else {
225
- // On Unix-like systems, create a symlink
226
- fs.symlinkSync(
227
- path.basename(binaryInfo.localPath),
228
- binaryInfo.genericPath
229
- );
230
- }
157
+ const isValid = await verifyBinary(info.localPath);
158
+ if (isValid) {
231
159
  console.log(
232
- `🔗 Created generic binary link: ${binaryInfo.genericPath}`
160
+ `🎉 XyPriss MCLI installed successfully at: ${info.genericPath}`,
233
161
  );
234
- }
235
-
236
- // Verify the binary works
237
- const isValid = await verifyBinary(binaryInfo.localPath);
238
- if (!isValid) {
162
+ } else {
239
163
  console.warn(
240
- "⚠️ Binary verification failed. Memory CLI will use fallback mode."
164
+ "⚠️ MCLI verification failed, it might not work as expected.",
241
165
  );
242
- return;
243
166
  }
244
-
245
- console.log("🎉 XyPriss MCLI installed successfully!");
246
167
  } catch (error) {
247
168
  console.error("❌ Failed to install Memory CLI:", error.message);
248
- console.log("Memory CLI will use fallback mode (Node.js os module)");
249
-
250
- // Clean up partial downloads
251
- if (fs.existsSync(binaryInfo.localPath)) {
252
- try {
253
- fs.unlinkSync(binaryInfo.localPath);
254
- } catch (cleanupError) {
255
- // Ignore cleanup errors
256
- }
257
- }
258
- }
259
- }
260
-
261
- /**
262
- * Check if we should skip installation
263
- */
264
- function shouldSkipInstall() {
265
- // Skip if CI environment variable is set to avoid network calls in CI
266
- if (
267
- process.env.CI === "true" ||
268
- process.env.SKIP_BINARY_DOWNLOAD === "true"
269
- ) {
270
- console.log("Skipping binary download (CI environment detected)");
271
- return true;
272
- }
273
-
274
- // Remove if binary already exists and is valid
275
- const binaryInfo = getPlatformBinary();
276
- if (binaryInfo && fs.existsSync(binaryInfo.localPath)) {
277
- const unLinkPath = path.dirname(binaryInfo.localPath);
278
- console.log("Removing MCLI dir to download latest version...");
279
- fs.rmdirSync(unLinkPath, { recursive: true });
280
169
  }
281
-
282
- return false;
283
170
  }
284
171
 
285
- // Run installation if this script is executed directly
172
+ // Only run if this is the main module (not being imported)
286
173
  if (import.meta.url === `file://${process.argv[1]}`) {
287
- if (!shouldSkipInstall()) {
288
- installMemoryCLI().catch((error) => {
289
- console.error("💥 Installation failed:", error);
290
- process.exit(0); // Don't fail npm install if binary download fails
291
- });
292
- }
174
+ installMemoryCLI().catch((error) => {
175
+ console.error("💥 Installation failed:", error);
176
+ process.exit(0);
177
+ });
293
178
  }
294
179
 
295
180
  export { installMemoryCLI, getPlatformBinary, downloadFile, verifyBinary };
@@ -2,10 +2,10 @@
2
2
 
3
3
  /**
4
4
  * XEMS Installer Script
5
- * Downloads or builds the XEMS (XyPriss Entry Management System) binary.
5
+ * Downloads the XEMS (XyPriss Entry Management System) binary from GitHub Releases.
6
+ * Supports cross-platform: Windows, Linux, and macOS (Intel & Silicon).
6
7
  */
7
8
 
8
- import { execSync } from "child_process";
9
9
  import fs from "fs";
10
10
  import path from "path";
11
11
  import { fileURLToPath } from "url";
@@ -15,33 +15,35 @@ const __filename = fileURLToPath(import.meta.url);
15
15
  const __dirname = path.dirname(__filename);
16
16
 
17
17
  const BIN_DIR = path.join(__dirname, "..", "bin");
18
- const XEMS_REPO = "https://github.com/Nehonix-Team/XyPriss-XEMS";
18
+ const REPO = "Nehonix-Team/XyPriss-XEMS";
19
19
  const CDN_BASE_URL = "https://dll.nehonix.com/dl/mds/xems/bin"; // Fallback CDN
20
20
 
21
21
  /**
22
22
  * Get platform-specific binary information for XEMS
23
+ * Maps directly to the files in tools/XEMS/dist/
23
24
  */
24
25
  function getPlatformBinary() {
25
26
  const platform = process.platform;
26
27
  const arch = process.arch;
27
28
 
28
- let binaryName;
29
+ let binaryTarget;
29
30
  if (platform === "win32") {
30
- binaryName =
31
- arch === "arm64"
32
- ? "xems-windows-arm64.exe"
33
- : "xems-windows-x64.exe";
31
+ binaryTarget = arch === "arm64" ? "windows-arm64" : "windows-x64";
34
32
  } else if (platform === "darwin") {
35
- binaryName = arch === "arm64" ? "xems-darwin-arm64" : "xems-darwin-x64";
33
+ binaryTarget = arch === "arm64" ? "darwin-arm64" : "darwin-x64";
36
34
  } else if (platform === "linux") {
37
- binaryName = arch === "arm64" ? "xems-linux-arm64" : "xems-linux-x64";
35
+ binaryTarget = arch === "arm64" ? "linux-arm64" : "linux-x64";
38
36
  } else {
39
37
  return null;
40
38
  }
41
39
 
40
+ // Naming convention: xems-linux-x64, xems-windows-x64.exe, etc.
41
+ const binaryName = `xems-${binaryTarget}${platform === "win32" ? ".exe" : ""}`;
42
+
42
43
  return {
43
44
  binaryName,
44
- url: `${CDN_BASE_URL}/${binaryName}`,
45
+ url: `https://github.com/${REPO}/releases/latest/download/${binaryName}`,
46
+ fallbackUrl: `${CDN_BASE_URL}/${binaryName}`,
45
47
  localPath: path.join(BIN_DIR, binaryName),
46
48
  genericPath: path.join(
47
49
  BIN_DIR,
@@ -50,50 +52,118 @@ function getPlatformBinary() {
50
52
  };
51
53
  }
52
54
 
53
- async function installXems() {
54
- console.log("🚀 Installing XEMS binary...");
55
+ /**
56
+ * Download a file with redirect support
57
+ */
58
+ function downloadFile(url, dest) {
59
+ return new Promise((resolve, reject) => {
60
+ const file = fs.createWriteStream(dest);
61
+
62
+ const request = https.get(
63
+ url,
64
+ {
65
+ headers: { "User-Agent": "XyPriss-Installer" },
66
+ },
67
+ (response) => {
68
+ if (
69
+ response.statusCode >= 300 &&
70
+ response.statusCode < 400 &&
71
+ response.headers.location
72
+ ) {
73
+ file.close();
74
+ fs.unlinkSync(dest);
75
+ return downloadFile(response.headers.location, dest)
76
+ .then(resolve)
77
+ .catch(reject);
78
+ }
79
+
80
+ if (response.statusCode !== 200) {
81
+ file.close();
82
+ fs.unlinkSync(dest);
83
+ return reject(
84
+ new Error(
85
+ `Server responded with ${response.statusCode}`,
86
+ ),
87
+ );
88
+ }
89
+
90
+ response.pipe(file);
91
+
92
+ file.on("finish", () => {
93
+ file.close();
94
+ resolve();
95
+ });
96
+ },
97
+ );
98
+
99
+ request.on("error", (err) => {
100
+ file.close();
101
+ if (fs.existsSync(dest)) fs.unlinkSync(dest);
102
+ reject(err);
103
+ });
104
+ });
105
+ }
55
106
 
107
+ async function installXems() {
56
108
  if (!fs.existsSync(BIN_DIR)) {
57
109
  fs.mkdirSync(BIN_DIR, { recursive: true });
58
110
  }
59
111
 
60
- // Strategy 1: Build from source if local source exists (Development)
61
- const localSource = path.join(__dirname, "..", "tools", "XEMS");
62
- if (fs.existsSync(localSource)) {
63
- console.log("🔨 Local source detected. Building XEMS from source...");
64
- try {
65
- const buildCmd =
66
- process.platform === "win32"
67
- ? `cd "${localSource}" && go build -o "../../bin/xems.exe" ./cmd/xems/main.go`
68
- : `cd "${localSource}" && go build -o "../../bin/xems" ./cmd/xems/main.go`;
69
-
70
- execSync(buildCmd, { stdio: "inherit" });
71
- console.log("✅ XEMS built successfully from local source.");
72
- return;
73
- } catch (err) {
74
- console.warn(
75
- "⚠️ Failed to build XEMS from local source, trying other methods...",
76
- );
77
- }
112
+ const info = getPlatformBinary();
113
+ if (!info) {
114
+ console.error(
115
+ " XEMS is not supported on this platform/architecture.",
116
+ );
117
+ return;
78
118
  }
79
119
 
80
- // Strategy 2: Download from GitHub Releases / CDN (Production)
81
- const info = getPlatformBinary();
82
- if (info) {
120
+ console.log(`📂 Target directory: ${BIN_DIR}`);
121
+ console.log(`📦 Binary: ${info.binaryName}`);
122
+
123
+ if (fs.existsSync(info.genericPath)) {
83
124
  console.log(
84
- `🌐 Downloading pre-built binary for ${process.platform}-${process.arch}...`,
125
+ `✨ XEMS binary already present at ${info.genericPath}, skipping.`,
85
126
  );
86
- // Note: For now we'll just log and suggest building.
87
- // Real implementation would use https.get to download as in install-memory-cli.js
88
- // console.warn(
89
- // "⚠️ Binary download not yet implemented for the new repo. Please ensure 'go' is installed and build from source.",
90
- // );
127
+ return;
128
+ }
129
+
130
+ console.log(`🌐 Downloading XEMS (${info.binaryName})...`);
131
+
132
+ try {
133
+ try {
134
+ console.log(`🌐 Downloading XEMS from GitHub: ${info.url}`);
135
+ await downloadFile(info.url, info.localPath);
136
+ console.log("✅ Downloaded from GitHub.");
137
+ } catch (e) {
138
+ console.log(
139
+ `📡 GitHub download failed, trying fallback CDN: ${info.fallbackUrl}`,
140
+ );
141
+ await downloadFile(info.fallbackUrl, info.localPath);
142
+ console.log("✅ Downloaded from fallback CDN.");
143
+ }
144
+
145
+ if (process.platform !== "win32") {
146
+ fs.chmodSync(info.localPath, 0o755);
147
+ }
148
+
149
+ if (process.platform === "win32") {
150
+ fs.copyFileSync(info.localPath, info.genericPath);
151
+ } else {
152
+ if (fs.existsSync(info.genericPath))
153
+ fs.unlinkSync(info.genericPath);
154
+ fs.symlinkSync(path.basename(info.localPath), info.genericPath);
155
+ }
156
+
157
+ console.log(`🚀 XEMS successfully installed at: ${info.genericPath}`);
158
+ } catch (err) {
159
+ console.error("❌ XEMS download failed:", err.message);
91
160
  }
92
161
  }
93
162
 
94
163
  if (import.meta.url === `file://${process.argv[1]}`) {
95
- installXems().catch((err) => {
96
- console.error(" XEMS Installation failed:", err);
164
+ installXems().catch((error) => {
165
+ console.error("🔥 Installation failed:", error.message);
166
+ process.exit(0);
97
167
  });
98
168
  }
99
169
 
@@ -1,9 +1,8 @@
1
1
  import { execSync } from "child_process";
2
- import { existsSync, mkdirSync, createWriteStream } from "fs";
3
- import { join, dirname } from "path";
2
+ import fs from "fs";
3
+ import { join, dirname, basename } from "path";
4
4
  import { platform, arch } from "os";
5
5
  import https from "https";
6
-
7
6
  import { fileURLToPath } from "url";
8
7
 
9
8
  const __filename = fileURLToPath(import.meta.url);
@@ -11,102 +10,118 @@ const __dirname = dirname(__filename);
11
10
 
12
11
  const REPO = "Nehonix-Team/XyPriss";
13
12
  const BIN_NAME = "xsys";
13
+ const BIN_DIR = join(__dirname, "..", "bin");
14
+
15
+ /**
16
+ * Téléchargement avec support des redirections GitHub
17
+ */
18
+ function downloadFile(url, dest) {
19
+ return new Promise((resolve, reject) => {
20
+ const file = fs.createWriteStream(dest);
21
+ const request = https.get(
22
+ url,
23
+ {
24
+ headers: { "User-Agent": "XyPriss-Installer" },
25
+ },
26
+ (response) => {
27
+ if (
28
+ response.statusCode >= 300 &&
29
+ response.statusCode < 400 &&
30
+ response.headers.location
31
+ ) {
32
+ file.close();
33
+ fs.unlinkSync(dest);
34
+ return downloadFile(response.headers.location, dest)
35
+ .then(resolve)
36
+ .catch(reject);
37
+ }
38
+ if (response.statusCode !== 200) {
39
+ file.close();
40
+ fs.unlinkSync(dest);
41
+ return reject(new Error(`HTTP ${response.statusCode}`));
42
+ }
43
+ response.pipe(file);
44
+ file.on("finish", () => {
45
+ file.close();
46
+ resolve();
47
+ });
48
+ },
49
+ );
50
+ request.on("error", (err) => {
51
+ file.close();
52
+ if (fs.existsSync(dest)) fs.unlinkSync(dest);
53
+ reject(err);
54
+ });
55
+ });
56
+ }
14
57
 
15
- async function install() {
16
- const targetDir = join(__dirname, "..", "bin");
17
- if (!existsSync(targetDir)) {
18
- mkdirSync(targetDir, { recursive: true });
58
+ async function installXsys() {
59
+ if (!fs.existsSync(BIN_DIR)) {
60
+ fs.mkdirSync(BIN_DIR, { recursive: true });
19
61
  }
20
62
 
21
63
  const osName = platform();
22
64
  const archName = arch();
23
65
 
66
+ // Mappage exact avec tes fichiers dans tools/xypriss-sys-go/dist/
24
67
  let binaryTarget = "";
25
68
  if (osName === "linux") {
26
69
  binaryTarget = archName === "arm64" ? "linux-arm64" : "linux-amd64";
27
70
  } else if (osName === "darwin") {
28
- binaryTarget = archName === "arm64" ? "darwin-arm64" : "darwin-amd64";
71
+ binaryTarget = archName === "arm64" ? "darwin-arm64" : "darwin-amd64"; // Support macOS Intel & Silicon
29
72
  } else if (osName === "win32") {
30
- binaryTarget = "windows-amd64";
73
+ binaryTarget = archName === "arm64" ? "windows-arm64" : "windows-amd64";
31
74
  } else {
32
- console.warn(
33
- `Unsupported platform/architecture: ${osName}/${archName}. Attempting to build from source...`
34
- );
35
- try {
36
- execSync("cd tools/xypriss-sys && cargo build --release", {
37
- stdio: "inherit",
38
- });
39
- execSync(
40
- `cp tools/xypriss-sys/target/release/${BIN_NAME} bin/${BIN_NAME}`,
41
- { stdio: "inherit" }
42
- );
43
- return;
44
- } catch (e) {
45
- console.error(
46
- "Failed to build from source. Please ensure Rust is installed."
47
- );
48
- process.exit(1);
49
- }
75
+ console.error(`❌ Plateforme non supportée : ${osName}`);
76
+ return;
50
77
  }
51
78
 
52
- const url = `https://github.com/${REPO}/releases/latest/download/${BIN_NAME}-${binaryTarget}${
53
- osName === "win32" ? ".exe" : ""
54
- }`;
55
- const destPath = join(
56
- targetDir,
57
- BIN_NAME + (osName === "win32" ? ".exe" : "")
79
+ const binaryFileName = `${BIN_NAME}-${binaryTarget}${osName === "win32" ? ".exe" : ""}`;
80
+ const url = `https://github.com/${REPO}/releases/latest/download/${binaryFileName}`;
81
+ const localPath = join(BIN_DIR, binaryFileName);
82
+ const genericPath = join(
83
+ BIN_DIR,
84
+ BIN_NAME + (osName === "win32" ? ".exe" : ""),
58
85
  );
59
86
 
60
- console.log(`Downloading ${BIN_NAME} from ${url}...`);
61
-
62
- // Note: Since this is a postinstall script, we might not have 'axios' or 'node-fetch'
63
- // We'll use built-in 'https'
64
-
65
- const download = (downloadUrl) => {
66
- https
67
- .get(
68
- downloadUrl,
69
- {
70
- headers: { "User-Agent": "XyPriss-Installer" },
71
- },
72
- (response) => {
73
- if (
74
- response.statusCode >= 300 &&
75
- response.statusCode < 400 &&
76
- response.headers.location
77
- ) {
78
- download(response.headers.location);
79
- return;
80
- }
81
-
82
- if (response.statusCode === 200) {
83
- const file = createWriteStream(destPath);
84
- response.pipe(file);
85
- file.on("finish", () => {
86
- file.close();
87
- if (osName !== "win32") {
88
- execSync(`chmod +x ${destPath}`);
89
- }
90
- console.log(
91
- `${BIN_NAME} installed successfully at ${destPath}`
92
- );
93
- });
94
- } else {
95
- console.error(
96
- `Failed to download binary: ${response.statusCode}`
97
- );
98
- process.exit(1);
99
- }
100
- }
101
- )
102
- .on("error", (err) => {
103
- console.error(`Error downloading file: ${err.message}`);
104
- process.exit(1);
105
- });
106
- };
107
-
108
- download(url);
87
+ console.log(`📂 Répertoire cible : ${BIN_DIR}`);
88
+ console.log(`📦 Binaire : ${binaryFileName}`);
89
+
90
+ if (fs.existsSync(genericPath)) {
91
+ console.log(
92
+ `✨ XSYS est déjà présent à ${genericPath}, installation ignorée.`,
93
+ );
94
+ return;
95
+ }
96
+
97
+ console.log(`🌐 Téléchargement de XSYS depuis GitHub : ${url}`);
98
+
99
+ try {
100
+ await downloadFile(url, localPath);
101
+
102
+ if (osName !== "win32") {
103
+ fs.chmodSync(localPath, 0o755);
104
+ }
105
+
106
+ // Création du lien/copie générique
107
+ if (osName === "win32") {
108
+ fs.copyFileSync(localPath, genericPath);
109
+ } else {
110
+ if (fs.existsSync(genericPath)) fs.unlinkSync(genericPath);
111
+ fs.symlinkSync(basename(localPath), genericPath);
112
+ }
113
+
114
+ console.log(`✅ XSYS installé avec succès : ${genericPath}`);
115
+ } catch (err) {
116
+ console.error(
117
+ `❌ Échec de l'acquisition du binaire XSYS : ${err.message}`,
118
+ );
119
+ }
120
+ }
121
+
122
+ if (import.meta.url === `file://${process.argv[1]}`) {
123
+ installXsys().catch(() => process.exit(0));
109
124
  }
110
125
 
111
- install().catch(console.error);
126
+ export { installXsys };
112
127
 
@@ -6,17 +6,27 @@
6
6
  */
7
7
 
8
8
  import { installMemoryCLI } from "./install-memory-cli.js";
9
+ import { installXems } from "./install-xems.js";
10
+ import { installXsys } from "./postinstall-xsys.js";
9
11
 
10
12
  async function postInstall() {
11
13
  console.log("🔧 Running XyPriss post-install setup...");
12
14
 
13
15
  try {
16
+ // 1. Install Memory CLI
14
17
  await installMemoryCLI();
18
+
19
+ // 2. Install XEMS (Security Core)
20
+ await installXems();
21
+
22
+ // 3. Install XSYS (System Core)
23
+ await installXsys();
24
+
15
25
  console.log("✅ XyPriss setup complete!");
16
26
  } catch (error) {
17
27
  console.warn(
18
28
  "⚠️ Post-install setup encountered issues:",
19
- error.message
29
+ error.message,
20
30
  );
21
31
  console.log("📝 XyPriss will continue to work with fallback mode.");
22
32
  }
@@ -32,4 +42,3 @@ if (import.meta.url === `file://${process.argv[1]}`) {
32
42
  }
33
43
 
34
44
  export { postInstall };
35
-