@kelceyp/caw 1.0.13 → 1.0.15
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 +90 -86
- package/package.json +1 -1
package/dist/caw.js
CHANGED
|
@@ -10556,6 +10556,63 @@ function checkPrefixWritable() {
|
|
|
10556
10556
|
}
|
|
10557
10557
|
}
|
|
10558
10558
|
|
|
10559
|
+
// src/server-info.js
|
|
10560
|
+
import fs3 from "node:fs";
|
|
10561
|
+
import path2 from "node:path";
|
|
10562
|
+
import { execSync as execSync2 } from "node:child_process";
|
|
10563
|
+
function resolve(overrideBinPath) {
|
|
10564
|
+
let binPath;
|
|
10565
|
+
if (overrideBinPath) {
|
|
10566
|
+
binPath = overrideBinPath;
|
|
10567
|
+
} else {
|
|
10568
|
+
try {
|
|
10569
|
+
binPath = execSync2("which caw-server", { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
10570
|
+
} catch {
|
|
10571
|
+
return null;
|
|
10572
|
+
}
|
|
10573
|
+
if (!binPath)
|
|
10574
|
+
return null;
|
|
10575
|
+
}
|
|
10576
|
+
let realPath;
|
|
10577
|
+
try {
|
|
10578
|
+
realPath = fs3.realpathSync(binPath);
|
|
10579
|
+
} catch {
|
|
10580
|
+
return null;
|
|
10581
|
+
}
|
|
10582
|
+
let dir = path2.dirname(realPath);
|
|
10583
|
+
let packageRoot = null;
|
|
10584
|
+
for (let i = 0;i < 10; i++) {
|
|
10585
|
+
const candidate = path2.join(dir, "package.json");
|
|
10586
|
+
if (fs3.existsSync(candidate)) {
|
|
10587
|
+
try {
|
|
10588
|
+
const pkg = JSON.parse(fs3.readFileSync(candidate, "utf8"));
|
|
10589
|
+
if (pkg.name === "@kelceyp/caw-server") {
|
|
10590
|
+
packageRoot = dir;
|
|
10591
|
+
break;
|
|
10592
|
+
}
|
|
10593
|
+
} catch {}
|
|
10594
|
+
}
|
|
10595
|
+
const parent = path2.dirname(dir);
|
|
10596
|
+
if (parent === dir)
|
|
10597
|
+
break;
|
|
10598
|
+
dir = parent;
|
|
10599
|
+
}
|
|
10600
|
+
if (!packageRoot)
|
|
10601
|
+
return null;
|
|
10602
|
+
const packageJsonPath = path2.join(packageRoot, "package.json");
|
|
10603
|
+
let version;
|
|
10604
|
+
try {
|
|
10605
|
+
const pkg = JSON.parse(fs3.readFileSync(packageJsonPath, "utf8"));
|
|
10606
|
+
version = pkg.version;
|
|
10607
|
+
} catch {
|
|
10608
|
+
return null;
|
|
10609
|
+
}
|
|
10610
|
+
const mainJsPath = path2.join(packageRoot, "dist", "main.js");
|
|
10611
|
+
if (!fs3.existsSync(mainJsPath))
|
|
10612
|
+
return null;
|
|
10613
|
+
return { mainJsPath, version, packageRoot };
|
|
10614
|
+
}
|
|
10615
|
+
|
|
10559
10616
|
// src/commands/start.js
|
|
10560
10617
|
import fs6 from "node:fs";
|
|
10561
10618
|
import path5 from "node:path";
|
|
@@ -10563,8 +10620,8 @@ import os2 from "node:os";
|
|
|
10563
10620
|
import { execSync as execSync4 } from "node:child_process";
|
|
10564
10621
|
|
|
10565
10622
|
// src/config.js
|
|
10566
|
-
import
|
|
10567
|
-
import
|
|
10623
|
+
import fs4 from "node:fs";
|
|
10624
|
+
import path3 from "node:path";
|
|
10568
10625
|
var CONFIG_FILENAME = "config.json";
|
|
10569
10626
|
var PENDING_FILENAME = "config.pending.json";
|
|
10570
10627
|
var DEFAULTS = Object.freeze({
|
|
@@ -10576,23 +10633,23 @@ var DEFAULTS = Object.freeze({
|
|
|
10576
10633
|
})
|
|
10577
10634
|
});
|
|
10578
10635
|
function configPath(envDir) {
|
|
10579
|
-
return
|
|
10636
|
+
return path3.join(envDir, CONFIG_FILENAME);
|
|
10580
10637
|
}
|
|
10581
10638
|
function pendingPath(envDir) {
|
|
10582
|
-
return
|
|
10639
|
+
return path3.join(envDir, PENDING_FILENAME);
|
|
10583
10640
|
}
|
|
10584
10641
|
function atomicWrite(filePath, data) {
|
|
10585
10642
|
const tmpPath = filePath + ".tmp";
|
|
10586
|
-
|
|
10643
|
+
fs4.writeFileSync(tmpPath, JSON.stringify(data, null, 2) + `
|
|
10587
10644
|
`);
|
|
10588
|
-
|
|
10645
|
+
fs4.renameSync(tmpPath, filePath);
|
|
10589
10646
|
}
|
|
10590
10647
|
function readJsonFile(filePath) {
|
|
10591
|
-
const raw =
|
|
10648
|
+
const raw = fs4.readFileSync(filePath, "utf8");
|
|
10592
10649
|
try {
|
|
10593
10650
|
return JSON.parse(raw);
|
|
10594
10651
|
} catch (e) {
|
|
10595
|
-
throw new Error(`Malformed JSON in ${
|
|
10652
|
+
throw new Error(`Malformed JSON in ${path3.basename(filePath)}: ${e.message}`);
|
|
10596
10653
|
}
|
|
10597
10654
|
}
|
|
10598
10655
|
function readConfig(envDir) {
|
|
@@ -10614,45 +10671,45 @@ function mergeConfig(envDir) {
|
|
|
10614
10671
|
return merged;
|
|
10615
10672
|
}
|
|
10616
10673
|
function hasPendingConfig(envDir) {
|
|
10617
|
-
return
|
|
10674
|
+
return fs4.existsSync(pendingPath(envDir));
|
|
10618
10675
|
}
|
|
10619
10676
|
function readPendingConfig(envDir) {
|
|
10620
10677
|
return readJsonFile(pendingPath(envDir));
|
|
10621
10678
|
}
|
|
10622
10679
|
function deletePendingConfig(envDir) {
|
|
10623
|
-
|
|
10680
|
+
fs4.unlinkSync(pendingPath(envDir));
|
|
10624
10681
|
}
|
|
10625
10682
|
|
|
10626
10683
|
// src/process-manager.js
|
|
10627
|
-
import
|
|
10628
|
-
import
|
|
10629
|
-
import { spawn, execSync as
|
|
10684
|
+
import fs5 from "node:fs";
|
|
10685
|
+
import path4 from "node:path";
|
|
10686
|
+
import { spawn, execSync as execSync3 } from "node:child_process";
|
|
10630
10687
|
var PID_FILENAME = "server.pid";
|
|
10631
10688
|
var LOG_FILENAME = "server.log";
|
|
10632
10689
|
function pidFilePath(envDir) {
|
|
10633
|
-
return
|
|
10690
|
+
return path4.join(envDir, PID_FILENAME);
|
|
10634
10691
|
}
|
|
10635
10692
|
function logFilePath(envDir) {
|
|
10636
|
-
return
|
|
10693
|
+
return path4.join(envDir, LOG_FILENAME);
|
|
10637
10694
|
}
|
|
10638
10695
|
function readPid(envDir) {
|
|
10639
10696
|
const filePath = pidFilePath(envDir);
|
|
10640
|
-
if (!
|
|
10697
|
+
if (!fs5.existsSync(filePath))
|
|
10641
10698
|
return null;
|
|
10642
|
-
const raw =
|
|
10699
|
+
const raw = fs5.readFileSync(filePath, "utf8").trim();
|
|
10643
10700
|
const pid = parseInt(raw, 10);
|
|
10644
10701
|
if (Number.isNaN(pid))
|
|
10645
10702
|
return null;
|
|
10646
10703
|
return pid;
|
|
10647
10704
|
}
|
|
10648
10705
|
function writePid(envDir, pid) {
|
|
10649
|
-
|
|
10706
|
+
fs5.writeFileSync(pidFilePath(envDir), String(pid) + `
|
|
10650
10707
|
`);
|
|
10651
10708
|
}
|
|
10652
10709
|
function removePidFile(envDir) {
|
|
10653
10710
|
const filePath = pidFilePath(envDir);
|
|
10654
|
-
if (
|
|
10655
|
-
|
|
10711
|
+
if (fs5.existsSync(filePath))
|
|
10712
|
+
fs5.unlinkSync(filePath);
|
|
10656
10713
|
}
|
|
10657
10714
|
function isProcessAlive(pid) {
|
|
10658
10715
|
try {
|
|
@@ -10663,14 +10720,14 @@ function isProcessAlive(pid) {
|
|
|
10663
10720
|
}
|
|
10664
10721
|
}
|
|
10665
10722
|
function getPm2Name(envDir) {
|
|
10666
|
-
const base =
|
|
10723
|
+
const base = path4.basename(envDir).replace(/^\./, "");
|
|
10667
10724
|
if (base === "caw")
|
|
10668
10725
|
return "caw";
|
|
10669
10726
|
return `caw-${base}`;
|
|
10670
10727
|
}
|
|
10671
10728
|
function isPm2Installed() {
|
|
10672
10729
|
try {
|
|
10673
|
-
|
|
10730
|
+
execSync3("which pm2", { stdio: "ignore" });
|
|
10674
10731
|
return true;
|
|
10675
10732
|
} catch {
|
|
10676
10733
|
return false;
|
|
@@ -10680,7 +10737,7 @@ function createPidManager(envDir) {
|
|
|
10680
10737
|
return {
|
|
10681
10738
|
start(mainJsPath, envVars, nodeArgs = []) {
|
|
10682
10739
|
const logPath = logFilePath(envDir);
|
|
10683
|
-
const logFd =
|
|
10740
|
+
const logFd = fs5.openSync(logPath, "a");
|
|
10684
10741
|
const child = spawn(process.execPath, [...nodeArgs, mainJsPath], {
|
|
10685
10742
|
detached: true,
|
|
10686
10743
|
stdio: ["ignore", logFd, logFd],
|
|
@@ -10688,7 +10745,7 @@ function createPidManager(envDir) {
|
|
|
10688
10745
|
});
|
|
10689
10746
|
writePid(envDir, child.pid);
|
|
10690
10747
|
child.unref();
|
|
10691
|
-
|
|
10748
|
+
fs5.closeSync(logFd);
|
|
10692
10749
|
return child.pid;
|
|
10693
10750
|
},
|
|
10694
10751
|
isRunning() {
|
|
@@ -10733,7 +10790,7 @@ function createPidManager(envDir) {
|
|
|
10733
10790
|
function createPm2Manager(envDir, checkPm2 = isPm2Installed) {
|
|
10734
10791
|
const name = getPm2Name(envDir);
|
|
10735
10792
|
function pm2Exec(args) {
|
|
10736
|
-
return
|
|
10793
|
+
return execSync3(`pm2 ${args}`, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
10737
10794
|
}
|
|
10738
10795
|
function stop() {
|
|
10739
10796
|
if (!checkPm2())
|
|
@@ -10760,8 +10817,8 @@ function createPm2Manager(envDir, checkPm2 = isPm2Installed) {
|
|
|
10760
10817
|
} catch {}
|
|
10761
10818
|
const logPath = logFilePath(envDir);
|
|
10762
10819
|
const envArgs = Object.entries(envVars).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
10763
|
-
const nodeArgsStr = nodeArgs.length > 0 ? ` --node-args="${nodeArgs.
|
|
10764
|
-
|
|
10820
|
+
const nodeArgsStr = nodeArgs.length > 0 ? ` --node-args="${nodeArgs.join(" ")}"` : "";
|
|
10821
|
+
execSync3(`${envArgs} pm2 start ${mainJsPath} --name ${name}${nodeArgsStr} --output ${logPath} --error ${logPath} --merge-logs`, { stdio: "inherit", env: { ...process.env, ...envVars } });
|
|
10765
10822
|
return name;
|
|
10766
10823
|
},
|
|
10767
10824
|
isRunning() {
|
|
@@ -10817,63 +10874,6 @@ async function waitForExit(pm, intervalMs, maxWaitMs) {
|
|
|
10817
10874
|
return false;
|
|
10818
10875
|
}
|
|
10819
10876
|
|
|
10820
|
-
// src/server-info.js
|
|
10821
|
-
import fs5 from "node:fs";
|
|
10822
|
-
import path4 from "node:path";
|
|
10823
|
-
import { execSync as execSync3 } from "node:child_process";
|
|
10824
|
-
function resolve(overrideBinPath) {
|
|
10825
|
-
let binPath;
|
|
10826
|
-
if (overrideBinPath) {
|
|
10827
|
-
binPath = overrideBinPath;
|
|
10828
|
-
} else {
|
|
10829
|
-
try {
|
|
10830
|
-
binPath = execSync3("which caw-server", { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
10831
|
-
} catch {
|
|
10832
|
-
return null;
|
|
10833
|
-
}
|
|
10834
|
-
if (!binPath)
|
|
10835
|
-
return null;
|
|
10836
|
-
}
|
|
10837
|
-
let realPath;
|
|
10838
|
-
try {
|
|
10839
|
-
realPath = fs5.realpathSync(binPath);
|
|
10840
|
-
} catch {
|
|
10841
|
-
return null;
|
|
10842
|
-
}
|
|
10843
|
-
let dir = path4.dirname(realPath);
|
|
10844
|
-
let packageRoot = null;
|
|
10845
|
-
for (let i = 0;i < 10; i++) {
|
|
10846
|
-
const candidate = path4.join(dir, "package.json");
|
|
10847
|
-
if (fs5.existsSync(candidate)) {
|
|
10848
|
-
try {
|
|
10849
|
-
const pkg = JSON.parse(fs5.readFileSync(candidate, "utf8"));
|
|
10850
|
-
if (pkg.name === "@kelceyp/caw-server") {
|
|
10851
|
-
packageRoot = dir;
|
|
10852
|
-
break;
|
|
10853
|
-
}
|
|
10854
|
-
} catch {}
|
|
10855
|
-
}
|
|
10856
|
-
const parent = path4.dirname(dir);
|
|
10857
|
-
if (parent === dir)
|
|
10858
|
-
break;
|
|
10859
|
-
dir = parent;
|
|
10860
|
-
}
|
|
10861
|
-
if (!packageRoot)
|
|
10862
|
-
return null;
|
|
10863
|
-
const packageJsonPath = path4.join(packageRoot, "package.json");
|
|
10864
|
-
let version;
|
|
10865
|
-
try {
|
|
10866
|
-
const pkg = JSON.parse(fs5.readFileSync(packageJsonPath, "utf8"));
|
|
10867
|
-
version = pkg.version;
|
|
10868
|
-
} catch {
|
|
10869
|
-
return null;
|
|
10870
|
-
}
|
|
10871
|
-
const mainJsPath = path4.join(packageRoot, "dist", "main.js");
|
|
10872
|
-
if (!fs5.existsSync(mainJsPath))
|
|
10873
|
-
return null;
|
|
10874
|
-
return { mainJsPath, version, packageRoot };
|
|
10875
|
-
}
|
|
10876
|
-
|
|
10877
10877
|
// src/commands/start.js
|
|
10878
10878
|
function resolveEnvDir(rawEnvDir) {
|
|
10879
10879
|
if (rawEnvDir.startsWith("~")) {
|
|
@@ -11643,6 +11643,10 @@ if (!globalCheck.ok) {
|
|
|
11643
11643
|
console.error(globalCheck.message);
|
|
11644
11644
|
process.exit(1);
|
|
11645
11645
|
}
|
|
11646
|
-
var LAUNCHER_VERSION = "1.0.
|
|
11647
|
-
var
|
|
11646
|
+
var LAUNCHER_VERSION = "1.0.15";
|
|
11647
|
+
var serverInfo = resolve();
|
|
11648
|
+
var serverVersion = serverInfo ? serverInfo.version : "not installed";
|
|
11649
|
+
var versionString = `Launcher: ${LAUNCHER_VERSION}
|
|
11650
|
+
Server: ${serverVersion}`;
|
|
11651
|
+
var app = create().name("caw").version(versionString).command(start_default.create()).command(stop_default.create()).command(status_default.create()).command(logs_default.create()).command(upgrade_default.create());
|
|
11648
11652
|
await app.run(process.argv.slice(2));
|