@omni-door/cli
Version:
A tool set for set up the standard JS project
23 lines (22 loc) • 2.83 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
function default_1(config) {
var multiOutput = config.multiOutput, _a = config.srcDir, srcDir = _a === void 0 ? path_1.default.resolve(__dirname, '../src/') : _a, _b = config.outDir, outDir = _b === void 0 ? path_1.default.resolve(__dirname, '../lib/') : _b, configurationPath = config.configurationPath, _c = config.pkjFieldName, pkjFieldName = _c === void 0 ? 'omni' : _c, _d = config.configFileName, configFileName = _d === void 0 ? 'omni.config.js' : _d, hash = config.hash;
var hashType = typeof hash === 'string'
? hash
: hash
? 'contenthash'
: hash;
return "'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\nconst { requireCwd } = require('@omni-door/utils');\nconst merge = requireCwd('webpack-merge');\n\nconst ppkj = requireCwd('./package.json');\nconst configFilePath = (ppkj && ppkj." + pkjFieldName + " && ppkj." + pkjFieldName + ".filePath) || './" + configFileName + "';\nconst configs = requireCwd(configFilePath);\n" + (configurationPath ? "const customConfig = require('" + configurationPath + "')" : '') + "\n\nconst { build } = configs || {};\nconst { configuration = config => config } = build || {};\n\n" + (multiOutput
? "const entriesPath = '" + srcDir + "';\nconst entriesList = getFolders(entriesPath);\n\nfunction getFolders (folderPath) {\n const list = fs.readdirSync(folderPath)\n const folderList = list.filter((v, k) => {\n const stats = fs.statSync(`${folderPath}/${v}`);\n return stats.isDirectory();\n })\n return folderList;\n}"
: '') + "\n\nlet indexPath = '';\nconst exts = ['ts', 'tsx', 'js', 'jsx'];\nfor (let i = 0, len = exts.length; i < len; i++) {\n indexPath = path.resolve('" + srcDir + "', `index.${exts[i]}`);\n if (fs.existsSync(indexPath)) break;\n}\nconst entry = {\n index: indexPath\n};\n\n" + (multiOutput
? "entriesList.forEach(v => {\n if (v !== 'style' && v !== 'styles') {\n let entryPath = '';\n for (let i = 0, len = exts.length; i < len; i++) {\n entryPath = path.resolve('" + srcDir + "', `${v}/index.${exts[i]}`);\n if (fs.existsSync(entryPath)) break;\n }\n entry[v] = entryPath;\n }\n})"
: '') + "\n\nconst basicConfig = {\n entry,\n output: {\n filename: '" + (hashType ? "[name].[" + hashType + ":8].js" : '[name].js') + "',\n path: '" + outDir + "'\n },\n mode: 'production'\n};\n\nmodule.exports = " + (configurationPath
? 'merge(basicConfig, customConfig);'
: 'configuration(basicConfig);');
}
exports.default = default_1;