|
@@ -1,21 +1,30 @@
|
|
|
/* eslint-disable */
|
|
|
var fs = require('fs')
|
|
|
-var path = require('path');
|
|
|
+var path = require('path')
|
|
|
|
|
|
var config = {
|
|
|
- // urlBefore: 'res://app2-jytest.jianyu360.cn',
|
|
|
- urlBefore: 'res://app-i1.jianyu360.com',
|
|
|
+ projectPath: path.resolve(__dirname),
|
|
|
+ filePath: '/datareport/',
|
|
|
+ templateName: 'index.html',
|
|
|
urlLocal: '/jyapp/local',
|
|
|
- readFile: '/datareport/index.html',
|
|
|
- writeFile: '/datareport/index_app.html'
|
|
|
+ output: [
|
|
|
+ {
|
|
|
+ origin: 'res://app-i1.jianyu360.com',
|
|
|
+ fileName: 'index_i1.html'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ origin: 'res://app2-jytest.jianyu360.cn',
|
|
|
+ fileName: 'index_app2.html'
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
|
|
|
-var filePath=path.resolve(__dirname);
|
|
|
-
|
|
|
-fs.readFile(filePath + config.readFile,'utf8',function(err,files){
|
|
|
- var result = files.replace(/\/datareport\//g, config.urlBefore + '/datareport/');
|
|
|
- result = result.replace(/script(.*?)src=(.*?)\d\/(.*?).min.js/g, `script$1src=${config.urlBefore}${config.urlLocal}/$3.min.js`);
|
|
|
- fs.writeFile(filePath + config.writeFile, result, 'utf8', function (err) {
|
|
|
- if (err) return console.log(err);
|
|
|
- });
|
|
|
+fs.readFile(`${config.projectPath}${config.filePath}${config.templateName}`, 'utf8', function(err, files) {
|
|
|
+ config.output.forEach(function (item, index) {
|
|
|
+ let replaced = files.replace(new RegExp(`${config.filePath}`, 'g'), `${item.origin}${config.filePath}`)
|
|
|
+ replaced = replaced.replace(/script(.*?)src=\/(.*)\/(.*).min.js/g, `script$1src=${item.origin}${config.urlLocal}/$3.min.js`)
|
|
|
+ fs.writeFileSync(`${config.projectPath}${config.filePath}${item.fileName}`, replaced, 'utf8', function (err) {
|
|
|
+ if (err) return console.log(err)
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|