From 585fe1675b871ba7ec680ac395210bf8a1e23023 Mon Sep 17 00:00:00 2001 From: emyarod Date: Wed, 10 Mar 2021 13:49:09 -0600 Subject: [PATCH 1/3] refactor(sketch): create icon symbol name formatter function --- packages/sketch/src/commands/icons/shared.js | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/sketch/src/commands/icons/shared.js b/packages/sketch/src/commands/icons/shared.js index 7e052730bd03..48998baa59a3 100644 --- a/packages/sketch/src/commands/icons/shared.js +++ b/packages/sketch/src/commands/icons/shared.js @@ -14,6 +14,23 @@ import { syncSymbol } from '../../tools/symbols'; const metadata = require('../../../generated/icons/metadata.json'); +/** + * Returns the formatted icon symbol name, given an icon object and a size value + * @param {object} params - getSymbolName parameters + * @param {object} params.icon - an icon object from the icon metadata + * @param {number} params.size + * @returns {string} - formatted icon symbol name: + * `[icon.subcategory] / [icon.subcategory] / / ` + */ +function getSymbolName({ icon, size }) { + const symbolName = `${icon.name} / ${size}`; + if (icon.category && icon.subcategory) { + return `${icon.category} / ${icon.subcategory} / ${symbolName}`; + } + + return symbolName; +} + export function syncIconSymbols({ document, symbols, @@ -114,12 +131,7 @@ function createSVGArtboards( }, }; - let symbolName = `${icon.name} / ${size}`; - - if (icon.category && icon.subcategory) { - symbolName = `${icon.category} / ${icon.subcategory} / ${symbolName}`; - } - + const symbolName = getSymbolName({ icon, size }); const artboard = new Artboard({ name: symbolName, frame: new Rectangle(X_OFFSET, Y_OFFSET, size, size), From ee0d399927abee76b785adc06becebe3e76bf805 Mon Sep 17 00:00:00 2001 From: emyarod Date: Wed, 10 Mar 2021 13:55:11 -0600 Subject: [PATCH 2/3] docs(sketch): fix typo --- packages/sketch/src/commands/icons/shared.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sketch/src/commands/icons/shared.js b/packages/sketch/src/commands/icons/shared.js index 48998baa59a3..d06b711b5739 100644 --- a/packages/sketch/src/commands/icons/shared.js +++ b/packages/sketch/src/commands/icons/shared.js @@ -87,7 +87,7 @@ function getInitialPageOffset(page) { /** * Create the SVG artboards for a given set of icons and sizes and place them in - * the given page with the given shared style set as th e fill. + * the given page with the given shared style set as the fill. * @param {Page} page * @param {SharedStyle} sharedStyle * @param {Array} icons From 0f8fa756bf3faf54034ac5b072519519eb8540dd Mon Sep 17 00:00:00 2001 From: emyarod Date: Wed, 10 Mar 2021 13:56:33 -0600 Subject: [PATCH 3/3] feat(sketch): programmatically remove deprecated icon symbols --- packages/sketch/src/commands/icons/shared.js | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/sketch/src/commands/icons/shared.js b/packages/sketch/src/commands/icons/shared.js index d06b711b5739..7834f8b178db 100644 --- a/packages/sketch/src/commands/icons/shared.js +++ b/packages/sketch/src/commands/icons/shared.js @@ -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} params.icons - array of all icon object metadata + * @param {Array} 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, @@ -48,6 +74,12 @@ export function syncIconSymbols({ ); } + removeDeprecatedSymbolArtboards({ + icons: metadata.icons, + sizes, + symbolsPage, + }); + const artboards = createSVGArtboards( symbolsPage, sharedStyle,