feat: auto clean client cache when SHOW_UPCOMING_CHANGES value changes (#43747)

* feat: auto clean client cache on env var change

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
This commit is contained in:
Niraj Nandish
2021-10-06 19:37:08 +04:00
committed by GitHub
parent e6b3c90983
commit 7824f13f5f

View File

@ -1,3 +1,4 @@
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
@ -101,6 +102,22 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
} else {
checkClientLocale();
checkCurriculumLocale();
if (fs.existsSync(`${globalConfigPath}/env.json`)) {
const { showUpcomingChanges } = require(`${globalConfigPath}/env.json`);
if (env['showUpcomingChanges'] !== showUpcomingChanges) {
console.log(
'SHOW_UPCOMING_CHANGES value has changed, cleaning client cache.'
);
const child = spawn('npm', ['run', 'clean:client']);
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
console.log(data);
});
child.on('error', err => {
console.error(err);
});
}
}
}
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));