diff --git a/scripts/update.mjs b/scripts/update.mjs index 477df10..4af5bcb 100644 --- a/scripts/update.mjs +++ b/scripts/update.mjs @@ -36,19 +36,34 @@ async function run(options) { removed, } // eslint-disable-next-line no-await-in-loop - = await updateGlobals({environment, getGlobals, dry: options.dry}); + = await updateGlobals({ + environment, + getGlobals, + dry: options.dry, + clean: options.clean, + }); - console.log( - outdent` - ✅ ${environment} globals updated. + console.log(`✅ ${environment} globals updated.`); - Added(${added.length}): - ${added.map(name => ` - ${name}`).join('\n') || 'None'} + if (added.length > 0) { + console.log(); + console.log( + outdent` + Added(${removed.length}): + ${added.map(name => ` + ${name}`).join('\n')} + `, + ); + } - Removed(${removed.length}): - ${removed.map(name => ` - ${name}`).join('\n') || 'None'} - `, - ); + if (removed.length > 0) { + console.log(); + console.log( + outdent` + Removed(${removed.length}): + ${removed.map(name => ` - ${name}`).join('\n')} + `, + ); + } } if (!options.dry) { @@ -73,6 +88,10 @@ const { type: 'boolean', default: false, }, + clean: { + type: 'boolean', + default: false, + }, }, }); diff --git a/scripts/utilities.mjs b/scripts/utilities.mjs index 20ecb85..344d637 100644 --- a/scripts/utilities.mjs +++ b/scripts/utilities.mjs @@ -19,10 +19,14 @@ const writeGlobals = async (environment, globals) => { await fs.writeFile(file, code + '\n'); }; -async function updateGlobals({environment, getGlobals, dry}) { - const updated = await getGlobals(); +async function updateGlobals({environment, getGlobals, dry, clean}) { + let updated = await getGlobals(); const original = await readGlobals(environment, {ignoreNonExits: true}); + if (!clean) { + updated = {...original, ...updated}; + } + if (!dry) { await writeGlobals(environment, updated); }