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
@@ -13,7 +13,7 @@
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/typescript"
|
||||
],
|
||||
"ignorePatterns": ["node_modules", "build"],
|
||||
"ignorePatterns": ["node_modules", "build", "generateVersionFile.cjs"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
|
||||
@@ -13,3 +13,4 @@ tests/**/*.jsx
|
||||
!.yarn/versions
|
||||
.pnp.*
|
||||
.env
|
||||
version.json
|
||||
@@ -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);
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"build": "tsc && vite build && node generateVersionFile.cjs",
|
||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview",
|
||||
"fix:prettier": "prettier --write \"src/**/*.{ts,tsx, js}\"",
|
||||
|
||||
Vendored
+1
@@ -1 +1,2 @@
|
||||
/// <reference types="vite/client" />
|
||||
declare const APP_VERSION: string
|
||||
Reference in new issue
Block a user