@@ -26,14 +26,23 @@ const commands = {
2626
2727const paths = {
2828 iconfont : path . resolve ( __dirname , '../../images/iconfont' ) ,
29- iconpng : path . resolve ( __dirname , '../../images/icons' ) ,
29+ iconPng : path . resolve ( __dirname , '../../images/icons' ) ,
30+ illustrationPng : path . resolve ( __dirname , '../../images/illustrations' ) ,
31+ releasePng : path . resolve ( __dirname , '../../images/releases' ) ,
3032 fonts : path . resolve ( __dirname , '../../fonts' ) ,
3133 webFonts : path . resolve ( __dirname , '../../fonts-for-web' ) ,
3234 webFontsCss : path . resolve ( __dirname , '../../fonts-for-web/fonts_custom.styl' ) ,
3335 iconConstants : path . resolve ( __dirname , '../../common-adapters/icon.constants-gen.tsx' ) ,
3436 iconCss : path . resolve ( __dirname , '../../common-adapters/icon.css' ) ,
3537}
3638
39+ // Locations of all PNG assets to include in icon.constants.gen
40+ const pngAssetDirPaths = [
41+ { assetDirPath : paths . iconPng , insertFn : insertIconAssets } ,
42+ { assetDirPath : paths . illustrationPng , insertFn : insertIllustrationAssets } ,
43+ { assetDirPath : paths . releasePng , insertFn : insertReleaseAssets } ,
44+ ]
45+
3746const fontHeight = 1024
3847const descentFraction = 16 // Source: https://icomoon.io/#docs/font-metrics
3948const descent = fontHeight / descentFraction
@@ -239,8 +248,7 @@ ${Object.keys(rules)
239248 content: "\\${ rules [ name ] . toString ( 16 ) } ";
240249}`
241250 )
242- . join ( '\n' ) }
243- `
251+ . join ( '\n' ) } `
244252
245253 try {
246254 fs . writeFileSync ( paths . webFontsCss , css , 'utf8' )
@@ -256,26 +264,24 @@ const fontsGeneratedError = error => {
256264 process . exit ( 1 )
257265}
258266
259- function updateIconConstants ( ) {
260- console . log ( 'Generating icon constants' )
261-
267+ function insertIconAssets ( iconFiles ) {
262268 const icons = { }
263269
264- // Build constants for the png assests.
265- const iconFiles = fs . readdirSync ( paths . iconpng ) . filter ( i => i . indexOf ( '@' ) === - 1 )
266270 // light
267271 iconFiles
268272 . filter ( i => i . startsWith ( 'icon-' ) )
269273 . forEach ( i => {
270274 const shortName = i . slice ( 0 , - 4 )
271275 icons [ shortName ] = {
272276 extension : i . slice ( - 3 ) ,
277+ imagesDir : `'icons'` ,
273278 isFont : false ,
274279 nameDark : undefined ,
275280 require : `'../images/icons/${ i } '` ,
276281 requireDark : undefined ,
277282 }
278283 } )
284+
279285 // dark
280286 iconFiles
281287 . filter ( i => i . startsWith ( 'icon-dark-' ) )
@@ -290,6 +296,63 @@ function updateIconConstants() {
290296 icons [ lightName ] . requireDark = `'../images/icons/${ i } '`
291297 } )
292298
299+ return icons
300+ }
301+
302+ function insertIllustrationAssets ( illustrationFiles ) {
303+ return illustrationFiles . reduce ( ( prevIcons , i ) => {
304+ const shortName = i . slice ( 0 , - 4 )
305+ return {
306+ ...prevIcons ,
307+ [ shortName ] : {
308+ extension : i . slice ( - 3 ) ,
309+ imagesDir : `'illustrations'` ,
310+ isFont : false ,
311+ nameDark : undefined ,
312+ require : `'../images/illustrations/${ i } '` ,
313+ requireDark : undefined ,
314+ } ,
315+ }
316+ } , { } )
317+ }
318+
319+ function insertReleaseAssets ( releaseFiles ) {
320+ return releaseFiles . reduce ( ( prevIcons , i ) => {
321+ const shortName = i . slice ( 0 , - 4 )
322+ return {
323+ ...prevIcons ,
324+ [ shortName ] : {
325+ extension : i . slice ( - 3 ) ,
326+ imagesDir : `'releases'` ,
327+ isFont : false ,
328+ nameDark : undefined ,
329+ require : `'../images/releases/${ i } '` ,
330+ requireDark : undefined ,
331+ } ,
332+ }
333+ } , { } )
334+ }
335+
336+ function updateIconConstants ( ) {
337+ console . log ( 'Generating icon constants (from the following directories)' )
338+ console . log ( '\t*' + pngAssetDirPaths . map ( ( { assetDirPath} ) => assetDirPath ) . join ( '\n\t*' ) )
339+
340+ // Build constants for the png assests.
341+ const icons = pngAssetDirPaths . reduce ( ( prevIcons , { assetDirPath, insertFn} ) => {
342+ // Don't include @2x and @3x assets in icon-constants-gen.
343+ // They are included later in srcSet generation by icon.*.tsx
344+ //
345+ // On macOS (10.12+) Finder.app will no longer display .DS_Store files. Make sure they are not included here.
346+ const iconFiles = fs
347+ . readdirSync ( assetDirPath )
348+ . filter ( i => i . indexOf ( '@' ) === - 1 && i . indexOf ( 'DS_Store' ) === - 1 )
349+ const newIcons = insertFn ( iconFiles )
350+ return {
351+ ...prevIcons ,
352+ ...newIcons ,
353+ }
354+ } , { } )
355+
293356 // Build constants for iconfont svgs
294357 const svgFilenames = getSvgNames ( false /* print skipped */ )
295358 svgFilenames . reduce ( ( _ , { counter, name, size} ) => {
@@ -307,6 +370,7 @@ function updateIconConstants() {
307370 extension?: string
308371 charCode?: number
309372 nameDark?: string
373+ imagesDir?: string
310374 require?: string
311375 requireDark?: string
312376 }
@@ -321,6 +385,7 @@ function updateIconConstants() {
321385 const meta = [
322386 icon . charCode ? [ `charCode: 0x${ icons [ name ] . charCode . toString ( 16 ) } ` ] : [ ] ,
323387 icon . extension ? [ `extension: '${ icons [ name ] . extension } '` ] : [ ] ,
388+ icon . imagesDir ? [ `imagesDir: ${ icons [ name ] . imagesDir } ` ] : [ ] ,
324389 icon . gridSize ? [ `gridSize: ${ icons [ name ] . gridSize } ` ] : [ ] ,
325390 `isFont: ${ icon . isFont } ` ,
326391 icon . nameDark ? [ `nameDark: ${ icons [ name ] . nameDark } ` ] : [ ] ,
@@ -458,7 +523,7 @@ const setFontMetrics = () => {
458523}
459524
460525function unusedAssetes ( ) {
461- const allFiles = fs . readdirSync ( paths . iconpng )
526+ const allFiles = fs . readdirSync ( paths . iconPng )
462527
463528 // map of root name => [files]
464529 const images = { }
0 commit comments