replace_dist.js 742 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const path = require('path');
  3. const fs = require('fs');
  4. const fsPro = require('fs-extra');
  5. console.log('moving frontend asset to egg public dir');
  6. // argv
  7. let distDir = '';
  8. for (let i = 0; i < process.argv.length; i++) {
  9. const tmpArgv = process.argv[i]
  10. if (tmpArgv.indexOf('--dist_dir=') !== -1) {
  11. distDir = tmpArgv.substr(11)
  12. }
  13. }
  14. const sourceDir = path.normalize(distDir);
  15. distDir = path.normalize('./app/public');
  16. // del dir and move
  17. fs.rmdirSync(distDir, {recursive: true});
  18. fsPro.copySync(sourceDir, distDir);
  19. // replace ejs
  20. const sourceFile = path.normalize(distDir + '/index.html');
  21. const distFile = path.normalize( './app/view/index.ejs');
  22. fsPro.copySync(sourceFile, distFile);
  23. console.log('Move over');