ghostfolio/replace.build.mjs
Thomas Kaul b1340a96e5
Feature/upgrade replace-in-file to version 8.3.0 (#4167)
* Upgrade replace-in-file to version 8.3.0

* Update changelog
2025-01-02 10:50:41 +01:00

38 lines
973 B
JavaScript

import dotenv from 'dotenv';
import { dirname, resolve } from 'path';
import { replaceInFileSync } from 'replace-in-file';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config({
path: resolve(__dirname, '.env')
});
const now = new Date();
const buildTimestamp = `${formatWithTwoDigits(
now.getDate()
)}.${formatWithTwoDigits(
now.getMonth() + 1
)}.${now.getFullYear()} ${formatWithTwoDigits(
now.getHours()
)}:${formatWithTwoDigits(now.getMinutes())}`;
try {
const changedFiles = replaceInFileSync({
files: './dist/apps/client/main.*.js',
from: /{BUILD_TIMESTAMP}/g,
to: buildTimestamp,
allowEmptyPaths: false
});
console.log('Build version set: ' + buildTimestamp);
console.log(changedFiles);
} catch (error) {
console.error('Error occurred:', error);
}
function formatWithTwoDigits(aNumber) {
return aNumber < 10 ? '0' + aNumber : aNumber;
}