Skip to content

Commit

Permalink
Find outdated icons and warn
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Apr 13, 2023
1 parent f7226e3 commit 3e274bc
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 116 deletions.
1 change: 0 additions & 1 deletion packages/dnb-eufemia/assets/icons/dnb/fund_in.svg

This file was deleted.

1 change: 0 additions & 1 deletion packages/dnb-eufemia/assets/icons/dnb/fund_out.svg

This file was deleted.

This file was deleted.

7 changes: 5 additions & 2 deletions packages/dnb-eufemia/scripts/figma/tasks/assetsExtractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
import properties from '../../../src/style/themes/theme-ui/properties'
import { create, extract } from 'tar'

const ICON_SIZES = {
export const ICON_SIZES = {
16: { suffix: '' },
24: { suffix: 'medium' },
}
export const NAME_SEPARATOR = '_'

const iconPrimaryList = process.env.FIGMA_ICONS_PRIMARY_LIST || [
'chevron_left',
Expand Down Expand Up @@ -625,7 +626,9 @@ const makeMetaFile = async ({
// remove duplication
const cleanedName = Object.values(ICON_SIZES).reduce(
(iconName, { suffix }) =>
suffix ? iconName.replace('_' + suffix, '') : iconName,
suffix
? iconName.replace(NAME_SEPARATOR + suffix, '')
: iconName,
iconName
)
tags = tags.filter((item, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ beforeAll(async () => {
preventDelete: true,
srcPath: path.resolve(__dirname, './test-files/**/*.svg'),
destPath: path.resolve(__dirname, './test-files/dist'),
customIconsLockFile: path.resolve(
customIconsLockFilePath: path.resolve(
__dirname,
'./test-files/dnb/icons-svg.lock'
),
Expand Down
62 changes: 49 additions & 13 deletions packages/dnb-eufemia/scripts/prebuild/tasks/convertSvgToJsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { md5 } from '../../figma/helpers/docHelpers'
import {
IconsConfig,
readIconsLockFile,
ICON_SIZES,
NAME_SEPARATOR,
} from '../../figma/tasks/assetsExtractors'
import packpath from 'packpath'

Expand All @@ -29,7 +31,7 @@ export default async function convertSvgToJsx({
srcPath = './assets/icons/**/*.svg',
destPath = './src/icons',
preventDelete = false,
customIconsLockFile = null,
customIconsLockFilePath = null,
} = {}) {
if (!preventDelete) {
await del(
Expand Down Expand Up @@ -70,20 +72,49 @@ export default async function convertSvgToJsx({
srcPath,
destPath,
assetsDir,
customIconsLockFile,
customIconsLockFilePath,
})

log.succeed(
`> PrePublish: Converting "svg to jsx" for "${assetsDir}" is done (${icons.length} icons)`
)

await controllRoutine({ icons })
})
}

const controllRoutine = async ({ icons }) => {
const listOfIcons = Object.values(icons)

const sizes = Object.values(ICON_SIZES).filter(({ suffix }) => {
return Boolean(suffix)
})

sizes.forEach(({ suffix: size }) => {
listOfIcons.forEach(({ name: origName }) => {
const foundNames = listOfIcons.filter(({ name }) => {
if (origName.endsWith(`${NAME_SEPARATOR}${size}`)) {
return origName.replace(`${NAME_SEPARATOR}${size}`, '') === name
}
return `${origName}${NAME_SEPARATOR}${size}` === name
})

if (foundNames.length !== 1) {
log.fail(
`The icon "${origName}" was not found with another size${
origName.endsWith(size) ? '' : ` (${size})`
}! They should be looked up. The failure can be in several places.`
)
}
})
})
}

const transformSvg = async ({
srcPath,
destPath,
assetsDir,
customIconsLockFile,
customIconsLockFilePath,
}) => {
try {
// create subfolder
Expand All @@ -97,7 +128,7 @@ const transformSvg = async ({
return await makeIconsEntryFiles({
destPath,
assetsDir,
customIconsLockFile,
customIconsLockFilePath,
})
} catch (e) {
log.fail('Failed to run the convertSvgToJsx process')
Expand Down Expand Up @@ -184,7 +215,7 @@ const transformToJsx = (content, file) => {
const makeIconsEntryFiles = async ({
destPath,
assetsDir,
customIconsLockFile = null,
customIconsLockFilePath = null,
}) => {
// get all the svg icons we find
const icons = (
Expand Down Expand Up @@ -215,18 +246,17 @@ const makeIconsEntryFiles = async ({
await generateFallbackIndexFiles({ icons, destPath, assetsDir })
}

// get the svg lock file
const { iconsLockFile } = IconsConfig({ assetsDir })
const lockFileContent = await readIconsLockFile({
file: customIconsLockFile || iconsLockFile,
})

if (assetsDir === FALLBACK) {
await generateIndexFile({ icons, destPath, assetsDir: '' }) // generate fallback index file
}

await generateIndexFile({ icons, destPath, assetsDir })
await generateGroupFiles({ icons, destPath, assetsDir, lockFileContent })
await generateGroupFiles({
icons,
destPath,
assetsDir,
customIconsLockFilePath,
})

return icons
}
Expand Down Expand Up @@ -275,8 +305,14 @@ const generateIndexFile = async ({ icons, destPath, assetsDir }) => {
const generateGroupFiles = async ({
destPath,
assetsDir,
lockFileContent,
customIconsLockFilePath,
}) => {
// get the svg lock file
const { iconsLockFile } = IconsConfig({ assetsDir })
const lockFileContent = await readIconsLockFile({
file: customIconsLockFilePath || iconsLockFile,
})

// from the svg lock file we can generate groups out of the "bundleName"
const groups = Object.entries(lockFileContent).reduce(
(acc, [file, { bundleName }]) => {
Expand Down
22 changes: 0 additions & 22 deletions packages/dnb-eufemia/src/icons/dnb/fund_in.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions packages/dnb-eufemia/src/icons/dnb/fund_out.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions packages/dnb-eufemia/src/icons/dnb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ import fridge from './fridge'
import fridge_medium from './fridge_medium'
import fullscreen from './fullscreen'
import fullscreen_medium from './fullscreen_medium'
import fund_in from './fund_in'
import fund_out from './fund_out'
import funds from './funds'
import funds_in from './funds_in'
import funds_in_medium from './funds_in_medium'
Expand Down Expand Up @@ -426,7 +424,6 @@ import portfolio_analytics from './portfolio_analytics'
import portfolio_analytics_medium from './portfolio_analytics_medium'
import printer from './printer'
import printer_medium from './printer_medium'
import products_account_percent_medium from './products_account_percent_medium'
import profile from './profile'
import profile_medium from './profile_medium'
import progress from './progress'
Expand Down Expand Up @@ -817,8 +814,6 @@ export {
fridge_medium,
fullscreen,
fullscreen_medium,
fund_in,
fund_out,
funds,
funds_in,
funds_in_medium,
Expand Down Expand Up @@ -979,7 +974,6 @@ export {
portfolio_analytics_medium,
printer,
printer_medium,
products_account_percent_medium,
profile,
profile_medium,
progress,
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions packages/dnb-eufemia/src/icons/fund_in.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/dnb-eufemia/src/icons/fund_out.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/dnb-eufemia/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ import fridge from './dnb/fridge'
import fridge_medium from './dnb/fridge_medium'
import fullscreen from './dnb/fullscreen'
import fullscreen_medium from './dnb/fullscreen_medium'
import fund_in from './dnb/fund_in'
import fund_out from './dnb/fund_out'
import funds from './dnb/funds'
import funds_in from './dnb/funds_in'
import funds_in_medium from './dnb/funds_in_medium'
Expand Down Expand Up @@ -426,7 +424,6 @@ import portfolio_analytics from './dnb/portfolio_analytics'
import portfolio_analytics_medium from './dnb/portfolio_analytics_medium'
import printer from './dnb/printer'
import printer_medium from './dnb/printer_medium'
import products_account_percent_medium from './dnb/products_account_percent_medium'
import profile from './dnb/profile'
import profile_medium from './dnb/profile_medium'
import progress from './dnb/progress'
Expand Down Expand Up @@ -817,8 +814,6 @@ export {
fridge_medium,
fullscreen,
fullscreen_medium,
fund_in,
fund_out,
funds,
funds_in,
funds_in_medium,
Expand Down Expand Up @@ -979,7 +974,6 @@ export {
portfolio_analytics_medium,
printer,
printer_medium,
products_account_percent_medium,
profile,
profile_medium,
progress,
Expand Down

This file was deleted.

0 comments on commit 3e274bc

Please sign in to comment.