Skip to content

Commit

Permalink
Bulk delete tags
Browse files Browse the repository at this point in the history
This changes the bulk editor's `remove` command so that specifying
target feature IDs is optional. This makes it possible to delete a tag
completely, without knowing which features the tag applies to.

Inspired by mdn#23188
  • Loading branch information
ddbeck committed May 28, 2024
1 parent e4011ca commit 5152062
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/bulk-editor/tags/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { updateFeatures } from '../utils.js';

const command = {
command: 'remove <tag> <bcd-id..>',
command: 'remove <tag> [bcd-id..]',
desc: 'Remove the following tag from the BCD features',
/**
* handler - Action to perform for 'tags remove'
Expand Down
15 changes: 12 additions & 3 deletions scripts/bulk-editor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,27 @@ export const updateFeatures = (featureIDs, updater) => {
const contents = JSON.parse(rawcontents.toString('utf8'));
let changed = false;

const applyToAnyFeatureID = !featureIDs || featureIDs.length === 0;
const walker = walk(undefined, contents);
for (const { path: featureID } of walker) {
if (
applyToAnyFeatureID ||
featureIDs.some(
(fid) =>
fid === featureID ||
(fid.endsWith('*') && featureID.startsWith(fid.slice(0, -1))),
)
) {
console.log(chalk`{yellow Updating ${featureID}...}`);
performUpdate(featureID, contents, updater);
changed = true;
const before = JSON.stringify(contents, undefined, 2);
const after = JSON.stringify(
performUpdate(featureID, contents, updater),
undefined,
2,
);
if (before != after) {
console.log(chalk`{yellow Updated ${featureID}}`);
changed = true;
}
}
}

Expand Down

0 comments on commit 5152062

Please sign in to comment.