Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
const CLI_STATE_DIR_NAME = "netcatty-tool-cli";
|
|
const TOOL_CLI_DISCOVERY_ENV_VAR = "NETCATTY_TOOL_CLI_DISCOVERY_FILE";
|
|
const FALLBACK_APP_DATA_DIR_NAME = "netcatty";
|
|
|
|
function toUnpackedAsarPath(filePath) {
|
|
return filePath.replace(/app\.asar([\\/])/, "app.asar.unpacked$1");
|
|
}
|
|
|
|
function getDefaultAppDataDirName() {
|
|
const packageJsonPaths = [
|
|
process.resourcesPath ? path.join(process.resourcesPath, "app.asar", "package.json") : null,
|
|
path.resolve(__dirname, "../../package.json"),
|
|
path.join(process.cwd(), "package.json"),
|
|
].filter(Boolean);
|
|
|
|
for (const packageJsonPath of packageJsonPaths) {
|
|
try {
|
|
const packageJson = require(packageJsonPath);
|
|
if (typeof packageJson?.name === "string" && packageJson.name) {
|
|
return packageJson.name;
|
|
}
|
|
} catch {
|
|
// Try the next location.
|
|
}
|
|
}
|
|
|
|
return FALLBACK_APP_DATA_DIR_NAME;
|
|
}
|
|
|
|
function getDefaultUserDataDir() {
|
|
const appDataDirName = getDefaultAppDataDirName();
|
|
if (process.platform === "darwin") {
|
|
return path.join(os.homedir(), "Library", "Application Support", appDataDirName);
|
|
}
|
|
if (process.platform === "win32") {
|
|
const appData = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
return path.join(appData, appDataDirName);
|
|
}
|
|
const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
|
|
return path.join(xdgConfigHome, appDataDirName);
|
|
}
|
|
|
|
function getConfiguredDiscoveryFilePath() {
|
|
return process.env[TOOL_CLI_DISCOVERY_ENV_VAR] || null;
|
|
}
|
|
|
|
function getToolCliStateDir(options = {}) {
|
|
const discoveryFilePath = getConfiguredDiscoveryFilePath();
|
|
if (discoveryFilePath) {
|
|
return path.dirname(discoveryFilePath);
|
|
}
|
|
const userDataDir = typeof options.userDataDir === "string" && options.userDataDir
|
|
? options.userDataDir
|
|
: getDefaultUserDataDir();
|
|
return path.join(userDataDir, CLI_STATE_DIR_NAME);
|
|
}
|
|
|
|
function getCliDiscoveryFilePath(options = {}) {
|
|
const discoveryFilePath = getConfiguredDiscoveryFilePath();
|
|
if (discoveryFilePath) {
|
|
return discoveryFilePath;
|
|
}
|
|
return path.join(getToolCliStateDir(options), "discovery.json");
|
|
}
|
|
|
|
function getCliLauncherPath() {
|
|
const fileName = process.platform === "win32"
|
|
? "netcatty-tool-cli.cmd"
|
|
: "netcatty-tool-cli";
|
|
return toUnpackedAsarPath(path.join(__dirname, fileName));
|
|
}
|
|
|
|
module.exports = {
|
|
getToolCliStateDir,
|
|
getCliDiscoveryFilePath,
|
|
getCliLauncherPath,
|
|
TOOL_CLI_DISCOVERY_ENV_VAR,
|
|
};
|