/**
* @file utils/global.js
* @copyright @spmhome @_2025
* @author Scott Meesseman @spmeesseman
*//** */
const { existsSync, basename, resolvePath } = require("@spmhome/cmn-utils");
const { SpmhEventEmitter } = require("@spmhome/type-utils");
const cwd = process.cwd(),
isWin32 = process.platform === "win32",
runtimeExists = existsSync(resolvePath(__dirname, "./runtime.js")),
isNodeModule = basename(resolvePath(__dirname, "../..")) === "node_modules",
isDevExec = !isNodeModule && existsSync(resolvePath(__dirname, "../../.spmhrc.json")),
isDevDistExec = runtimeExists && !isNodeModule && existsSync(resolvePath(__dirname, "../.spmhrc.json")),
isGlobalExec= !isDevExec && runtimeExists && existsSync(resolvePath(__dirname, "./runtime.js")),
globalEmitter = new SpmhEventEmitter();
const globalEvent = globalEmitter; // .event;
let baseDir = cwd;
while (!existsSync(resolvePath(baseDir, "node_modules")) && baseDir !== ".")
{ try {
baseDir = resolvePath(baseDir, "..");
}
catch { baseDir = process.cwd(); break; }
}
/**
* @type {IWpwGlobalEnvironment}
*/
const globalEnv = {
cwd,
isWin32,
isDevExec,
globalEvent,
cacheDir: "",
isGlobalExec,
buildCount: 0,
isDevDistExec,
verbose: false
};
module.exports = globalEnv;