UNPKG

@workflow-manager/runner

Version:

CLI runner for in-memory and markdown workflow orchestration using ATEP-like envelopes

40 lines (39 loc) 1.32 kB
import fs from "node:fs"; import os from "node:os"; import path from "node:path"; function configRoot() { const override = process.env.WORKFLOW_MANAGER_CONFIG_DIR; if (override) { return override; } if (process.platform === "win32") { return path.join(process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming"), "workflow-manager"); } return path.join(os.homedir(), ".config", "workflow-manager"); } export function configFilePath() { return path.join(configRoot(), "config.json"); } export function loadRemoteConfig() { const filePath = configFilePath(); if (!fs.existsSync(filePath)) { return {}; } const raw = fs.readFileSync(filePath, "utf-8"); const parsed = JSON.parse(raw); return typeof parsed === "object" && parsed ? parsed : {}; } export function saveRemoteConfig(config) { const filePath = configFilePath(); fs.mkdirSync(path.dirname(filePath), { recursive: true }); fs.writeFileSync(filePath, `${JSON.stringify(config, null, 2)}\n`, "utf-8"); } export function clearRemoteConfig() { const filePath = configFilePath(); if (fs.existsSync(filePath)) { fs.rmSync(filePath); } } export function resolveAuthToken() { return process.env.WORKFLOW_MANAGER_TOKEN ?? loadRemoteConfig().token; }