ala-cli
Version:
aladdin develop utils
69 lines (54 loc) • 1.71 kB
JavaScript
/**
*
* @file fis3编译:vue -> php/js/smarty
* @author chenrui09
* @date 2017/5/4
*
*/
const fs = require('fs-extra');
const path = require('path');
let dirRoot = process.cwd();
let appConf = require(path.join(dirRoot, 'app.conf'));
let buildConf = appConf.build;
let buildPath = path.join(appConf.dest, buildConf.path);
let pluginsPath = '../plugins/';
let modules = appConf.modules;
let rules = buildConf.rules;
fs.ensureDirSync(buildPath);
// 默认不执行编译
fis.match('**', {
release: false
});
// 识别vue格式文件
fis.set('project.fileType.text', 'vue');
// 动态规则匹配
for (let key in rules) {
let rule = rules[key];
let ruleModule = modules[rule.module];
let fisMatch = path.normalize(ruleModule + '/(' + rule.match + ')');
let fisParams = {};
fisParams.release = rule.release ? rule.release : '$0';
if (rule.plugins && rule.plugins.length) {
let plugins = [];
rule.plugins.forEach(function (plg) {
let handler;
// 判断是否有路径匹配符
if (/\//.test(plg)) {
handler = require(path.join(dirRoot, plg));
} else {
handler = require(pluginsPath + plg);
}
plugins.push(handler);
});
fisParams.parser = plugins;
}
fis.match(fisMatch, fisParams);
if (rule.exclude && rule.exclude.length) {
rule.exclude.forEach(function (exc) {
let excMatch = path.normalize(ruleModule + '/' + exc + '/**');
fis.match(excMatch, {
release: false
});
});
}
}