123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import fs from 'fs';
- import ncp from 'ncp';
- import * as path from 'path';
- import { fileURLToPath } from 'url';
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
- class CopyStaticsTask {
- static SourcePath = './static';
- static DestinationPath = './build/static'
- static AppPath = `${CopyStaticsTask.DestinationPath}/App.js`;
- static start() {
- const pck = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json')).toString());
- const replacementMap = [
- { regexp: /#_version_/g, replacement: pck.version }
- ];
- ncp(CopyStaticsTask.SourcePath, CopyStaticsTask.DestinationPath, function (err) {
- if (err) {
- return console.error(err);
- }
-
- CopyStaticsTask.applyGlobals(replacementMap);
- });
- }
- static applyGlobals(replacementMap) {
- fs.readFile(CopyStaticsTask.AppPath, 'utf8', function (err, data) {
- if (err) {
- return console.error(`Unable to read file ${CopyStaticsTask.AppPath}: ` + err);
- }
-
- for(const replacement of replacementMap) {
- data = data.replace(replacement.regexp, replacement.replacement);
- }
-
- fs.writeFile(CopyStaticsTask.AppPath, data, 'utf8', function (err) {
- if (err) return console.error('Unable to write file: ' + err);
- });
- });
- }
- }
- CopyStaticsTask.start();
|