-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSvg.js
More file actions
39 lines (33 loc) · 906 Bytes
/
Copy pathcreateSvg.js
File metadata and controls
39 lines (33 loc) · 906 Bytes
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
/**
* Takes svg's from folder (svgsPath) and outputs json file to outputPath and creates file with
* name outputFileName
*/
const fs = require('fs');
const svgsPath = './icons/';
const outputPath = './src/assets/icons/';
const outputFileName ='svg.json';
try {
fs.readdir(svgsPath, function (err, files) {
if (err) {
console.log(err);
return;
}
const result = {};
files
.filter( function(elm) {
return elm.match(/.*\.(svg)/ig);
})
.forEach(function (file) {
const path = svgsPath + file;
result[file] = fs.readFileSync(path, 'utf8');
});
fs.writeFile(outputPath + outputFileName, JSON.stringify(result), 'utf8', function (err) {
if (err) {
console.log(err);
}
});
});
}
catch(err){
if (err) throw err;
}