1
1
const camelCase = require ( "camelcase" ) ;
2
- const fs = require ( "fs-extra" ) ;
2
+ const {
3
+ promises : { writeFile, readFile } ,
4
+ readFileSync,
5
+ } = require ( "fs" ) ;
3
6
const { glob } = require ( "glob" ) ;
4
7
const { parse } = require ( "svgson" ) ;
5
8
const path = require ( "path" ) ;
@@ -30,10 +33,11 @@ function formatSVG(svg) {
30
33
function getPaths ( svg ) {
31
34
const bbPaths = [ "M0 0h16v16H0z" , "M0 0h24v24H0z" , "M0 0h32v32H0z" ] ;
32
35
return svg . children
33
- . filter (
34
- ( child ) => child . name === "path" && bbPaths . indexOf ( child . attributes . d ) === - 1 ,
35
- ) // filter out bounding box paths
36
- . map ( ( child ) => ( { opacity : child . attributes . opacity , d : child . attributes . d } ) ) ;
36
+ . filter ( ( child ) => child . name === "path" && bbPaths . indexOf ( child . attributes . d ) === - 1 ) // filter out bounding box paths
37
+ . map ( ( child ) => ( {
38
+ opacity : child . attributes . opacity ,
39
+ d : child . attributes . d ,
40
+ } ) ) ;
37
41
}
38
42
39
43
/**
@@ -64,17 +68,12 @@ function getSize(name) {
64
68
*/
65
69
function readSVG ( fileName ) {
66
70
return new Promise ( ( resolve , reject ) =>
67
- fs
68
- . readFile ( fileName , "utf-8" )
69
- . then ( ( svg ) =>
70
- parse ( svg ) . then ( ( contents ) => resolve ( { file : fileName , contents } ) ) ,
71
- ) ,
71
+ readFile ( fileName , "utf-8" ) . then ( ( svg ) => parse ( svg ) . then ( ( contents ) => resolve ( { file : fileName , contents } ) ) ) ,
72
72
) ;
73
73
}
74
74
75
75
module . exports = function generatePathFile ( ) {
76
- let banner =
77
- "// File generated automatically by path-data.js, do not edit directly\n" ;
76
+ let banner = "// File generated automatically by path-data.js, do not edit directly\n" ;
78
77
let jsFile = `${ banner } ` ;
79
78
let tsFile = `
80
79
${ banner }
@@ -89,11 +88,10 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
89
88
. then ( ( files ) => files . map ( formatSVG ) )
90
89
. then ( ( files ) => {
91
90
let icons = { } ;
92
- let keywords = JSON . parse ( fs . readFileSync ( "docs/keywords.json" , "utf-8" ) ) ;
91
+ let keywords = JSON . parse ( readFileSync ( "docs/keywords.json" , "utf-8" ) ) ;
93
92
files . forEach ( ( file ) => {
94
93
// add to json file
95
- icons [ file . variant ] = icons [ file . variant ] ||
96
- keywords [ file . variant ] || { alias : [ ] , category : "" , release : "" } ;
94
+ icons [ file . variant ] = icons [ file . variant ] || keywords [ file . variant ] || { alias : [ ] , category : "" , release : "" } ;
97
95
var icon = icons [ file . variant ] ;
98
96
const firstPath = file . paths [ 0 ] || { d : "" } ; // back up for "blank" icon
99
97
const paths = file . paths . length > 1 ? file . paths : firstPath . d ;
@@ -109,12 +107,8 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
109
107
}
110
108
}
111
109
// add to ts and js files
112
- const variant = file . variant . match ( / ^ \d / )
113
- ? `i${ file . variant } `
114
- : file . variant ;
115
- const camelCaseName = camelCase (
116
- `${ file . filled ? base : variant } -${ file . size } ${ file . filled ? "-f" : "" } ` ,
117
- ) ;
110
+ const variant = file . variant . match ( / ^ \d / ) ? `i${ file . variant } ` : file . variant ;
111
+ const camelCaseName = camelCase ( `${ file . filled ? base : variant } -${ file . size } ${ file . filled ? "-f" : "" } ` ) ;
118
112
jsFile += `export {${ camelCaseName } } from "./js/${ camelCaseName } .js";\n` ;
119
113
120
114
let contents , tsContents ;
@@ -129,18 +123,14 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
129
123
tsContents = `export const ${ camelCaseName } : CalciteMultiPathEntry[];\n` ;
130
124
}
131
125
132
- fs . writeFile ( `js/${ camelCaseName } .js` , contents , "utf8" ) ;
133
- fs . writeFile ( `js/${ camelCaseName } .d.ts` , tsContents , "utf8" ) ;
134
- fs . writeFile ( `js/${ camelCaseName } .json` , JSON . stringify ( paths ) , "utf8" ) ;
126
+ writeFile ( `js/${ camelCaseName } .js` , contents , "utf8" ) ;
127
+ writeFile ( `js/${ camelCaseName } .d.ts` , tsContents , "utf8" ) ;
128
+ writeFile ( `js/${ camelCaseName } .json` , JSON . stringify ( paths ) , "utf8" ) ;
135
129
} ) ;
136
130
let promises = [
137
- fs . writeFile (
138
- "docs/icons.json" ,
139
- JSON . stringify ( { version, icons } ) ,
140
- "utf8" ,
141
- ) ,
142
- fs . writeFile ( "index.d.ts" , tsFile , "utf8" ) ,
143
- fs . writeFile ( "index.js" , jsFile , "utf8" ) ,
131
+ writeFile ( "docs/icons.json" , JSON . stringify ( { version, icons } ) , "utf8" ) ,
132
+ writeFile ( "index.d.ts" , tsFile , "utf8" ) ,
133
+ writeFile ( "index.js" , jsFile , "utf8" ) ,
144
134
] ;
145
135
return Promise . all ( promises ) ;
146
136
} ) ;
0 commit comments