From 6e24643b59dee1a7fc0a08b52a55cab7a763c31e Mon Sep 17 00:00:00 2001 From: vagnerbarbosant Date: Wed, 3 Apr 2024 21:19:16 -0300 Subject: [PATCH 1/2] feat(natds-themes): filter Primitive Colors affects: natds-themes DSY-4348 --- .../config/android/buildAndroidConfig.js | 4 +-- .../natds-themes/config/ios/buildIosConfig.js | 6 ++--- .../react-native/buildReactNativeConfig.js | 4 ++- .../config/shared/helpers/helpers.js | 27 +++++++++++++++++++ .../natds-themes/config/web/buildWebConfig.js | 6 +++-- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/packages/natds-themes/config/android/buildAndroidConfig.js b/packages/natds-themes/config/android/buildAndroidConfig.js index 5d933d2e8..575c7fcb6 100644 --- a/packages/natds-themes/config/android/buildAndroidConfig.js +++ b/packages/natds-themes/config/android/buildAndroidConfig.js @@ -1,4 +1,4 @@ -import { capitalizeWord, camelToSnakeCase } from '../shared/helpers' +import { capitalizeWord, camelToSnakeCase, excludePrimitiveTokens } from '../shared/helpers' import { filterPrivateAndFontFamilyProps, filterSearchAndFontFamilyProps } from './helpers/helpers' export const buildAndroidConfig = (brand, mode) => { @@ -16,7 +16,7 @@ export const buildAndroidConfig = (brand, mode) => { { brandName: capitalizeWord(brand), destination: `theme/theme_${brandName}_${mode}_ssot.xml`, - filter: filterPrivateAndFontFamilyProps, + filter: (token) => excludePrimitiveTokens(token) && filterPrivateAndFontFamilyProps, format: 'android/themes', mode: capitalizeWord(mode) }, diff --git a/packages/natds-themes/config/ios/buildIosConfig.js b/packages/natds-themes/config/ios/buildIosConfig.js index c6633649a..8e05c852a 100644 --- a/packages/natds-themes/config/ios/buildIosConfig.js +++ b/packages/natds-themes/config/ios/buildIosConfig.js @@ -1,4 +1,4 @@ -import { capitalizeWord, snakeToCamelCase } from '../shared/helpers' +import { capitalizeWord, snakeToCamelCase, excludePrimitiveTokens } from '../shared/helpers' const buildIosConfig = (brand, mode) => { const brandFormated = capitalizeWord(snakeToCamelCase(brand)) @@ -11,13 +11,13 @@ const buildIosConfig = (brand, mode) => { files: [ { destination: `theme/${brandFormated}/${fileName}Theme.swift`, - filter: 'privateProperties', + filter: (token) => excludePrimitiveTokens(token) && 'privateProperties', format: 'ios-swift/theme.swift', themeName: fileName }, { destination: 'theme/ThemeProtocol.swift', - filter: 'privateProperties', + filter: (token) => excludePrimitiveTokens(token) && 'privateProperties', format: 'ios-swift/theme-protocol.swift' }, { diff --git a/packages/natds-themes/config/react-native/buildReactNativeConfig.js b/packages/natds-themes/config/react-native/buildReactNativeConfig.js index d7c451c7d..a46469cd3 100644 --- a/packages/natds-themes/config/react-native/buildReactNativeConfig.js +++ b/packages/natds-themes/config/react-native/buildReactNativeConfig.js @@ -1,10 +1,12 @@ +import { excludePrimitiveTokens } from '../shared/helpers' + const buildReactNativeConfig = (brand, mode) => ({ actions: ['create_type_definitions', 'custom_copy_assets'], buildPath: 'build/react-native/', files: [ { destination: `${brand}/${mode}.json`, - filter: 'privateProperties', + filter: (token) => excludePrimitiveTokens(token) && 'privateProperties', format: 'json/nested' }, { diff --git a/packages/natds-themes/config/shared/helpers/helpers.js b/packages/natds-themes/config/shared/helpers/helpers.js index 47c8abfbf..150c80993 100644 --- a/packages/natds-themes/config/shared/helpers/helpers.js +++ b/packages/natds-themes/config/shared/helpers/helpers.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import fs from 'fs' import path from 'path' import { @@ -36,6 +37,32 @@ export const hasAlpha = (value) => value.length === 9 export const isFontFamilyProp = isProp('fontFamily') export const checkDir = (dir) => !fs.existsSync(dir) && fs.mkdirSync(dir, { recursive: true }) +const removeTokens = [ + 'colorPrimitiveLightGray50', + 'colorPrimitiveLightGray100', + 'colorPrimitiveLightGray200', + 'colorPrimitiveLightGray300', + 'colorPrimitiveLightGray400', + 'colorPrimitiveLightGray600', + 'colorPrimitiveLightGray700', + 'colorPrimitiveLightGray800', + 'colorPrimitiveLightGray900', + 'colorPrimitiveDarkGray50', + 'colorPrimitiveDarkGray100', + 'colorPrimitiveDarkGray200', + 'colorPrimitiveDarkGray300', + 'colorPrimitiveDarkGray400', + 'colorPrimitiveDarkGray500', + 'colorPrimitiveDarkGray600', + 'colorPrimitiveDarkGray700', + 'colorPrimitiveDarkGray800', + 'colorPrimitiveDarkGray900', + 'colorPrimitiveBlack', + 'colorPrimitiveWhite' +] + +export const excludePrimitiveTokens = (token) => !removeTokens.some((excludeItem) => token.name.includes(excludeItem)) + export const isLogoAssetFileLanguage = (token) => token.attributes.state === 'file' || token.attributes.state === 'pt' || token.attributes.state === 'es' export function snakeToCamelCase(str) { return str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()) diff --git a/packages/natds-themes/config/web/buildWebConfig.js b/packages/natds-themes/config/web/buildWebConfig.js index 915046cef..337b383ed 100644 --- a/packages/natds-themes/config/web/buildWebConfig.js +++ b/packages/natds-themes/config/web/buildWebConfig.js @@ -1,3 +1,5 @@ +import { excludePrimitiveTokens } from '../shared/helpers' + export const buildWebConfig = (brand, mode) => ({ actions: ['create_type_definitions', 'custom_copy_assets', 'create_type_face'], brand, @@ -11,13 +13,13 @@ export const buildWebConfig = (brand, mode) => ({ }, { destination: `${brand}/${mode}.json`, - filter: 'privateProperties', + filter: (token) => excludePrimitiveTokens(token) && 'privateProperties', format: 'json/nested', options: { showFileHeader: false } }, { destination: `${brand}/${mode}.js`, - filter: 'privateProperties', + filter: (token) => excludePrimitiveTokens(token) && 'privateProperties', format: 'javascript/es6', options: { showFileHeader: false } }, From d90f70becd996f52b31e5ba466c1ab8968fb6566 Mon Sep 17 00:00:00 2001 From: vagnerbarbosant Date: Wed, 3 Apr 2024 21:20:10 -0300 Subject: [PATCH 2/2] feat(natds-themes): added tokens components affects: natds-themes DSY-4348 --- .../registerTokenSearchPropertiesFilter.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/natds-themes/config/shared/filters/registerTokenSearchPropertiesFilter.js b/packages/natds-themes/config/shared/filters/registerTokenSearchPropertiesFilter.js index fc644d53a..abd085365 100644 --- a/packages/natds-themes/config/shared/filters/registerTokenSearchPropertiesFilter.js +++ b/packages/natds-themes/config/shared/filters/registerTokenSearchPropertiesFilter.js @@ -4,6 +4,28 @@ const tokenCategories = [ 'typography', 'borderRadius', 'color', + 'alert', + 'appBarTop', + 'avatar', + 'badge', + 'button', + 'card', + 'checkbox', + 'counter', + 'dialog', + 'divider', + 'expansionPanel', + 'iconButton', + 'image', + 'link', + 'navigationDrawer', + 'progressIndicator', + 'radioButton', + 'shortcut', + 'snackbar', + 'tab', + 'tag', + 'textField', 'elevation', 'opacity', 'asset'