@intlayer/config
Version:
Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.
99 lines • 4.01 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var getConfiguration_exports = {};
__export(getConfiguration_exports, {
getConfiguration: () => getConfiguration
});
module.exports = __toCommonJS(getConfiguration_exports);
var import_deepmerge = __toESM(require("deepmerge"));
var import_path = require("path");
var import_logger = require('../logger.cjs');
var import_buildConfigurationFields = require('./buildConfigurationFields.cjs');
var import_loadConfigurationFile = require('./loadConfigurationFile.cjs');
var import_searchConfigurationFile = require('./searchConfigurationFile.cjs');
let storedConfiguration;
let storedConfigurationFilePath;
let storedNumCustomConfiguration;
const BASE_DIR_PATH = process.cwd();
const getConfiguration = (options) => {
const mergedOptions = {
baseDir: BASE_DIR_PATH,
...options
};
const { baseDir, env, envFile } = mergedOptions;
if (!storedConfiguration || typeof options !== "undefined") {
const { configurationFilePath, numCustomConfiguration } = (0, import_searchConfigurationFile.searchConfigurationFile)(baseDir);
let customConfiguration;
if (configurationFilePath) {
customConfiguration = (0, import_loadConfigurationFile.loadConfigurationFile)(configurationFilePath, {
env,
envFile
});
}
storedConfiguration = (0, import_buildConfigurationFields.buildConfigurationFields)(
customConfiguration,
baseDir
);
storedConfigurationFilePath = configurationFilePath;
storedNumCustomConfiguration = numCustomConfiguration;
}
if (options?.override?.log?.mode === "verbose") {
logConfigFileResult(
storedNumCustomConfiguration,
storedConfigurationFilePath
);
}
return (0, import_deepmerge.default)(storedConfiguration, options?.override ?? {});
};
const logConfigFileResult = (numCustomConfiguration, configurationFilePath) => {
if (numCustomConfiguration === 0) {
(0, import_logger.logger)("Configuration file not found, using default configuration.", {
isVerbose: true
});
} else {
const relativeOutputPath = (0, import_path.relative)(BASE_DIR_PATH, configurationFilePath);
if (numCustomConfiguration === 1) {
(0, import_logger.logger)(`Configuration file found: ${relativeOutputPath}.`, {
isVerbose: true
});
} else {
(0, import_logger.logger)(
`Multiple configuration files found, using ${relativeOutputPath}.`,
{
isVerbose: true
}
);
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getConfiguration
});
//# sourceMappingURL=getConfiguration.cjs.map