UNPKG

accelerator-build-engine

Version:
182 lines (146 loc) 5.41 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _isEmpty = require('lodash/isEmpty'); var _isEmpty2 = _interopRequireDefault(_isEmpty); var _assignIn = require('lodash/assignIn'); var _assignIn2 = _interopRequireDefault(_assignIn); var _forEach = require('lodash/forEach'); var _forEach2 = _interopRequireDefault(_forEach); var _isPlainObject = require('lodash/isPlainObject'); var _isPlainObject2 = _interopRequireDefault(_isPlainObject); var _isString = require('lodash/isString'); var _isString2 = _interopRequireDefault(_isString); var _configs = require('../configs'); var _constants = require('../constants'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } const getEnvConfig = (env = _constants.ENV.DEV) => env === _constants.ENV.PROD ? _configs.production : _configs.development; const getEnvWebpack = (env = _constants.ENV.DEV) => env === _constants.ENV.PROD ? _configs.packProdConfigs : _configs.packDevConfigs; const getJourneys = (env = _constants.ENV.DEV) => { const configs = getEnvConfig(env); return configs.journeys || []; }; const isJourneyActive = (env = _constants.ENV.DEV) => { const configs = getEnvConfig(env); return configs.journeys.length > 1; }; const getBrands = (env = _constants.ENV.DEV) => { const configs = getEnvConfig(env); return configs.brands || []; }; const isBrandActive = (env = _constants.ENV.DEV) => { const configs = getEnvConfig(env); return configs.brands.length > 0; }; const getJourneyConfig = (env = _constants.ENV.DEV, journey = '') => { const configs = getEnvConfig(env); return configs[journey] || {}; }; const updateProperties = (oldProps = {}, newProps = {}) => { if ((0, _isEmpty2['default'])(oldProps) && (0, _isEmpty2['default'])(newProps)) { return null; } return (0, _assignIn2['default'])(oldProps, newProps); }; const isValidPath = (path = '') => { if ((0, _isEmpty2['default'])(path)) { return false; } try { const stats = _fs2['default'].lstatSync(path); return stats.isDirectory(); } catch (e) { return false; } }; const getFolderFilePath = (env = _constants.ENV.DEV, journey = '') => { const journeyConfig = getJourneyConfig(env, journey); const outputProps = journeyConfig.output || {}; return outputProps.foldersFilesMap || {}; }; const getOutputPath = (data = {}, path = {}, outputPath = []) => { if ((0, _isEmpty2['default'])(data)) { return outputPath; } (0, _forEach2['default'])(data, (prop, key) => { if ((0, _isPlainObject2['default'])(prop)) { const param = path.name || ''; getOutputPath(prop, { name: `${param}${key}/` }, outputPath); } else if ((0, _isString2['default'])(prop) && key !== 'styles') { const param = path.name || ''; outputPath.push({ path: `${param}${prop}`, ref: key }); } }); return outputPath; }; const getStyleOutputPath = (data = {}, path = {}, outputPath = []) => { if ((0, _isEmpty2['default'])(data)) { return outputPath; } (0, _forEach2['default'])(data, (prop, key) => { if ((0, _isPlainObject2['default'])(prop)) { const param = path.name || ''; getStyleOutputPath(prop, { name: `${param}${key}/` }, outputPath); } else if ((0, _isString2['default'])(prop) && key === 'styles') { const param = path.name || ''; outputPath.push({ path: `${param}${prop}`, ref: key }); } }); return outputPath; }; const getVersionFilename = (env = _constants.ENV.PROD, basePath = '') => { if (env === _constants.ENV.DEV) { return ''; } const rootPath = (0, _isEmpty2['default'])(basePath) ? '' : `${basePath}/`; const filePath = `${rootPath}${_constants.CLI_PATH.RELEASE_PATH}${_constants.DEFAULT_VALUE.VERSION_NAME}`; return _path2['default'].resolve(process.cwd(), filePath); }; const getJourneyBrandPath = (isActive, journey, brand) => { const journeyPath = isActive && !(0, _isEmpty2['default'])(journey) ? `${journey}/` : ''; const brandPath = (0, _isEmpty2['default'])(brand) ? '' : `${brand}`; return `${journeyPath}${brandPath}`; }; const getBaseOutputPath = (env = _constants.ENV.DEV, journey = '', brand = '') => { const configs = getEnvConfig(env); const journeyBrandPath = getJourneyBrandPath(isJourneyActive(env), journey, brand); const subpath = (0, _isEmpty2['default'])(journeyBrandPath) ? '' : `/${journeyBrandPath}`; const rootPath = _path2['default'].resolve(process.cwd(), `${configs.output.root}`); return `${rootPath}${subpath}`; }; const getReleaseVersionPath = (env = _constants.ENV.PROD) => { const configs = getEnvConfig(env); const path = env === _constants.ENV.DEV ? '' : `${_constants.CLI_PATH.RELEASE_PATH}`; return env === _constants.ENV.PROD && !configs.noHash ? `${path}[hash]/` : path; }; exports['default'] = { getEnvConfig, getEnvWebpack, getJourneyConfig, isJourneyActive, isBrandActive, getJourneys, getBrands, updateProperties, isValidPath, getFolderFilePath, getStyleOutputPath, getOutputPath, getReleaseVersionPath, getVersionFilename, getBaseOutputPath, getJourneyBrandPath }; module.exports = exports['default']; //# sourceMappingURL=common.js.map