@@ -13,8 +13,15 @@ const pick = require('lodash.pick')
1313 svgPath : path
1414 } ) )
1515
16+ const lightIcons = Object . entries ( require ( '@mdi/light-js' ) )
17+ . filter ( ( [ name ] ) => name . indexOf ( 'mdil' ) === 0 )
18+ . map ( ( [ name , path ] ) => ( {
19+ name : pascalCase ( name . substr ( 4 ) ) , // remove mdil prefix
20+ svgPath : path
21+ } ) )
22+
1623 fse . removeSync ( path . join ( __dirname , 'package' ) )
17- fse . mkdirpSync ( path . join ( __dirname , 'package' ) )
24+ fse . mkdirpSync ( path . join ( __dirname , 'package' , 'light' ) )
1825
1926 for ( const { name, svgPath } of icons ) {
2027 const code = `import createIcon from './util/createIcon'
@@ -32,18 +39,39 @@ const pick = require('lodash.pick')
3239 ` )
3340 }
3441
35- // es2015 module syntax
36- const allExports = icons . map ( ( { name } ) => `export { default as ${ name } } from './${ name } '` ) . join ( '\n' )
37- fse . writeFileSync ( path . join ( __dirname , 'package' , 'index.es.js' ) , allExports )
42+ for ( const { name, svgPath } of lightIcons ) {
43+ const code = `import createIcon from '../util/createIcon'
44+ export default createIcon('${ svgPath } ')
45+ `
46+
47+ // commonjs module syntax
48+ fse . writeFileSync ( path . join ( __dirname , 'package' , 'light' , `${ name } .js` ) , babel . transform ( code , {
49+ presets : [ 'es2015' , 'react' , 'stage-0' ] ,
50+ compact : process . env . NODE_ENV === 'production'
51+ } ) . code )
52+
53+ // typescript definition
54+ fse . writeFileSync ( path . join ( __dirname , 'package' , 'light' , `${ name } .d.ts` ) , `export { default } from '@material-ui/core/SvgIcon'
55+ ` )
56+ }
3857
39- // typescript index definition (looks exactly the same)
40- fse . writeFileSync ( path . join ( __dirname , 'package' , 'index.d.ts' ) , allExports )
58+ const generateIndexFiles = ( destination , icons ) => {
59+ // es2015 module syntax
60+ const allExports = icons . map ( ( { name } ) => `export { default as ${ name } } from './${ name } '` ) . join ( '\n' )
61+ fse . writeFileSync ( path . join ( destination , 'index.es.js' ) , allExports )
62+
63+ // typescript index definition (looks exactly the same)
64+ fse . writeFileSync ( path . join ( destination , 'index.d.ts' ) , allExports )
65+
66+ // commonjs module
67+ fse . writeFileSync ( path . join ( destination , 'index.js' ) , babel . transform ( allExports , {
68+ plugins : [ 'transform-es2015-modules-commonjs' ] ,
69+ compact : process . env . NODE_ENV === 'production'
70+ } ) . code )
71+ }
4172
42- // commonjs module
43- fse . writeFileSync ( path . join ( __dirname , 'package' , 'index.js' ) , babel . transform ( allExports , {
44- plugins : [ 'transform-es2015-modules-commonjs' ] ,
45- compact : process . env . NODE_ENV === 'production'
46- } ) . code )
73+ generateIndexFiles ( path . join ( __dirname , 'package' ) , icons )
74+ generateIndexFiles ( path . join ( __dirname , 'package' , 'light' ) , lightIcons )
4775
4876 // createIcon function
4977 fse . mkdirSync ( path . join ( __dirname , 'package' , 'util' ) )
@@ -57,8 +85,10 @@ const pick = require('lodash.pick')
5785
5886 // update readme
5987 const mdiVersion = require ( path . join ( require . resolve ( '@mdi/js' ) , '..' , '..' , 'package.json' ) ) . version
88+ const mdiLightVersion = require ( path . join ( require . resolve ( '@mdi/light-js' ) , '..' , '..' , 'package.json' ) ) . version
6089 let readme = await fse . readFile ( path . join ( __dirname , 'README.md' ) , 'utf-8' )
6190 readme = readme . replace ( / i m g \. s h i e l d s \. i o \/ b a d g e \/ m d i - v ( .+ ?) - b l u e \. s v g / g, `img.shields.io/badge/mdi-v${ mdiVersion } -blue.svg` )
91+ readme = readme . replace ( / i m g \. s h i e l d s \. i o \/ b a d g e \/ m d i - - l i g h t - v ( .+ ?) - b l u e \. s v g / g, `img.shields.io/badge/mdi--light-v${ mdiLightVersion } -blue.svg` )
6292 await fse . writeFile ( path . join ( __dirname , 'README.md' ) , readme , 'utf-8' )
6393
6494 // copy other files
0 commit comments