forked from BoostIO/BoostNote-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportIcons.js
More file actions
executable file
·63 lines (59 loc) · 1.78 KB
/
Copy pathimportIcons.js
File metadata and controls
executable file
·63 lines (59 loc) · 1.78 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const fs = require('fs')
const fillRegex = new RegExp(`fill=[\"\']\#[a-zA-Z0-9]*[\"\']`, 'g')
fs.readdir('src/components/icons', function(err, filenames) {
if (err) {
console.log(err)
return
}
const exports = []
filenames.forEach(function(filename) {
exports.push(`export * from './${filename.split('.')[0]}'`)
try {
fs.readFile(`src/components/icons/${filename}`, 'utf8', function(
err,
data
) {
if (err) {
console.log(err)
return
}
const removeFillAttributeSplit = data
.split('export default')[0]
.replace('const Svg', 'export const Icon')
.replace('<svg ', '<BoostnoteIconStyledContainer><svg ')
.replace('= props', '= (props: BoostnoteIconProps)')
.replace(new RegExp('=1em', 'g'), '=0.9em')
.replace(
'{...props}',
'{...props} style={props.size != null ? {...props.style, width: props.size, height: props.size} : props.style}'
)
.replace('</svg>', '</svg></BoostnoteIconStyledContainer>')
.split(fillRegex)
const content = [
`import { BoostnoteIconProps, BoostnoteIconStyledContainer } from '../../lib/icons'`,
removeFillAttributeSplit.join('fill="currentColor"')
].join(`\n`)
fs.writeFile(
`src/components/icons/${filename.replace('js', 'tsx')}`,
content,
function(err2) {
if (err2) {
console.log(err2)
return
}
}
)
})
} catch (err) {
console.log('could not convert file')
}
})
fs.writeFile('src/components/icons/index.ts', exports.join('\n'), function(
err
) {
if (err) {
console.log(err)
return
}
})
})