-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (33 loc) · 1.22 KB
/
index.js
File metadata and controls
37 lines (33 loc) · 1.22 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
#!/usr/bin/env node
console.log('Begin..');
const createHTML = require('./createHtml');
const program = require('commander');
const xml2js = require('xml2js');
const fs = require('fs');
let out = '.';
let file = '';
program
.arguments('<file>')
.option('-o, --out <path>', 'output file path')
.action(function(infile) {
console.log('file: %s out: %s', file, program.out );
out = program.out || '.';
file = infile.replace(/\..*/, '');;
const xml2json = async(xml) => {
const json = await xml2js(xml);
return json;
};
let xml = fs.readFileSync(file + '.svg', 'utf8');
//unicode=" "
xml = xml.toString().replace("\ufeff", "").replace(/unicode\=\"\&\#x(.*?)\;\"/g, 'unicode\=\"\\$1\"');
var parser = new xml2js.Parser();
parser.parseString(xml, (err, json) => {
console.log(JSON.stringify(json.svg.defs[0].font[0].$.id));
if (!fs.existsSync(out)) {
fs.mkdirSync(out);
}
out !== '.' && fs.copyFileSync(`${file}.ttf`, `${out}/${file}.ttf`);
fs.writeFileSync(`${out}/${file}.html`, createHTML(json, file));
});
})
.parse(process.argv);