@titanpl/core 2.0.7 → 2.0.8

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/configure.js +42 -24
  2. package/package.json +1 -1
package/configure.js CHANGED
@@ -2,48 +2,66 @@ import { readFileSync, existsSync, writeFileSync } from 'fs';
2
2
  import { resolve, dirname } from 'path';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { platform as _platform } from 'os';
5
+ import { spawnSync } from 'child_process';
5
6
 
6
7
  const __filename = fileURLToPath(import.meta.url);
7
8
  const __dirname = dirname(__filename);
8
- const platform = _platform(); // 'win32', 'linux', 'darwin'
9
+ const platform = _platform();
9
10
  const titanConfigPath = resolve(__dirname, 'titan.json');
10
11
 
11
12
  console.log(`Configuring titan.json for platform: ${platform}`);
12
13
 
13
- try {
14
- const content = readFileSync(titanConfigPath, 'utf8');
15
- const titanConfig = JSON.parse(content);
14
+ // 1. Platform-specific output file name
15
+ let libFile = "";
16
+ if (platform === "win32") {
17
+ libFile = "titan_core.dll";
18
+ } else if (platform === "darwin") {
19
+ libFile = "libtitan_core.dylib";
20
+ } else {
21
+ libFile = "libtitan_core.so";
22
+ }
16
23
 
17
- let libPath = "";
18
- if (platform === 'win32') {
19
- libPath = "native/target/release/titan_core.dll";
20
- } else if (platform === 'darwin') {
21
- libPath = "native/target/release/libtitan_core.dylib";
22
- } else {
23
- // Assume linux/unix defaults for anything else
24
- libPath = "native/target/release/libtitan_core.so";
25
- }
24
+ const nativeDir = resolve(__dirname, "native");
25
+ const expectedBinary = resolve(nativeDir, "target/release", libFile);
26
26
 
27
- const fullPath = resolve(__dirname, libPath);
28
- if (!existsSync(fullPath)) {
29
- console.warn(`Warning: Native binary not found at ${fullPath}. Valid binaries for this platform must be built or provided.`);
30
- }
27
+ // 2. Build if binary missing
28
+ if (!existsSync(expectedBinary)) {
29
+ console.log(`Native binary missing. Building silently for ${platform}...`);
30
+
31
+ const build = spawnSync(
32
+ "cargo",
33
+ ["build", "--release"],
34
+ {
35
+ cwd: nativeDir,
36
+ stdio: "ignore", // <-- completely hides Rust logs
37
+ shell: true
38
+ }
39
+ );
31
40
 
32
- // Check if configuration actually needs changing to avoid unnecessary writes
33
- if (titanConfig.native && titanConfig.native.path === libPath) {
34
- console.log(`titan.json is already configured for ${platform}.`);
35
- process.exit(0);
41
+ if (build.status !== 0) {
42
+ console.error("Cargo build failed. (No logs shown due to silent mode)");
43
+ process.exit(1);
36
44
  }
37
45
 
46
+ console.log(`Build completed for ${platform}.`);
47
+ }
48
+
49
+ // 3. Update titan.json
50
+ try {
51
+ const content = readFileSync(titanConfigPath, "utf8");
52
+ const titanConfig = JSON.parse(content);
53
+
54
+ const relativeLibPath = `native/target/release/${libFile}`;
55
+
38
56
  if (!titanConfig.native) {
39
57
  titanConfig.native = {};
40
58
  }
41
59
 
42
- titanConfig.native.path = libPath;
60
+ titanConfig.native.path = relativeLibPath;
43
61
 
44
62
  writeFileSync(titanConfigPath, JSON.stringify(titanConfig, null, 2));
45
- console.log(`Successfully updated titan.json native path to: ${libPath}`);
63
+ console.log(`Updated titan.json to use native binary: ${relativeLibPath}`);
46
64
  } catch (error) {
47
- console.error("Error configuring titan.json:", error);
65
+ console.error("Error updating titan.json:", error);
48
66
  process.exit(1);
49
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/core",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "The official Core Standard Library for Titan Planet - provides fs, path, crypto, os, net, proc, time, and url modules",
5
5
  "main": "index.js",
6
6
  "type": "module",