forked from styled-system/styled-system
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (32 loc) · 801 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { getOptions } = require('loader-utils')
const stringify = str => `'${str}'`
const createModule = ({
name,
type,
props = {},
css,
styles = []
}) => (`
export const ${name} = sys(
${JSON.stringify(
Object.assign({}, props, type ? { is: type } : null),
null, 2)},
${css ? `${stringify(css)},` : ''}
${styles.map(stringify).join(',\n')}
)
${name}.displayName = '${name}'
`)
module.exports = function (src) {
const callback = this.async()
const opts = getOptions(this)
const config = JSON.parse(src)
const names = config.components.map(c => c.name)
const modules = config.components.map(createModule)
const code = `
import sys from 'system-components'
${modules.join('\n\n')}
export default {
${names.join(',\n')}
}`
callback(null, code)
}