From 7824f13f5fc66fec94a88409dbf2dcf42eb1e0aa Mon Sep 17 00:00:00 2001 From: Niraj Nandish Date: Wed, 6 Oct 2021 19:37:08 +0400 Subject: [PATCH] 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 Co-authored-by: Nicholas Carrigan (he/him) --- tools/scripts/build/ensure-env.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/scripts/build/ensure-env.js b/tools/scripts/build/ensure-env.js index 658a0e7091..e9e7f544c5 100644 --- a/tools/scripts/build/ensure-env.js +++ b/tools/scripts/build/ensure-env.js @@ -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));