2022-05-15 09:35:59 +03:00
|
|
|
import fs from 'fs';
|
2022-02-27 22:10:10 +03:00
|
|
|
|
|
|
|
function replaceVersionPlaceholder(version) {
|
2022-12-24 13:34:39 +03:00
|
|
|
const staticJsFilesPath = './build/assets';
|
2022-02-27 22:10:10 +03:00
|
|
|
const versionPlaceholder = '%_VERSION_%';
|
|
|
|
|
2022-12-24 13:34:39 +03:00
|
|
|
const isMainFile = (file) => file.startsWith('index-') && file.endsWith('.js');
|
|
|
|
const [mainJsFile] = fs.readdirSync(staticJsFilesPath).filter(isMainFile);
|
2022-02-27 22:10:10 +03:00
|
|
|
const filePath = `${staticJsFilesPath}/${mainJsFile}`;
|
|
|
|
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
|
|
const replaced = fileContent.replace(versionPlaceholder, version);
|
|
|
|
|
|
|
|
fs.writeFileSync(filePath, replaced, 'utf-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
const version = process.env.VERSION;
|
|
|
|
|
|
|
|
if (version) {
|
|
|
|
replaceVersionPlaceholder(version);
|
|
|
|
}
|