-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertSVG.js
More file actions
48 lines (43 loc) · 1.52 KB
/
convertSVG.js
File metadata and controls
48 lines (43 loc) · 1.52 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
// This is a nodejs script that will convert all .svg files to .png files for vscode publishing
const { svg2png } = require('svg-png-converter');
const fs = require("fs");
const { exit } = require('process');
let basedir = __dirname+"/resources";
let verbose = process.argv.includes("-v") || process.argv.includes("--verbose");
if(process.argv.includes("--help") || process.argv.includes("-h")){
console.log(
`CLI Options
-v --verbose Enable verbose output
-h --help Display this information
`);
exit(0);
}
async function parseDir(path){
let files = fs.readdirSync(path);
for(let name of files){
let f = path+"/"+name;
let stat = fs.lstatSync(f);
if(stat.isDirectory()){
parseDir(f);
} else if(name.endsWith(".svg")) {
let png = f.replace(/\.svg$/, ".png");
if(!fs.existsSync(png) || stat.mtime.getTime() > fs.lstatSync(png).mtime.getTime()){
console.log("Convert: "+f.replace(basedir+"/", ""));
try{
svg2png({
input:fs.readFileSync(f),
encoding:"buffer",
format:'png'
}).then((buffer)=>{
fs.writeFileSync(png, buffer);
});
} catch(e){
console.warn(e+"\n");
}
} else {
if(verbose){console.log("Skipped: "+f.replace(basedir+"/", ""));}
}
}
}
}
parseDir(basedir);