Skip to content

Commit

Permalink
feat(sketch): programmatically remove deprecated icon symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Mar 10, 2021
1 parent 0f563f9 commit 9c0b94e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/sketch/src/commands/icons/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ function getSymbolName({ icon, size }) {
return symbolName;
}

/**
* Remove deprecated icon symbols from the current Sketch document
* @param {object} params - removeDeprecatedSymbolArtboards parameters
* @param {Array<object>} params.icons - array of all icon object metadata
* @param {Array<number>} params.sizes - array of icon sizes
* @param {Page} params.symbolsPage - the symbols page as identified by Sketch
*/
function removeDeprecatedSymbolArtboards({ icons, sizes, symbolsPage }) {
const deprecatedIcons = icons.reduce((deprecatedIconsMap, currentIcon) => {
if (currentIcon.deprecated) {
sizes.forEach((size) => {
const symbolName = getSymbolName({ icon: currentIcon, size });
deprecatedIconsMap.set(symbolName, currentIcon);
});
}

return deprecatedIconsMap;
}, new Map());

symbolsPage.layers.forEach((symbol) => {
if (deprecatedIcons.get(symbol.name)) {
symbol.remove();
}
});
}

export function syncIconSymbols({
document,
symbols,
Expand All @@ -48,6 +74,12 @@ export function syncIconSymbols({
);
}

removeDeprecatedSymbolArtboards({
icons: metadata.icons,
sizes,
symbolsPage,
});

const artboards = createSVGArtboards(
symbolsPage,
sharedStyle,
Expand Down

0 comments on commit 9c0b94e

Please sign in to comment.