mirror of
https://github.com/mempool/mempool.git
synced 2025-04-14 14:59:27 +02:00
Generate config on serve and updated git revision method (#587)
* run generate-config on serve * write the config file only if settings have changed * read the git commit hash from the current branch, not master * git sha is now short by default, no need to trim on the about component
This commit is contained in:
parent
1016586992
commit
4c7d0cd2e5
@ -1,4 +1,5 @@
|
||||
var fs = require('fs');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const CONFIG_FILE_NAME = 'mempool-frontend-config.json';
|
||||
const GENERATED_CONFIG_FILE_NAME = 'generated-config.js';
|
||||
@ -32,12 +33,13 @@ for (setting in configContent) {
|
||||
}
|
||||
|
||||
try {
|
||||
gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
|
||||
const command = 'git rev-parse --short HEAD';
|
||||
gitCommitHash = execSync(command).toString('utf8').replace(/[\n\r\s]+$/, '');
|
||||
} catch (e) {
|
||||
console.log('Could not load git commit info: ' + e.message || e);
|
||||
}
|
||||
|
||||
const code = `(function (window) {
|
||||
const newConfig = `(function (window) {
|
||||
window.__env = window.__env || {};${settings.reduce((str, obj) => `${str}
|
||||
window.__env.${obj.key} = ${ typeof obj.value === 'string' ? `'${obj.value}'` : obj.value };`, '')}
|
||||
window.__env.GIT_COMMIT_HASH = '${gitCommitHash}';
|
||||
@ -45,9 +47,17 @@ const code = `(function (window) {
|
||||
}(global || this));`;
|
||||
|
||||
try {
|
||||
fs.writeFileSync(GENERATED_CONFIG_FILE_NAME, code, 'utf8');
|
||||
const currentConfig = fs.readFileSync(GENERATED_CONFIG_FILE_NAME).toString().trim();
|
||||
if (currentConfig === newConfig) {
|
||||
console.log("Configuration not changed, skipping generation");
|
||||
} else {
|
||||
try {
|
||||
fs.writeFileSync(GENERATED_CONFIG_FILE_NAME, newConfig, 'utf8');
|
||||
console.log('Config file generated');
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
||||
console.log('Config file generated');
|
@ -24,9 +24,9 @@
|
||||
"tsc": "./node_modules/typescript/bin/tsc",
|
||||
"i18n-extract-from-source": "./node_modules/@angular/cli/bin/ng xi18n --ivy --out-file ./src/locale/messages.xlf",
|
||||
"i18n-pull-from-transifex": "tx pull -a --parallel --minimum-perc 1 --force",
|
||||
"serve": "ng serve -c local",
|
||||
"serve:stg": "ng serve -c staging",
|
||||
"serve:local-prod": "ng serve -c local-prod",
|
||||
"serve": "npm run generate-config && ng serve -c local",
|
||||
"serve:stg": "npm run generate-config && ng serve -c staging",
|
||||
"serve:local-prod": "npm run generate-config && ng serve -c local-prod",
|
||||
"start": "npm run generate-config && npm run sync-assets-dev && ng serve -c local",
|
||||
"start:stg": "npm run generate-config && npm run sync-assets-dev && ng serve -c staging",
|
||||
"start:local-prod": "npm run generate-config && npm run sync-assets-dev && ng serve -c local-prod",
|
||||
|
@ -17,7 +17,7 @@ export class AboutComponent implements OnInit {
|
||||
backendInfo$: Observable<IBackendInfo>;
|
||||
sponsors$: Observable<any>;
|
||||
contributors$: Observable<any>;
|
||||
frontendGitCommitHash = this.stateService.env.GIT_COMMIT_HASH.substr(0, 8);
|
||||
frontendGitCommitHash = this.stateService.env.GIT_COMMIT_HASH;
|
||||
packetJsonVersion = this.stateService.env.PACKAGE_JSON_VERSION;
|
||||
officialMempoolSpace = this.stateService.env.OFFICIAL_MEMPOOL_SPACE;
|
||||
showNavigateToSponsor = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user