Skip to content

Commit

Permalink
Update update script to be incremental (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Feb 20, 2024
1 parent bc4e17f commit af24d13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
39 changes: 29 additions & 10 deletions scripts/update.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -73,6 +88,10 @@ const {
type: 'boolean',
default: false,
},
clean: {
type: 'boolean',
default: false,
},
},
});

Expand Down
8 changes: 6 additions & 2 deletions scripts/utilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit af24d13

Please sign in to comment.