UNPKG

ala-cli

Version:

aladdin develop utils

44 lines (35 loc) 1.24 kB
/** * * @file 编译php/js文件插件 * @author chenrui09 * @date 2017/5/8 * */ const fs = require('fs-extra'); const path = require('path'); const vipCompiler = require('../libs/vip-compiler'); let dirRoot = process.cwd(); let appConf = require(path.join(dirRoot, 'app.conf')); let staticPath = path.join(appConf.dest, appConf.build.path, appConf.modules.static); let phpPath = path.join(appConf.dest, appConf.build.path, appConf.modules.php); fs.ensureDirSync(staticPath); fs.ensureDirSync(phpPath); module.exports = (content, file) => { let subpath = file.subpathNoExt.replace(/^\/(((?!\/).)*)\//, ''); let out = path.join(staticPath, subpath + '.js'); let out2 = path.join(phpPath, subpath + '.php'); let dir = path.dirname(out); let dir2 = path.dirname(out2); let result = vipCompiler.cache(file.subpathNoExt, content); if (result) { fs.ensureDirSync(dir); fs.writeFile(out, result.compiled.js); fs.ensureDirSync(dir2); fs.writeFile(out2, result.compiled.php); console.log('编译文件完成: ', subpath); } else { console.log('编译文件失败.', subpath); } return content; };