From dc61560ef0021bf96dc3534e7d76aae3ef8a3204 Mon Sep 17 00:00:00 2001 From: leMaik Date: Sun, 3 Jun 2018 18:30:37 +0200 Subject: [PATCH] Set muiName property for generated icons. #14 --- generate-module.js | 14 ++++++++++++-- src/util/createIcon.js | 8 ++++++++ test.js | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/util/createIcon.js diff --git a/generate-module.js b/generate-module.js index 916baf6..ad76433 100755 --- a/generate-module.js +++ b/generate-module.js @@ -42,8 +42,8 @@ const pick = require('lodash.pick') for (const { name, svg } of icons) { const code = `import React from 'react' - import SvgIcon from 'material-ui/SvgIcon' - export default (props) => ${svg} + import createIcon from './util/createIcon' + export default createIcon(${svg}) ` // commonjs module syntax @@ -70,6 +70,16 @@ const pick = require('lodash.pick') compact: process.env.NODE_ENV === 'production' }).code) + // createIcon function + fse.mkdirSync(path.join(__dirname, 'package', 'util')) + fse.writeFileSync( + path.join(__dirname, 'package', 'util', 'createIcon.js'), + babel.transform(fse.readFileSync(path.join(__dirname, 'src', 'util', 'createIcon.js')), { + presets: ['es2015', 'react', 'stage-0'], + compact: process.env.NODE_ENV === 'production' + }).code + ) + // copy other files ;[ 'README.md', diff --git a/src/util/createIcon.js b/src/util/createIcon.js new file mode 100644 index 0000000..c916965 --- /dev/null +++ b/src/util/createIcon.js @@ -0,0 +1,8 @@ +import React from 'react' +import SvgIcon from 'material-ui/SvgIcon' + +export default (svg) => { + const Icon = (props) => {svg} + Icon.muiName = 'SvgIcon' + return Icon +} diff --git a/test.js b/test.js index 5c2d909..7026881 100644 --- a/test.js +++ b/test.js @@ -19,6 +19,7 @@ for (const iconName of Object.keys(commonjsIcons)) { ) ).toJSON() t.is(renderedIcon.type, 'svg') + t.is(commonjsIcons[iconName].muiName, 'SvgIcon') }) } test('ES module index file', (t) => {