const fs = require('fs'); const ncp = require('ncp').ncp; const { version } = require('../package.json'); const sourcePath = './static'; const destinationPath = './dist/static' const appPath = `${destinationPath}/App.js`; const replacementMap = [ { regexp: /#_version_/g, replacement: version } ]; ncp(sourcePath, destinationPath, function (err) { if (err) { return console.error(err); } applyGlobals(); }); function applyGlobals() { fs.readFile(appPath, 'utf8', function (err, data) { if (err) { return console.error(`Unable to read file ${filePath}: ` + err); } for(const replacement of replacementMap) { data = data.replace(replacement.regexp, replacement.replacement); } fs.writeFile(appPath, data, 'utf8', function (err) { if (err) return console.error('Unable to write file: ' + err); }); }); }