UNPKG

ecology9-src4js-tools

Version:

src4js-tools

70 lines (61 loc) 2.33 kB
'use strict'; process.env.BABEL_ENV = 'production'; process.env.NODE_ENV = 'production'; process.on('unhandledRejection', err => { throw err; }); const fs = require('fs-extra'); const paths = require('../config/paths-html'); const chalk = require('chalk'); const versions = require('../versions'); const versionsCom = require('../versionsCom'); const v = versionsCom.concat(versions); const buildHtml = []; paths.forEach(setting => { if (setting.appHtml && setting.htmlName && setting.servedPath && setting.appBuild) { const htmlPath = setting.htmlName; const js = setting.jsName ? setting.servedPath + setting.jsName : ''; const jsSingle = setting.jsSingleName ? setting.servedPath + setting.jsSingleName : ''; if (setting.ecPath) { buildHtml.push(htmlPath.replace(setting.ecPath, '')); if (setting.copyFiles && Array.isArray(setting.copyFilesPath)) { setting.copyFilesPath.forEach(copyFile => { if (htmlPath === copyFile.from) { buildHtml.push(copyFile.to.replace(setting.ecPath, '')); } }); } } fs.readFile(htmlPath, { encoding: 'utf8' },(err, data) => { if(err) return; let oldData = data; console.log(htmlPath); if (oldData) { v.forEach(obj => { // oldData = oldData.replace(new RegExp(`\\"${obj.key}[^\\"]*\\"`, 'g'), `"${obj.src}"`); // if (obj.key === js && jsSingle) { // oldData = oldData.replace(new RegExp(`\\"${jsSingle}[^\\"]*\\"`, 'g'), `"${jsSingle}?v=${obj.version}"`); // } oldData = oldData.replace(new RegExp('jquery-1.8.3.min.js', 'g'), 'jquery-1.12.4.min.js'); }); } fs.writeFile(htmlPath, oldData, { 'flag': 'w' }, function(err) { if(err) return; if (setting.copyFiles && Array.isArray(setting.copyFilesPath)) { setting.copyFilesPath.forEach(copyFile => { if (htmlPath === copyFile.from) { fs.copy(copyFile.from, copyFile.to, err => { if (err) { console.log(chalk.red('Failed to copy files.\n')); printBuildError(err); } else { // console.log('File has been copied.'); } }) } }); } }) }); } });