24 lines
870 B
JavaScript
24 lines
870 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = requireSth;
|
|
const fs_1 = require("fs");
|
|
const lodash_1 = require("oak-domain/lib/utils/lodash");
|
|
const path_1 = require("path");
|
|
function requireSth(prjPath, filePath, dependencies) {
|
|
const depFilePath = (0, path_1.join)(prjPath, filePath);
|
|
let sth;
|
|
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
sth = require((0, path_1.join)(prjPath, filePath)).default;
|
|
}
|
|
const sthExternal = dependencies.map(ele => {
|
|
const depFilePath = (0, path_1.join)(prjPath, 'node_modules', ele, filePath);
|
|
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
return require(depFilePath).default;
|
|
}
|
|
}).filter(ele => !!ele);
|
|
if (sth) {
|
|
sthExternal.push(sth);
|
|
}
|
|
return (0, lodash_1.mergeConcatMany)(sthExternal);
|
|
}
|