/** * * @authors Tony.Deng (dengtongyu123@163.com) * @date 2018-05-15 10:55:16 * @version $Id$ */ const path = require('path'); let _pathConfig = null; let _config = { base: 'src', build: 'build' }; exports.initPath = (pathName) => { _pathConfig = {}; _pathConfig.currPath = pathName; //stylus build目录 _pathConfig.styleBuildPath = _config.base + '/pages/' + pathName + '/**/!(_)*.styl'; //swig build目录 _pathConfig.htmlBuildPath = _config.base + '/pages/' + pathName + '/**/*.htm'; //htmlmin build目录 _pathConfig.htmlminBuildPath = _config.build + '/pages/' + pathName + '/**/*.html'; //wabpck build 目录 _pathConfig.scriptBuildPath = _config.base + '/pages/' + pathName + '/index.js'; _pathConfig.babelOutPath = _config.build + '/pages/' + pathName; //uglify build目录 _pathConfig.uglifyBuildPath = _config.build + '/pages/' + pathName + '/index.js'; //tmod build目录 _pathConfig.artBuildPath = _config.base + '/pages/' + pathName + '/**/*.art'; return _pathConfig; } exports.getPathConfig = () => { return _pathConfig; } exports.getConfig = () => { return _config; } //随机路径名 exports.randomActName = () => { let d = new Date(); let m = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1).toString(); let dd = d.getDate() < 10 ? '0' + d.getDate() : d.getDate(); let str = d.getFullYear() + m + dd + String.fromCharCode(Math.floor(Math.random() * 26) + "a".charCodeAt(0)) + Math.floor(Math.random() * 10); return str; } exports.siwgConfig = () => { let url = '../' + _config.base + '/pages/' + _pathConfig.currPath + '/data.json'; delete require.cache[require.resolve(url)] let swigData = require(url); swigData.now = function () { return new Date().getTime() }; return { defaults: { varControls: ['{[', ']}'], cache: false, locals:swigData } }; } exports.pathType = (filePath) => { let type = path.parse(filePath).ext; if (type == '.styl') { return 0; } else if (type == '.htm') { return 1; } else if (type == '.html') { return 2; } else if (type == '.js') { if (filePath.match(/build/ig)) { return 4; } else { return 3; } } else if (type == '.tmod') { return 5; } }