UNPKG

@msfw/cli

Version:

Install the package in your project directory with:

52 lines (51 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfigPath = getConfigPath; exports.loadMsfwConfig = loadMsfwConfig; const cosmiconfig_1 = require("cosmiconfig"); const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader"); const utils_1 = require("./utils"); const paths_1 = require("./paths"); const logger_1 = require("./logger"); const constants_1 = require("./constants"); const DEFAULT_CONFIG = { devServer: { host: '0.0.0.0', port: 3000, open: true, hot: true, }, }; const explorer = (0, cosmiconfig_1.cosmiconfigSync)(constants_1.MSFWNAME, { searchPlaces: [`${constants_1.MSFWNAME}.config.ts`, `${constants_1.MSFWNAME}.config.js`, `${constants_1.MSFWNAME}.config.cjs`], loaders: { '.ts': (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(), }, }); function getConfigPath(config) { if (config && (0, utils_1.isString)(config)) { return (0, paths_1.resolveApp)(config); } else { const result = explorer.search(paths_1.appDirectory); if (result === null) { (0, logger_1.log)(`${(0, utils_1.toUpperCase)(constants_1.MSFWNAME)}: Config file not found. check if file exists at root (${constants_1.MSFWNAME}.config.ts, ${constants_1.MSFWNAME}.config.js)`); return ''; } return result.filepath; } } function getConfigAsObject(context) { const configFilePath = context.appConfig; const result = explorer.load(configFilePath); const config = (0, utils_1.isFunction)(result?.config) ? result.config(context) : result?.config; if (!config) { return {}; } return config; } function loadMsfwConfig(context) { const configAsObject = getConfigAsObject(context); const msfwConfig = (0, utils_1.deepMergeWidthArray)({}, DEFAULT_CONFIG, configAsObject); return msfwConfig; }