UNPKG

ffbt

Version:

Build a Typescript app without pain

60 lines (59 loc) 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProjectConfig = void 0; const tslib_1 = require("tslib"); const prop_1 = require("../core/prop"); const default_1 = require("./default"); const lodash_1 = require("lodash"); const environment_registry_1 = require("../core/environment-registry"); const locate_1 = require("../core/locate"); const paths_1 = require("./paths"); const CONFIG_FILE_NAME = "ffbt-config.js"; class ProjectConfig { constructor(sourcesDirectory, projectConfig = {}, defaults = default_1.defaultConfig) { this.sourcesDirectory = sourcesDirectory; this.environments = new environment_registry_1.EnvironmentRegistry(); this.currentEnvName = "default"; this.props = lodash_1.merge({}, defaults, projectConfig); this.fixIncorrectConfigValuesForWebpack(); this.environments.addMany(this.props.environments); this.paths = new paths_1.ProjectPaths(this); } setCurrentEnvironmentName(currentEnvName) { this.currentEnvName = currentEnvName; } get env() { return this.environments.get(this.currentEnvName); } overrideEnvironmentSettings(optionsWithValue) { lodash_1.merge(this.env, optionsWithValue); } // Normalize some values that seems to be correct but webpack interprets them as incorrect fixIncorrectConfigValuesForWebpack() { const noParse = this.env.noParse; const noParseIsEmptyArray = Array.isArray(noParse) && !noParse.length; const noParseIsNull = noParse === null; if (noParseIsEmptyArray || noParseIsNull) { this.env.noParse = undefined; } } static getPathToConfigFile(sourcesDirectory) { return locate_1.locateFile(CONFIG_FILE_NAME, sourcesDirectory, false) || null; } static loadFromFile(sourcesDirectory) { const configPath = this.getPathToConfigFile(sourcesDirectory); if (!configPath) { // It's OK if we can't find the config, just create it from default values return new this(sourcesDirectory); } const config = require(configPath); return new this(sourcesDirectory, config); } } tslib_1.__decorate([ prop_1.Prop() ], ProjectConfig.prototype, "configureWebpack", void 0); tslib_1.__decorate([ prop_1.Prop() ], ProjectConfig.prototype, "disableWebpackLayers", void 0); exports.ProjectConfig = ProjectConfig;