Skip to content

Commit

Permalink
feat(Icons): remove iOS (PDF) icons library support (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed May 31, 2023
1 parent 37251b5 commit 6063ff3
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 251 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"node-gyp": "8.4.0"
},
"resolutions": {
"svg2vectordrawable/svgo": "2.3.0",
"gatsby/socket.io": "4.6.1",
"gatsby/browserslist": "4.21.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/src/docs/icons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ListAllIcons from 'dnb-design-system-portal/src/shared/parts/icons/ListAl
This is a list of all icons available sorted in categories. Its a list where primary and secondary icons are combined. You may be interested to [read more](/icons/details) about what [the difference](/icons/primary) is and [how to import](/icons/secondary#react-example-usage).

- for Web there are both [icons as SVG](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons) and ready to use [React Components](/icons/secondary#react-example-usage).
- for iOS there is a [custom PDF package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-pdf.tgz) and a [categorized PDF package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-pdf-categorized.tgz).
- for Android there is a [custom XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-xml.tgz) and a [categorized XML (drawable) package](https://github.com/dnbexperience/eufemia/tree/main/packages/dnb-eufemia/assets/icons/eufemia-icons-xml-categorized.tgz).
- the support for iOS with the PDF format was discontinued in v10.

<ListAllIcons groupBy="category" />
Binary file not shown.
Binary file not shown.
17 changes: 1 addition & 16 deletions packages/dnb-eufemia/scripts/figma/FigmaAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*
*/

import {
extractIconsAsSVG,
extractIconsAsPDF,
} from './tasks/assetsExtractors'
import { extractIconsAsSVG } from './tasks/assetsExtractors'
import { getFigmaDoc } from './helpers/docHelpers'
import { getRequiredBranchName } from './../prebuild/commitToBranch'
import { log, ErrorHandler } from '../lib'
Expand Down Expand Up @@ -39,18 +36,6 @@ export const fetchFigmaIcons = async ({
} catch (e) {
log.fail(new ErrorHandler('Failed during extractIconsAsSVG', e))
}

try {
log.start('> Figma: Starting the pdf fetch')
const pdfs = await extractIconsAsPDF({
figmaFile,
figmaDoc,
...args,
})
log.succeed(`> Figma: PDFs conversion done (${pdfs?.length} pdfs)`)
} catch (e) {
log.fail(new ErrorHandler('Failed during extractIconsAsPDF', e))
}
}

export const fetchFigmaAll = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import fs from 'fs-extra'
import tar from 'tar'
import { log } from '../../../lib'
import '../../../../src/core/jest/jestSetup'
import { getFigmaDoc } from '../../helpers/docHelpers'
Expand Down Expand Up @@ -78,12 +79,24 @@ jest.mock('fs-extra', () => {
return 'unknown'
}),
unlink: jest.fn().mockResolvedValue(),
move: jest.fn(),
stat: jest.fn((file) => {
const size = file.includes('eufemia-icons-xml.tgz') ? 100 : 200
return { size }
}),
createWriteStream: jest.fn(() => {
return writeStream
}),
}
})

jest.mock('tar', () => {
return {
create: jest.fn(),
extract: jest.fn(),
}
})

jest.mock('https', () => {
return {
get: jest.fn(() => {
Expand Down Expand Up @@ -142,6 +155,10 @@ describe('assetsExtractors', () => {

const writeFile = jest.fn()
jest.spyOn(fs, 'writeFile').mockImplementation(writeFile)
const unlink = jest.fn()
jest.spyOn(fs, 'unlink').mockImplementation(unlink)
const move = jest.fn()
jest.spyOn(fs, 'move').mockImplementation(move)

const figmaDoc = await getFigmaDoc({
forceRefetch: false,
Expand All @@ -163,7 +180,7 @@ describe('assetsExtractors', () => {
'Starting to fetch 2 icons from the "Icons" Canvas'
)
)
expect(info).toHaveBeenCalledTimes(6)
expect(info).toHaveBeenCalledTimes(7)
expect(info).toHaveBeenNthCalledWith(
1,
expect.stringContaining(
Expand Down Expand Up @@ -196,10 +213,78 @@ describe('assetsExtractors', () => {
6,
expect.stringContaining('Icon was optimized: bell.svg')
)
expect(succeed).toHaveBeenCalledTimes(1)
expect(succeed).toHaveBeenCalledWith(
expect(info).toHaveBeenNthCalledWith(
7,
expect.stringContaining('started to create eufemia-icons-xml.tgz')
)
expect(succeed).toHaveBeenCalledTimes(2)
expect(succeed).toHaveBeenNthCalledWith(
1,
expect.stringContaining('Using old Figma document')
)
expect(succeed).toHaveBeenNthCalledWith(
2,
expect.stringContaining('finished to create eufemia-icons-xml.tgz')
)

expect(move).toHaveBeenCalledTimes(2)
expect(move).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/assets/icons/bell_medium.xml'),
expect.stringContaining('/assets/icons/bell/bell_medium.xml')
)
expect(move).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/assets/icons/bell.xml'),
expect.stringContaining('/assets/icons/bell/bell.xml')
)

expect(unlink).toHaveBeenCalledTimes(3)
expect(unlink).toHaveBeenNthCalledWith(
1,
expect.stringContaining('/assets/icons/tmp.tgz')
)
expect(unlink).toHaveBeenNthCalledWith(
2,
expect.stringContaining('/assets/icons/bell_medium.xml')
)
expect(unlink).toHaveBeenNthCalledWith(
3,
expect.stringContaining('/assets/icons/bell.xml')
)

expect(tar.create).toHaveBeenCalledTimes(3)
expect(tar.create).toHaveBeenNthCalledWith(
1,
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining('/assets/icons/tmp.tgz'),
gzip: true,
},
['bell_medium.xml', 'bell.xml']
)
expect(tar.create).toHaveBeenNthCalledWith(
2,
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining(
'/assets/icons/eufemia-icons-xml.tgz'
),
gzip: true,
},
['bell_medium.xml', 'bell.xml']
)
expect(tar.create).toHaveBeenNthCalledWith(
3,
{
cwd: expect.stringContaining('/assets/icons'),
file: expect.stringContaining(
'/assets/icons/eufemia-icons-xml-categorized.tgz'
),
gzip: true,
},
['bell/bell_medium.xml', 'bell/bell.xml']
)

expect(writeFile).toHaveBeenCalledTimes(4)
expect(writeFile).toHaveBeenNthCalledWith(
Expand Down
192 changes: 8 additions & 184 deletions packages/dnb-eufemia/scripts/figma/tasks/assetsExtractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ export const extractIconsAsSVG = async ({
if (listWithNewFiles.length > 0) {
await optimizeSVGIcons({ destDir, listWithFiles: listWithNewFiles })

// NB: This step was moved into the pdf creation step
// await createXMLTarBundles({
// destDir,
// listOfProcessedFiles,
// })
// Android support
await createXMLTarBundles({
destDir,
listOfProcessedFiles,
})
}

makeMetaFile({
Expand Down Expand Up @@ -235,184 +235,6 @@ const runDiffControll = ({ controllStorageLists }) => {
}
}

export const extractIconsAsPDF = async ({
figmaFile,
figmaDoc = null,
forceReconvert = null,
outputName = 'eufemia-icons-pdf.tgz',
outputNameCategorized = 'eufemia-icons-pdf-categorized.tgz',
...rest
}) => {
try {
if (figmaDoc === null) {
figmaDoc = await getFigmaDoc({
figmaFile,
preventUpdate: forceReconvert,
})
}

// juice out, if no changes
if (!figmaDoc) return []

log.start('> Figma: started to fetch PDFs by using frameIconsFactory')

const destDir = path.resolve(__dirname, '../../../assets/icons')
if (!fs.existsSync(destDir)) {
fs.mkdir(destDir)
}

let tarFileSize = 0
const tarFile = path.resolve(destDir, outputName)
if (fs.existsSync(tarFile)) {
tarFileSize = (await fs.stat(tarFile)).size
await extract({
cwd: destDir,
file: tarFile,
})
}

const iconsLockFile = path.resolve(
__dirname,
'../../../src/icons/icons-pdf.lock'
)

const { listOfProcessedFiles, listWithNewFiles } =
await collectIconsFromFigmaDoc({
figmaFile,
figmaDoc,
format: 'pdf',
...IconsConfig({ iconsLockFile }),
...rest,
})

log.info(
`> Figma: finished fetching PDFs by using frameIconsFactory. Processed ${listOfProcessedFiles.length} files along with ${listWithNewFiles.length} new files.`
)

// save the lockFile content
await saveIconsLockFile({
file: iconsLockFile,
data: listOfProcessedFiles.reduce((acc, { iconFile, ...cur }) => {
acc[iconFile] = cur
return acc
}, {}),
})

log.info(`> Figma: ${iconsLockFile} file got generated`)

if (listWithNewFiles.length > 0) {
log.info(`> Figma: started to create ${outputName}`)

const hasSizeChanged = async () => {
const fileList = listOfProcessedFiles.map(
({ iconFile }) => iconFile
)

const tmp = path.resolve(destDir, 'tmp.tgz')
await create(
{
gzip: true,
cwd: destDir,
file: tmp,
},
fileList
)
const tmpSize = (await fs.stat(tmp)).size

await fs.unlink(tmp)

return Math.abs(tarFileSize - tmpSize) > 30
}

const createTarWithoutCategories = async () => {
const fileList = listOfProcessedFiles.map(
({ iconFile }) => iconFile
)

await create(
{
gzip: true,
cwd: destDir,
file: tarFile,
},
fileList
)
}

const createTarWithCategories = async () => {
const { getCategoryFromIconName } = IconsConfig()

await asyncForEach(
listOfProcessedFiles,
async ({ name, iconFile }) => {
const source = path.resolve(destDir, iconFile)
const dest = path.resolve(
destDir,
`${getCategoryFromIconName(name)}/${iconFile}`
)

if (fs.existsSync(source)) {
await fs.move(source, dest)
}
}
)

const fileList = listOfProcessedFiles.map(
({ name, iconFile }) =>
`${getCategoryFromIconName(name)}/${iconFile}`
)

const tarFile = path.resolve(destDir, outputNameCategorized)
await create(
{
gzip: true,
cwd: destDir,
file: tarFile,
},
fileList
)

await asyncForEach(fileList, async (file) => {
file = path.resolve(destDir, file)
if (fs.existsSync(file)) {
await fs.unlink(file)
}
})
}

const sizeHasChanged = await hasSizeChanged()
if (sizeHasChanged) {
await createTarWithoutCategories()
await createTarWithCategories()
}

log.succeed(`> Figma: finished to create ${outputName}`)

// Also create the XML bundles
await createXMLTarBundles({
destDir,
listOfProcessedFiles,
})
}

// Remove the pdfs
await asyncForEach(listOfProcessedFiles, async ({ iconFile }) => {
const file = path.resolve(destDir, iconFile)
if (fs.existsSync(file)) {
try {
await fs.unlink(file)
} catch (e) {
log.fail(new ErrorHandler(`Failed to remove ${iconFile}`, e))
}
}
})

return listOfProcessedFiles
} catch (e) {
log.fail(new ErrorHandler('extractIconsAsPDF failed', e))
}
}

const frameIconsFactory = async ({
frameDoc,
figmaFile,
Expand Down Expand Up @@ -854,7 +676,9 @@ const createXMLTarBundles = async ({
const source = path.resolve(destDir, iconFile)
const dest = path.resolve(destDir, iconFileXML)

await svg2vectordrawable(source, dest, floatPrecision)
await svg2vectordrawable.convertFile(source, dest, {
floatPrecision,
})
}
)
}
Expand Down
Loading

0 comments on commit 6063ff3

Please sign in to comment.