-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert-svg.js
73 lines (56 loc) · 1.62 KB
/
insert-svg.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const jetpack = require('fs-jetpack');
const { basename } = require('path')
const svgs = jetpack.list('./src/svgs/');
for (let file in svgs) {
let filename = basename(svgs[file], '.svg');
let svgfilepath = jetpack.path('./src', 'svgs', filename + '.svg')
let jsfilepath = jetpack.path('./src', 'components', filename + '.js')
if (jetpack.exists(jsfilepath)) {
let jscontent = jetpack.read(jsfilepath);
let svgcontent = jetpack.read(svgfilepath);
if (jscontent.match(/const el = `(.*)`/gms)) {
let replacedSVG = `$1\`${svgcontent.trim()}\`$3`
jscontent = jscontent.replace(/(.*const el = )`(.*)`(.*)/gms, replacedSVG)
jetpack.write(jsfilepath, jscontent);
}
}
else {
let jscontent = `/**
* ${filename}
*/
const el = \`\`;
const ${filename} = ({id=true, color='#000000'} = {}) => {
let draw = SVG();
draw.svg(el);
// Add modifications here
// if(!id){
// let shape = draw.findOne('#id');
// shape.opacity(0);
// }
// if(color){
// let Shapes = draw.find('#id path');
// Shapes.forEach( shape => shape.fill(color) );
// }
return draw.findOne('svg').svg(false);
}
export default ${filename};
export const settings = () => {
let draw = SVG();
draw.svg(el);
let move = draw.findOne('#${filename}');
return {
"id": "${filename}",
"headerTitle": "${filename}",
"show": true,
"options": [
{ "type": "range", "name": "position", "value": move.x(), "label": "Position", "step": "1", "min": "0", "max": 1400 - move.width() },
]
}
}
export const legend = () => {
return ``
}
`
jetpack.write(jsfilepath, jscontent);
}
}