MSP-3074 add generateVersionFile function
This commit is contained in:
1 parent
09f4159dc6
commit
f13c1f2677
5 files changed
+37
-2
No files matched your search
@@ -0,0 +1,33 @@
|
||||
const fs = require('fs');
|
||||
const packageJson = require('./package.json');
|
||||
|
||||
function writeJsonFile(filePath, data) {
|
||||
fs.writeFileSync(filePath, JSON.stringify(data));
|
||||
}
|
||||
|
||||
function readHtmlFile(filePath) {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
}
|
||||
|
||||
function writeHtmlFile(filePath, data) {
|
||||
fs.writeFileSync(filePath, data);
|
||||
}
|
||||
|
||||
const welcomePagePath = 'build/index.html';
|
||||
|
||||
let indexHtml = readHtmlFile(welcomePagePath);
|
||||
|
||||
const scriptTagRegex = /<script type="module">window\.AppVersion\s*=\s*'.*';<\/script>/;
|
||||
const scriptTag = `<script type="module">window.AppVersion = '${packageJson.version}';</script>`;
|
||||
indexHtml = indexHtml
|
||||
.replace(scriptTagRegex, '')
|
||||
.replace('</head>', `${scriptTag}</head>`);
|
||||
|
||||
writeHtmlFile(welcomePagePath, indexHtml);
|
||||
|
||||
const versionData = {
|
||||
version: packageJson.version,
|
||||
};
|
||||
|
||||
writeJsonFile('build/version.json', versionData);
|
||||
writeJsonFile('version.json', versionData);
|
||||
Reference in new issue
Block a user