@bloxbean/yaci-devkit 0.10.0-preview4 → 0.10.1

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 +3 -3
  2. package/start.mjs +52 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloxbean/yaci-devkit",
3
- "version": "0.10.0-preview4",
3
+ "version": "0.10.1",
4
4
  "description": "A set of development tools for building on Cardano by creating a local devnet.",
5
5
  "keywords": [
6
6
  "yaci-devkit",
@@ -17,8 +17,8 @@
17
17
  "yaci-devkit": "./start.mjs"
18
18
  },
19
19
  "dependencies": {
20
- "@bloxbean/yaci-devkit-linux-x64": "0.10.0-preview4",
21
- "@bloxbean/yaci-devkit-macos-arm64": "0.10.0-preview4"
20
+ "@bloxbean/yaci-devkit-linux-x64": "0.10.1",
21
+ "@bloxbean/yaci-devkit-macos-arm64": "0.10.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^22.10.2",
package/start.mjs CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from "node:child_process";
4
- import { platform } from "node:os";
5
- import { fileURLToPath } from 'node:url';
6
- import { dirname, resolve } from 'node:path';
4
+ import { platform, homedir } from "node:os";
5
+ import { fileURLToPath } from "node:url";
6
+ import { dirname, resolve, join } from "node:path";
7
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from "node:fs";
8
+
7
9
  // import { createHash } from "node:crypto";
8
10
 
9
11
  const osType = platform();
@@ -38,6 +40,42 @@ const devkitDir = dirname(binPath);
38
40
 
39
41
  const configPath = resolve(devkitDir, 'config');
40
42
 
43
+ // Determine the path to the user's `.yaci-cli` directory
44
+ const yaciCliHome = join(homedir(), ".yaci-cli");
45
+ if (!existsSync(yaciCliHome)) {
46
+ mkdirSync(yaciCliHome, { recursive: true });
47
+ }
48
+
49
+ // Path for the PID file
50
+ const pidFilePath = join(yaciCliHome, "yaci-cli.pid");
51
+
52
+ function killProcessTree(pid) {
53
+ try {
54
+ if (osType === "linux" || osType === "darwin") {
55
+ // Use `pkill` to kill the entire process tree
56
+ spawn("pkill", ["-TERM", "-P", pid], { stdio: "ignore" });
57
+ process.kill(pid, "SIGKILL"); // Kill the main process
58
+ } else {
59
+ console.error("Unsupported platform for process termination.");
60
+ }
61
+ } catch (err) {
62
+ console.error(`Failed to kill process tree for PID ${pid}: ${err.message}`);
63
+ }
64
+ }
65
+
66
+ if (existsSync(pidFilePath)) {
67
+ try {
68
+ const existingPid = parseInt(readFileSync(pidFilePath, "utf-8"), 10);
69
+ if (!isNaN(existingPid)) {
70
+ console.log(`Killing existing yaci-cli process and its subprocesses with PID: ${existingPid}`);
71
+ killProcessTree(existingPid); // Kill the process tree
72
+ unlinkSync(pidFilePath); // Remove the stale PID file
73
+ }
74
+ } catch (err) {
75
+ console.error(`Failed to clean up existing yaci-cli process: ${err.message}`);
76
+ }
77
+ }
78
+
41
79
  // const tmpSuffix = createHash('md5').update(workDir).digest("hex");
42
80
  // const yaciCLIHome = resolve("/tmp", ".yaci-cli" + tmpSuffix )
43
81
 
@@ -55,6 +93,17 @@ const child = spawn(binPath, [additionalConfigArg, ...process.argv.slice(2)], {
55
93
 
56
94
  });
57
95
 
96
+
97
+ writeFileSync(pidFilePath, child.pid.toString());
98
+ console.log(`yaci-cli process started with PID: ${child.pid}`);
99
+
100
+ // Handle process exit
58
101
  child.on("close", (code) => {
102
+ console.log(`yaci-cli process exited with code: ${code}`);
103
+ try {
104
+ unlinkSync(pidFilePath);
105
+ } catch (err) {
106
+ console.error(`Failed to remove PID file: ${err.message}`);
107
+ }
59
108
  process.exit(code ?? 0);
60
109
  });