1
1
const path = require ( 'path' )
2
- const { green, blue, red } = require ( 'kolorist' )
3
- const { readFile, writeFile } = require ( '../utils' )
2
+ const { green, blue, red} = require ( 'kolorist' )
3
+ const { readFile, writeFile} = require ( '../utils' )
4
4
5
5
const themeMap = {
6
6
baseline : '' ,
@@ -9,14 +9,26 @@ const themeMap = {
9
9
sharp : 's_'
10
10
}
11
11
12
- function run ( googleIcons , theme ) {
12
+ function run ( googleIcons , theme ) {
13
13
const name = 'material-icons' + ( theme === 'baseline' ? '' : '-' + theme )
14
14
// console.log(`${blue('[building]')} ${name}...`)
15
15
const inputLocation = `../../src/components/icon-set/${ name } .js`
16
16
const outputLocation = `../../src/components/icon-set/${ name } .js`
17
17
const oldIcons = { }
18
18
const icons = [ ]
19
19
const blacklisted = [
20
+ 'grade' ,
21
+ 'grading' ,
22
+ 'dynamic_feed' ,
23
+ 'o_dynamic_feed' ,
24
+ 'r_dynamic_feed' ,
25
+ 's_dynamic_feed' ,
26
+ 's_grade' ,
27
+ 's_grading' ,
28
+ 'r_grade' ,
29
+ 'r_grading' ,
30
+ 'o_grade' ,
31
+ 'o_grading'
20
32
]
21
33
const whiteListed = {
22
34
baseline : [
@@ -74,15 +86,15 @@ function run (googleIcons, theme) {
74
86
fa . forEach ( f => {
75
87
const name = f . name
76
88
const tags = f . tags
77
- oldIcons [ name ] = { tags : Array ( tags ) . join ( ',' ) }
89
+ oldIcons [ name ] = { tags : Array ( tags ) . join ( ',' ) }
78
90
} )
79
91
80
92
googleIcons . forEach ( gi => {
81
93
gi . name = themeMap [ theme ] + gi . name
82
94
} )
83
95
84
96
whiteListed [ theme ] . forEach ( name => {
85
- googleIcons . push ( { name : themeMap [ theme ] + name } )
97
+ googleIcons . push ( { name : themeMap [ theme ] + name } )
86
98
} )
87
99
88
100
googleIcons . sort ( ( a , b ) => {
@@ -94,14 +106,22 @@ function run (googleIcons, theme) {
94
106
const name = gi . name
95
107
if ( blacklisted . includes ( name ) === false ) {
96
108
if ( oldIcons [ name ] ) {
97
- const tags = oldIcons [ name ] . tags . split ( ',' ) . map ( tag => {
98
- if ( tag === '' ) return tag
99
- return "'" + tag + "'"
100
- } ) . join ( ', ' )
101
- icons . push ( `{ name: '${ name } ', tags: [${ tags } ] }` )
102
- }
103
- else {
104
- icons . push ( `{ name: '${ name } ', tags: [] }` )
109
+
110
+ const oldTags = oldIcons [ name ] . tags
111
+ . split ( ',' )
112
+
113
+ // Merge old and new tags
114
+ const tagsWithoutDuplicates = [ ...new Set ( oldTags . concat ( gi . tags ) ) ] ;
115
+ const newTags = tagsWithoutDuplicates
116
+ . filter ( tag => tag !== "" )
117
+ . map ( tag => "'" + tag + "'" )
118
+ . join ( ', ' )
119
+
120
+ // Add merged tags old/new
121
+ icons . push ( `{ name: '${ name } ', tags: [${ newTags } ] }` )
122
+ } else {
123
+ // Add new tags
124
+ icons . push ( `{ name: '${ name } ', tags: [${ gi . tags } ] }` )
105
125
}
106
126
}
107
127
} )
@@ -127,6 +147,7 @@ function run (googleIcons, theme) {
127
147
output += '}\n'
128
148
129
149
writeFile ( path . resolve ( __dirname , outputLocation ) , output )
150
+ . catch ( exception => console . error ( exception ) )
130
151
console . log ( `${ blue ( '[icon]' ) } ${ green ( name + ':' ) } ${ icons . length } generated` )
131
152
}
132
153
0 commit comments