UNPKG

pandora

Version:
59 lines 2.01 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const fs_1 = require("fs"); const const_1 = require("../const"); const GlobalConfigProcessor_1 = require("./GlobalConfigProcessor"); const extend = require('extend'); function calcAppName(dir) { let ret; try { const pkg = require(path_1.join(process.cwd(), 'package.json')); ret = pkg.name; } catch (err) { ret = null; } if (!ret && dir) { ret = dir.split('/').slice(-1)[0] || null; } return ret; } exports.calcAppName = calcAppName; function attachEntryParams(command, cliConfig, defaultConfig = {}) { const currentPath = process.cwd(); let pandoraConfig; try { const pandoraAttachConfig = require(`${currentPath}/package.json`)['pandora']; pandoraConfig = pandoraAttachConfig[command] || {}; pandoraConfig['config'] = pandoraConfig['config'] || []; // set global config to environment pandoraConfig['config'].push(process.env[const_1.PANDORA_GLOBAL_CONFIG] || ''); process.env[const_1.PANDORA_GLOBAL_CONFIG] = pandoraConfig['config'].filter((text) => { return !!text; }).join(GlobalConfigProcessor_1.GlobalConfigProcessor.GLOBAL_PACKAGE_SPLIT); } catch (err) { // console.log(err); pandoraConfig = {}; } const sendConfig = extend(true, defaultConfig, pandoraConfig || {}, cliConfig); sendConfig['entry'] = sendConfig['entry'] || currentPath; try { const p = path_1.resolve(sendConfig['entry']); let fd = fs_1.statSync(p); if (fd.isDirectory()) { sendConfig['appDir'] = p; } else if (fd.isFile()) { sendConfig['entryFile'] = p; sendConfig['appDir'] = currentPath; } } catch (err) { console.error(err); } return sendConfig; } exports.attachEntryParams = attachEntryParams; //# sourceMappingURL=Helpers.js.map