@@ -14,17 +14,21 @@ class IconLibraryCompiler {
1414 constructor ( ) {
1515 this . rootDir = join ( __dirname , '..' ) ;
1616 this . paths = {
17+ collection : {
18+ file : 'collection.generated.json' ,
19+ destination : 'lib' ,
20+ } ,
1721 svg : {
1822 source : 'src/icons' ,
19- destination : 'dist /icons' ,
23+ destination : 'lib /icons' ,
2024 } ,
2125 sass : {
2226 source : 'src/styles/main.scss' ,
23- destination : 'dist /styles/main.css' ,
27+ destination : 'lib /styles/main.css' ,
2428 } ,
2529 sprite : {
2630 file : 'icons.sprite.svg' ,
27- destination : 'dist /icons' ,
31+ destination : 'lib /icons' ,
2832 }
2933 } ;
3034 }
@@ -38,9 +42,9 @@ class IconLibraryCompiler {
3842 let items = [ ] ;
3943
4044 try {
41- await readdir ( directory , ( err , files ) => {
45+ items = await readdir ( directory , ( err , files ) => {
46+ console . log ( 'Files:' , files )
4247 if ( err ) throw Error ( err . message ) ;
43- items = files ;
4448 } ) ;
4549 } catch {
4650 return await mkdir ( directory , {
@@ -51,6 +55,19 @@ class IconLibraryCompiler {
5155 return Promise . all ( items . map ( ( item ) => rm ( join ( directory , item ) , { recursive : true } ) ) ) ;
5256 }
5357
58+ /**
59+ * Writes the collected icons to a json file
60+ * @param svgData
61+ * @returns {Promise<void> }
62+ */
63+ async createIconCollection ( svgData ) {
64+ let map = { } ;
65+ const dist = join ( this . rootDir , this . paths . collection . destination , this . paths . collection . file ) ;
66+ svgData . map ( ( data ) => ( map [ data . key ] = data . optimizedSvg ) ) ;
67+
68+ return await writeFile ( dist , JSON . stringify ( map ) ) ;
69+ }
70+
5471 /**
5572 * Returns the SVG data from source directory
5673 * @returns {Promise<Awaited<{optimizedSvg: string, iconName: *, title: string, iconFileName: *, key: *}>[]> }
@@ -176,6 +193,7 @@ class IconLibraryCompiler {
176193 await this . emptyDirectory ( join ( this . rootDir , this . paths . svg . destination ) ) ;
177194 await this . emptyDirectory ( join ( this . rootDir , this . paths . sass . destination . substring ( 0 , this . paths . sass . destination . lastIndexOf ( '/' ) ) ) ) ;
178195 const svgData = await this . getSvgsData ( ) ;
196+ await this . createIconCollection ( svgData ) ;
179197 await this . createSvgIconFiles ( svgData ) ;
180198 await this . createSassStyles ( svgData ) ;
181199 await this . createSvgSprite ( svgData ) ;
@@ -187,4 +205,4 @@ class IconLibraryCompiler {
187205}
188206
189207const iconCompiler = new IconLibraryCompiler ( ) ;
190- iconCompiler . compileIcons ( ) . then ( ( ) => console . log ( "Successful compiled!" ) ) ;
208+ iconCompiler . compileIcons ( ) . then ( ( ) => console . log ( "Successful compiled Icon library static assets !" ) ) ;
0 commit comments