1 | const fs = require('mz/fs')
|
2 | const morphSvgToView = require('./svg-to-view.js')
|
3 |
|
4 | const svgCustomStyles = [
|
5 | 'alignSelf props.alignSelf',
|
6 | 'flex props.flex',
|
7 | 'margin props.margin',
|
8 | 'marginTop props.marginTop',
|
9 | 'marginBottom props.marginBottom',
|
10 | 'marginLeft props.marginLeft',
|
11 | 'marginRight props.marginRight',
|
12 | ]
|
13 |
|
14 | module.exports = async svgFile => {
|
15 | const content = await fs.readFile(svgFile, 'utf-8')
|
16 |
|
17 | return (await morphSvgToView(content))
|
18 | .split('\n')
|
19 | .map(
|
20 | line =>
|
21 | line === 'Svg'
|
22 | ? `Svg\n${svgCustomStyles.join('\n')}`
|
23 | : line.startsWith('width')
|
24 | ? line.replace('width', 'width props.width || ')
|
25 | : line.startsWith('height')
|
26 | ? line.replace('height', 'height props.height || ')
|
27 | : line
|
28 | )
|
29 | .join('\n')
|
30 | }
|