copyStatics.js 864 B

1234567891011121314151617181920212223242526272829303132333435
  1. const fs = require('fs');
  2. const ncp = require('ncp').ncp;
  3. const { version } = require('../package.json');
  4. const sourcePath = './static';
  5. const destinationPath = './dist/static'
  6. const appPath = `${destinationPath}/App.js`;
  7. const replacementMap = [
  8. { regexp: /#_version_/g, replacement: version }
  9. ];
  10. ncp(sourcePath, destinationPath, function (err) {
  11. if (err) {
  12. return console.error(err);
  13. }
  14. applyGlobals();
  15. });
  16. function applyGlobals() {
  17. fs.readFile(appPath, 'utf8', function (err, data) {
  18. if (err) {
  19. return console.error(`Unable to read file ${filePath}: ` + err);
  20. }
  21. for(const replacement of replacementMap) {
  22. data = data.replace(replacement.regexp, replacement.replacement);
  23. }
  24. fs.writeFile(appPath, data, 'utf8', function (err) {
  25. if (err) return console.error('Unable to write file: ' + err);
  26. });
  27. });
  28. }