build-plugin-rax-app
Version:
The basic webpack configuration for rax project
57 lines • 2.53 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var path = require('path');
var fs = require('fs-extra');
var formatPath = require('@builder/app-helpers').formatPath;
var _a = require('../constants'), STATIC_CONFIG = _a.STATIC_CONFIG, TAB_BAR_PATH = _a.TAB_BAR_PATH;
module.exports = function (api) {
var setValue = api.setValue, getValue = api.getValue, context = api.context, applyMethod = api.applyMethod;
var rootDir = context.rootDir, userConfig = context.userConfig;
var staticConfig;
try {
staticConfig = JSON.parse(fs.readFileSync(path.join(rootDir, 'src/app.json')));
}
catch (err) {
throw new Error('There need app.json in root dir.');
}
if (staticConfig.tabBar) {
var tabBarPath_1;
if (staticConfig.tabBar.custom) {
tabBarPath_1 = path.join(rootDir, 'src/components/CustomTabBar/index');
if (!checkComponentFileExists(tabBarPath_1)) {
tabBarPath_1 = path.join(rootDir, 'src/CustomTabBar/index');
if (!checkComponentFileExists(tabBarPath_1)) {
throw new Error('There need custom tab bar implement in src/components/CustomTabBar/index.jsx');
}
}
if (!Array.isArray(staticConfig.tabBar.list)) {
throw new Error('There should have list field as array type to know which page need show tab bar');
}
staticConfig.tabBar.source = tabBarPath_1.replace("".concat(rootDir, "/src"), '');
}
else {
tabBarPath_1 = path.join(getValue('TEMP_PATH'), 'plugins/app/TabBar');
}
tabBarPath_1 = formatPath(tabBarPath_1);
setValue(TAB_BAR_PATH, tabBarPath_1);
if (!userConfig.mpa) {
applyMethod('modifyRenderData', function (renderData) {
return __assign(__assign({}, renderData), { tabBarPath: tabBarPath_1 });
});
}
}
setValue(STATIC_CONFIG, staticConfig);
};
function checkComponentFileExists(filepath) {
return ['jsx', 'js', 'tsx'].some(function (ext) { return fs.existsSync("".concat(filepath, ".").concat(ext)); });
}
//# sourceMappingURL=setStaticConfig.js.map