@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
52 lines (51 loc) • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.readConfig = void 0;
const fs_1 = require("fs");
const jiti_1 = require("jiti");
const yaml_1 = require("yaml");
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 jiti = (0, jiti_1.createJiti)(directory);
const result = await jiti.import(filePath);
const config = result.default || result;
return {
path: filePath,
ext: found,
config: 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
- The TypeScript loader (jiti) 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.
- Missing or incorrect dependencies in your project
- TypeScript configuration issues in your tsconfig.json
`);
return null;
}
};
exports.readConfig = readConfig;