UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

53 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readConfig = void 0; const fs_1 = require("fs"); // eslint-disable-next-line @typescript-eslint/no-require-imports const tsx = require("tsx/cjs/api"); const yaml_1 = require("yaml"); // allows us to load ts files const fullPath = (directory, ext) => directory + "/catladder." + ext; const readConfigInternal = async (directory = process.cwd()) => { const found = ["ts", "js", "yml", "yaml"].find((extension) => (0, fs_1.existsSync)(fullPath(directory, extension))); if (found) { const filePath = fullPath(directory, found); if (found === "ts" || found === "js") { const result = await tsx.require(filePath, directory); // weird: if target project is esm, result is under result.default, but if its commonjs, its under result.default.default const config = result.default.default || result.default; return { path: filePath, ext: found, config, }; } else { return { path: filePath, ext: found, config: (0, yaml_1.parse)((0, fs_1.readFileSync)(filePath, { encoding: "utf-8" })), }; } } return null; }; const readConfig = async (directory = process.cwd()) => { try { return await readConfigInternal(directory); } catch (error) { console.error(`Error reading config in ${directory}:`, error); console.error(` This may happen due to various reasons: - Syntax errors in your catladder.ts file - tsx (the TypeScript loader used by catladder) needs to understand the syntax in your project. If your project uses newer TypeScript/JavaScript syntax, you may need to update catladder to get a newer version of tsx that supports it. - Missing or incorrect dependencies in your project - TypeScript configuration issues in your tsconfig.json `); return null; } }; exports.readConfig = readConfig; //# sourceMappingURL=readConfig.js.map