UNPKG

ts-packager

Version:
40 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadConfig = void 0; const path_1 = require("path"); function loadConfig(cliArgs, defaults) { // Check for ts-package-config.ts config file let configPath = cliArgs.config; const configDir = process.cwd(); if (!configPath.includes(configDir)) { configPath = (0, path_1.join)(configDir, cliArgs.config); } // Load ts-package-config.ts let file; try { // eslint-disable-next-line @typescript-eslint/no-var-requires file = require(configPath); } catch (e) { throw new Error(`Could not load config file "${configPath}"`); } const checkFileExport = (key) => { if (!(key in file)) { throw new Error(`Config file does not export "${key}"`); } if (typeof file[key] !== 'object') { throw new Error('Config file exported "${key}" is not an object'); } }; checkFileExport('config'); checkFileExport('files'); const fileConfig = file.config; for (const key in fileConfig) { if (!(key in defaults)) { throw new Error('Unknown configuration item ' + key); } } return file; } exports.loadConfig = loadConfig; //# sourceMappingURL=config-loader.js.map