-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_frame_svgs_script.js
49 lines (38 loc) · 1.26 KB
/
create_frame_svgs_script.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
const path = require('path');
const fs = require('fs');
start();
function start(){
startWirteSvgFile(function(){
});
}
/*
遍历app 目录 遍历项目 然后遍历项目模块
每个模块目录下的assets/svg 目录 确定有的话开始读取
然后写入到assets 到svgs.js 文件
*/
function startWirteSvgFile(successCallBack){
var svgDir = "./src/components/icon/svgs";
writeSvgFile(svgDir);
console.log("success ");
}
function exists(_path){
return fs.existsSync(_path);
}
function writeSvgFile(dirpath){
if(fs.existsSync(dirpath)){
var Re = {};
var files = fs.readdirSync(dirpath);
files.forEach(function(filename) {
var fnArr = filename.split(".");
if(fnArr.length===2&&fnArr[1]==="svg"){
var data = fs.readFileSync(dirpath+"/"+filename,'utf-8');
data = data.replace(/<\?xml.*?\?>|<!--.*?-->|<path fill='#[a-zA-Z0-9]'|<!DOCTYPE.*?>/g, '');
data = data.replace(/<path fill="#[a-zA-Z0-9]+"|<path/g, '<path fill="#ef473a"');
data = data.replace(/\sclass="[\w|\-|\_]*"/g,'');
data = data.replace(/\sstyle="[\w|\-|\_]*"/g,'');
Re[fnArr[0]] = data;
}
});
fs.writeFileSync("./src/components/icon/svgs.js", "export default " + JSON.stringify(Re));
}
}