@@ -24,6 +24,7 @@ import util from 'util';
2424const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
2525
2626const UTF8 = 'utf8' ;
27+ const START_UNICODE = 0xea01 ;
2728
2829const ROOT_DIR = path . resolve ( __dirname , '..' ) ;
2930const DIST_DIR = path . join ( ROOT_DIR , 'font' ) ;
@@ -39,6 +40,8 @@ const EOT_OUTPUT_FILE = path.join(DIST_DIR, 'SimpleIcons.eot');
3940const OTF_OUTPUT_FILE = path . join ( DIST_DIR , 'SimpleIcons.otf' ) ;
4041const WOFF_OUTPUT_FILE = path . join ( DIST_DIR , 'SimpleIcons.woff' ) ;
4142const WOFF2_OUTPUT_FILE = path . join ( DIST_DIR , 'SimpleIcons.woff2' ) ;
43+ const DATA_JSON_OUTPUT_FILE = path . join ( DIST_DIR , 'SimpleIcons.json' ) ;
44+ const DATA_JSON_MIN_OUTPUT_FILE = path . join ( DIST_DIR , 'SimpleIcons.min.json' ) ;
4245
4346const CSS_BASE_FILE = path . resolve ( __dirname , 'templates' , 'base.css' ) ;
4447const SVG_TEMPLATE_FILE = path . join ( __dirname , 'templates' , 'font.svg' ) ;
@@ -57,7 +60,7 @@ const icons = await getIconsData();
5760const buildSimpleIconsSvgFontFile = async ( ) => {
5861 const usedUnicodes = [ ] ;
5962 const unicodeHexBySlug = [ ] ;
60- let startUnicode = 0xea01 ;
63+ let startUnicode = START_UNICODE ;
6164 let glyphsContent = '' ;
6265
6366 for ( const iconData of icons ) {
@@ -141,6 +144,34 @@ const buildSimpleIconsMinCssFile = (cssFileContent) =>
141144 }
142145 } ) ;
143146
147+ const buildSimpleIconsJsonFile = ( ) => {
148+ new Promise ( async ( resolve , reject ) => {
149+ try {
150+ const iconsWithSlugs = icons . map ( ( { title, slug, ...rest } , index ) => ( {
151+ title,
152+ slug : getIconSlug ( { title, slug } ) ,
153+ code : ( START_UNICODE + index ) . toString ( 16 ) ,
154+ ...rest ,
155+ } ) ) ;
156+ const jsonFileContent = JSON . stringify ( iconsWithSlugs , null , '\t' ) ;
157+ const minJsonFileContent = JSON . stringify ( iconsWithSlugs ) ;
158+
159+ await Promise . all ( [
160+ fs . writeFile ( DATA_JSON_OUTPUT_FILE , jsonFileContent ) . then ( ( ) => {
161+ console . log ( `'${ DATA_JSON_OUTPUT_FILE } ' file built` ) ;
162+ } ) ,
163+ fs . writeFile ( DATA_JSON_MIN_OUTPUT_FILE , minJsonFileContent ) . then ( ( ) => {
164+ console . log ( `'${ DATA_JSON_MIN_OUTPUT_FILE } ' file built` ) ;
165+ } ) ,
166+ ] ) ;
167+
168+ resolve ( ) ;
169+ } catch ( error ) {
170+ reject ( error ) ;
171+ }
172+ } ) ;
173+ } ;
174+
144175const buildSimpleIconsTtfFontFile = ( svgFileContent ) =>
145176 new Promise ( async ( resolve , reject ) => {
146177 try {
@@ -223,6 +254,7 @@ const main = async () => {
223254 Promise . all ( [
224255 buildSimpleIconsCssFile ( unicodeHexBySlug ) ,
225256 buildSimpleIconsTtfFontFile ( svgFileContent ) ,
257+ buildSimpleIconsJsonFile ( ) ,
226258 ] ) . then ( ( [ cssFileContent , ttfFileContent ] ) => {
227259 Promise . all ( [
228260 buildSimpleIconsWoffFontFile ( ttfFileContent ) ,
0 commit comments