@intlayer/config
Version:
Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.
59 lines • 2.35 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var searchConfigurationFile_exports = {};
__export(searchConfigurationFile_exports, {
searchConfigurationFile: () => searchConfigurationFile
});
module.exports = __toCommonJS(searchConfigurationFile_exports);
var import_fs = require("fs");
var import_path = require("path");
var import_logger = require('../logger.cjs');
const EXTENSION = ["ts", "js", "json", "cjs", "mjs", ""];
const CONFIGURATION_FILE_NAME_1 = "intlayer.config";
const CONFIGURATION_FILE_NAME_2 = ".intlayerrc";
const intLayerConfigFiles = EXTENSION.filter(
(extension) => extension !== ""
).map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`);
const configurationFiles = [...intLayerConfigFiles, CONFIGURATION_FILE_NAME_2];
const searchConfigurationFile = (configFilePath = process.cwd()) => {
let configurationFilePath = void 0;
let numCustomConfiguration = 0;
for (const fileName of configurationFiles) {
try {
const filePath = (0, import_path.resolve)(configFilePath, fileName);
if (!(0, import_fs.existsSync)(filePath)) {
continue;
} else {
numCustomConfiguration += 1;
if (!configurationFilePath) {
configurationFilePath = filePath;
}
}
} catch (error) {
(0, import_logger.logger)(`${fileName}: ${error}`, { level: "error" });
continue;
}
}
return { configurationFilePath, numCustomConfiguration };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
searchConfigurationFile
});
//# sourceMappingURL=searchConfigurationFile.cjs.map