@@ -15,11 +15,8 @@ const DST_ICONS_ESM = path.join(DST_ICONS_DIR, 'index.mjs');
1515const DST_ICONS_CJS = path . join ( DST_ICONS_DIR , 'index.js' ) ;
1616const DST_ICONS_DTS = path . join ( DST_ICONS_DIR , 'index.d.ts' ) ;
1717
18- const DST_ICONS_IMPORTS_DIR = path . join ( DST_ICONS_DIR , 'imports' ) ;
19-
2018
2119fs . emptyDirSync ( DST_ICONS_DIR ) ;
22- fs . emptyDirSync ( DST_ICONS_IMPORTS_DIR ) ;
2320
2421console . log ( 'checking icon data: ' + SRC_JSON ) ;
2522
@@ -68,13 +65,13 @@ function camelize(text) {
6865
6966
7067const moduleData = { } ;
71- const esmIndex = [
68+ const esm = [
7269 `/* Ionicons, ES Modules */` , ``
7370] ;
74- const cjsIndex = [
71+ const cjs = [
7572 `/* Ionicons, CommonJS */` , ``
7673] ;
77- const dtsIndex = [
74+ const dts = [
7875 `/* Ionicons, Types */` , ``
7976] ;
8077
@@ -119,8 +116,6 @@ svgFiles.forEach(fileName => {
119116 modes : { }
120117 } ;
121118 moduleData [ exportCommonName ] = commonIconData ;
122-
123- esmIndex . push ( `import ${ exportCommonName } from './imports/${ commonName } .mjs';` ) ;
124119 }
125120
126121 commonIconData . modes [ mode ] = {
@@ -131,76 +126,66 @@ svgFiles.forEach(fileName => {
131126 } ;
132127} ) ;
133128
134- esmIndex . push ( `` ) ;
135-
136129
137130const sortedKeys = Object . keys ( moduleData ) . sort ( ) ;
138131
139132sortedKeys . forEach ( key => {
140133 const d = moduleData [ key ] ;
141- const esmFilePath = path . join ( DST_ICONS_IMPORTS_DIR , d . commonName + '.mjs' ) ;
142- const cjsFilePath = path . join ( DST_ICONS_IMPORTS_DIR , d . commonName + '.js' ) ;
143- const esm = [ ] ;
144- const cjs = [ ] ;
145-
146134 const modes = Object . keys ( d . modes ) . sort ( ) ;
147135
148136 if ( modes . length > 1 ) {
149- for ( let i = 0 ; i < modes . length ; i ++ ) {
150- const mode = modes [ i ] ;
151- esm . push ( `import ${ mode } from '../../dist/ionicons/svg/${ d . modes [ mode ] . fileName } ';` ) ;
152- }
153-
154- esm . push ( `` ) ;
155- esm . push ( `export default /*#__PURE__*/ {` ) ;
156-
157- cjs . push ( `module.exports = /*#__PURE__*/ {` ) ;
158-
159- dtsIndex . push ( `export declare var ${ d . exportCommonName } : {` ) ;
137+ esm . push ( `export const ${ d . exportCommonName } = {` ) ;
138+ cjs . push ( `exports.${ d . exportCommonName } = {` ) ;
139+ dts . push ( `export declare var ${ d . exportCommonName } : {` ) ;
160140
161141 for ( let i = 0 ; i < modes . length ; i ++ ) {
162142 const mode = modes [ i ] ;
163143 const suffix = i < modes . length - 1 ? ',' : '' ;
164144
165- esm . push ( ` ${ mode } : ${ mode } ${ suffix } ` ) ;
145+ const svgContent = getDataUrl ( d . modes [ mode ] . fileName ) ;
166146
167- cjs . push ( ` ${ mode } : require('../../dist/ionicons/svg/${ d . modes [ mode ] . fileName } ')${ suffix } ` ) ;
147+ esm . push ( ` ${ mode } : ${ svgContent } ${ suffix } ` ) ;
148+ cjs . push ( ` ${ mode } : ${ svgContent } ${ suffix } ` ) ;
168149
169- dtsIndex . push ( ` ${ mode } : string;` ) ;
150+ dts . push ( ` ${ mode } : string;` ) ;
170151 }
171152
172153 esm . push ( `};` ) ;
173154 cjs . push ( `};` ) ;
174- dtsIndex . push ( `};` ) ;
155+ dts . push ( `};` ) ;
175156
176157 } else {
177- esm . push ( `import icon from '../../dist/ionicons/svg/${ d . fileName } '` ) ;
178- esm . push ( `` ) ;
179- esm . push ( `export default /*#__PURE__*/ icon;` ) ;
180-
181- cjs . push ( `module.exports = /*#__PURE__*/ require('../../dist/ionicons/svg/${ d . fileName } ');` ) ;
158+ const svgContent = getDataUrl ( d . fileName ) ;
182159
183- dtsIndex . push ( `export declare var ${ d . exportCommonName } : string;` ) ;
184- }
160+ esm . push ( `export const ${ d . exportCommonName } = ${ svgContent } ;` ) ;
185161
186- esmIndex . push ( `export { ${ d . exportCommonName } } ` ) ;
162+ cjs . push ( `exports. ${ d . exportCommonName } = ${ svgContent } ; ` ) ;
187163
188- cjsIndex . push ( `exports.${ d . exportCommonName } = /*#__PURE__*/ require('./imports/${ d . commonName } .js');` ) ;
189-
190- fs . writeFileSync ( esmFilePath , esm . join ( '\n' ) ) ;
191- fs . writeFileSync ( cjsFilePath , cjs . join ( '\n' ) ) ;
164+ dts . push ( `export declare var ${ d . exportCommonName } : string;` ) ;
165+ }
192166} ) ;
193167
194- fs . writeFileSync ( DST_ICONS_ESM , esmIndex . join ( '\n' ) + '\n' ) ;
195- fs . writeFileSync ( DST_ICONS_CJS , cjsIndex . join ( '\n' ) + '\n' ) ;
196- fs . writeFileSync ( DST_ICONS_DTS , dtsIndex . join ( '\n' ) + '\n' ) ;
168+ fs . writeFileSync ( DST_ICONS_ESM , esm . join ( '\n' ) + '\n' ) ;
169+ fs . writeFileSync ( DST_ICONS_CJS , cjs . join ( '\n' ) + '\n' ) ;
170+ fs . writeFileSync ( DST_ICONS_DTS , dts . join ( '\n' ) + '\n' ) ;
197171
198172fs . writeFileSync ( DST_ICONS_PKGJSON , JSON . stringify ( {
199173 "name" : "ionicons/icons" ,
200- "main" : "index.mjs" ,
174+ "module" : "index.mjs" ,
175+ "main" : "index.js" ,
201176 "typings" : "index.d.ts" ,
202- "sideEffects" : [
203- "imports/"
204- ] ,
205177 "private" : true
206178} , null , 2 ) ) ;
179+
180+ function getDataUrl ( filePath ) {
181+ filePath = path . join ( __dirname , '..' , 'dist' , 'ionicons' , 'svg' , filePath ) ;
182+ let svg = fs . readFileSync ( filePath , 'utf8' ) ;
183+ if ( svg . includes ( `'` ) ) {
184+ throw new Error ( `oh no! no single quotes allowed! ${ filePath } ` ) ;
185+ }
186+ if ( svg . includes ( `\n` ) || svg . includes ( `\r` ) ) {
187+ throw new Error ( `oh no! no new lines allowed! ${ filePath } ` ) ;
188+ }
189+ svg = svg . replace ( / " / g, "'" ) ;
190+ return `"data:image/svg+xml;utf8,${ svg } "` ;
191+ }
0 commit comments