@kelceyp/caw 1.0.6 → 1.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.
- package/dist/caw.js +62 -18
- package/package.json +1 -1
- package/scripts/postinstall.js +1 -1
package/dist/caw.js
CHANGED
|
@@ -10644,7 +10644,10 @@ function isProcessAlive(pid) {
|
|
|
10644
10644
|
}
|
|
10645
10645
|
}
|
|
10646
10646
|
function getPm2Name(envDir) {
|
|
10647
|
-
|
|
10647
|
+
const base = path3.basename(envDir).replace(/^\./, "");
|
|
10648
|
+
if (base === "caw")
|
|
10649
|
+
return "caw";
|
|
10650
|
+
return `caw-${base}`;
|
|
10648
10651
|
}
|
|
10649
10652
|
function isPm2Installed() {
|
|
10650
10653
|
try {
|
|
@@ -10718,6 +10721,8 @@ function createPm2Manager(envDir, checkPm2 = isPm2Installed) {
|
|
|
10718
10721
|
return false;
|
|
10719
10722
|
try {
|
|
10720
10723
|
pm2Exec(`stop ${name}`);
|
|
10724
|
+
} catch {}
|
|
10725
|
+
try {
|
|
10721
10726
|
pm2Exec(`delete ${name}`);
|
|
10722
10727
|
return true;
|
|
10723
10728
|
} catch {
|
|
@@ -10731,6 +10736,9 @@ function createPm2Manager(envDir, checkPm2 = isPm2Installed) {
|
|
|
10731
10736
|
` + `Install PM2 with: npm install -g pm2
|
|
10732
10737
|
` + 'Or switch to PID mode by setting "process_manager": "pid" in config.json');
|
|
10733
10738
|
}
|
|
10739
|
+
try {
|
|
10740
|
+
pm2Exec(`delete ${name}`);
|
|
10741
|
+
} catch {}
|
|
10734
10742
|
const logPath = logFilePath(envDir);
|
|
10735
10743
|
const envArgs = Object.entries(envVars).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
10736
10744
|
const nodeArgsStr = nodeArgs.length > 0 ? ` --node-args="${nodeArgs.map((a) => `\\"${a}\\"`).join(" ")}"` : "";
|
|
@@ -10971,7 +10979,7 @@ async function pollHealth(port, maxRetries = 10, intervalMs = 1000) {
|
|
|
10971
10979
|
}
|
|
10972
10980
|
function attemptInstallServer() {
|
|
10973
10981
|
try {
|
|
10974
|
-
execSync4("npm install -g @kelceyp/caw-server@^1", { stdio: "inherit" });
|
|
10982
|
+
execSync4("npm install -g @kelceyp/caw-server@^1 --loglevel=error", { stdio: "inherit" });
|
|
10975
10983
|
return true;
|
|
10976
10984
|
} catch {
|
|
10977
10985
|
return false;
|
|
@@ -11412,6 +11420,18 @@ async function checkHealth3(port) {
|
|
|
11412
11420
|
return { reachable: false, healthy: false, data: null };
|
|
11413
11421
|
}
|
|
11414
11422
|
}
|
|
11423
|
+
async function fetchRunningVersion(port) {
|
|
11424
|
+
try {
|
|
11425
|
+
const response = await fetch(`http://localhost:${port}/api/info`);
|
|
11426
|
+
if (response.ok) {
|
|
11427
|
+
const data = await response.json();
|
|
11428
|
+
return data.version || null;
|
|
11429
|
+
}
|
|
11430
|
+
return null;
|
|
11431
|
+
} catch {
|
|
11432
|
+
return null;
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11415
11435
|
async function pollHealth2(port, maxRetries = 10, intervalMs = 1000) {
|
|
11416
11436
|
for (let i = 0;i < maxRetries; i++) {
|
|
11417
11437
|
await new Promise((r) => setTimeout(r, intervalMs));
|
|
@@ -11467,12 +11487,30 @@ var create6 = () => {
|
|
|
11467
11487
|
} catch (e) {
|
|
11468
11488
|
console.warn(`Warning: Could not write cache file: ${e.message}`);
|
|
11469
11489
|
}
|
|
11490
|
+
let skipInstall = false;
|
|
11470
11491
|
if (import_semver2.default.gte(installedVersion, latestServerVersion)) {
|
|
11471
|
-
|
|
11472
|
-
|
|
11492
|
+
let needsRestart = false;
|
|
11493
|
+
if (fs11.existsSync(envDir) && configExists4(envDir)) {
|
|
11494
|
+
const config = readConfigWithDefaults(envDir);
|
|
11495
|
+
const pm = createProcessManager(config, envDir);
|
|
11496
|
+
if (pm.isRunning().running) {
|
|
11497
|
+
const runningVersion = await fetchRunningVersion(config.port);
|
|
11498
|
+
if (runningVersion && import_semver2.default.lt(runningVersion, installedVersion)) {
|
|
11499
|
+
needsRestart = true;
|
|
11500
|
+
console.log(`Installed: ${installedVersion} Running: ${runningVersion} — restarting server.`);
|
|
11501
|
+
}
|
|
11502
|
+
}
|
|
11503
|
+
}
|
|
11504
|
+
if (!needsRestart) {
|
|
11505
|
+
console.log(`Server is already up to date (version ${installedVersion}).`);
|
|
11506
|
+
process.exit(0);
|
|
11507
|
+
}
|
|
11508
|
+
skipInstall = true;
|
|
11509
|
+
}
|
|
11510
|
+
if (!skipInstall) {
|
|
11511
|
+
console.log(`Server update available: ${installedVersion} → ${latestServerVersion}`);
|
|
11473
11512
|
}
|
|
11474
|
-
|
|
11475
|
-
if (!import_semver2.default.satisfies(latestServerVersion, COMPATIBLE_SERVER_RANGE)) {
|
|
11513
|
+
if (!skipInstall && !import_semver2.default.satisfies(latestServerVersion, COMPATIBLE_SERVER_RANGE)) {
|
|
11476
11514
|
const installedLauncherVersion = resolveInstalledLauncherVersion();
|
|
11477
11515
|
if (installedLauncherVersion && installedLauncherVersion === latestLauncherVersion) {
|
|
11478
11516
|
console.error(`Error: Launcher is already at the latest version (${installedLauncherVersion}) but does not support server version ${latestServerVersion}. A new launcher version is needed before upgrading.`);
|
|
@@ -11480,7 +11518,7 @@ var create6 = () => {
|
|
|
11480
11518
|
}
|
|
11481
11519
|
console.log(`Upgrading launcher to ${latestLauncherVersion}...`);
|
|
11482
11520
|
try {
|
|
11483
|
-
execSync5(`npm install -g @kelceyp/caw@${latestLauncherVersion}`, { stdio: "inherit" });
|
|
11521
|
+
execSync5(`npm install -g @kelceyp/caw@${latestLauncherVersion} --loglevel=error`, { stdio: "inherit" });
|
|
11484
11522
|
} catch {
|
|
11485
11523
|
console.error("Error: Could not upgrade launcher. Run manually: npm install -g @kelceyp/caw@latest");
|
|
11486
11524
|
process.exit(1);
|
|
@@ -11529,16 +11567,18 @@ var create6 = () => {
|
|
|
11529
11567
|
pm.cleanup();
|
|
11530
11568
|
}
|
|
11531
11569
|
}
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11570
|
+
if (!skipInstall) {
|
|
11571
|
+
console.log(`Installing @kelceyp/caw-server@${latestServerVersion}...`);
|
|
11572
|
+
try {
|
|
11573
|
+
execSync5(`npm install -g @kelceyp/caw-server@${latestServerVersion} --loglevel=error`, { stdio: "inherit" });
|
|
11574
|
+
} catch {
|
|
11575
|
+
if (serverWasStopped) {
|
|
11576
|
+
console.error("Error: npm install failed. Server is stopped. Fix the issue and run 'caw upgrade' again, or start the server with 'caw start'.");
|
|
11577
|
+
} else {
|
|
11578
|
+
console.error("Error: npm install failed. Fix the issue and run 'caw upgrade' again.");
|
|
11579
|
+
}
|
|
11580
|
+
process.exit(1);
|
|
11540
11581
|
}
|
|
11541
|
-
process.exit(1);
|
|
11542
11582
|
}
|
|
11543
11583
|
if (serverWasStopped || fs11.existsSync(envDir) && configExists4(envDir)) {
|
|
11544
11584
|
const config = readConfigWithDefaults(envDir);
|
|
@@ -11560,7 +11600,11 @@ var create6 = () => {
|
|
|
11560
11600
|
process.exit(1);
|
|
11561
11601
|
}
|
|
11562
11602
|
}
|
|
11563
|
-
|
|
11603
|
+
if (skipInstall) {
|
|
11604
|
+
console.log(`Server restarted with version ${installedVersion}.`);
|
|
11605
|
+
} else {
|
|
11606
|
+
console.log(`Server upgraded from ${installedVersion} to ${latestServerVersion}.`);
|
|
11607
|
+
}
|
|
11564
11608
|
}).onError({ exitCode: 1 }).build();
|
|
11565
11609
|
};
|
|
11566
11610
|
var upgrade_default = Object.freeze({ create: create6 });
|
|
@@ -11577,6 +11621,6 @@ if (!globalCheck.ok) {
|
|
|
11577
11621
|
console.error(globalCheck.message);
|
|
11578
11622
|
process.exit(1);
|
|
11579
11623
|
}
|
|
11580
|
-
var LAUNCHER_VERSION = "1.0.
|
|
11624
|
+
var LAUNCHER_VERSION = "1.0.8";
|
|
11581
11625
|
var app = create().name("caw").version(LAUNCHER_VERSION).command(start_default.create()).command(stop_default.create()).command(status_default.create()).command(logs_default.create()).command(upgrade_default.create());
|
|
11582
11626
|
await app.run(process.argv.slice(2));
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process';
|
|
2
2
|
|
|
3
3
|
try {
|
|
4
|
-
execSync('npm install -g @kelceyp/caw-server@^1', { stdio: 'inherit' });
|
|
4
|
+
execSync('npm install -g @kelceyp/caw-server@^1 --loglevel=error', { stdio: 'inherit' });
|
|
5
5
|
} catch {
|
|
6
6
|
console.warn('Could not install @kelceyp/caw-server automatically.');
|
|
7
7
|
console.warn('Run "caw start" to retry installation.');
|