-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·36 lines (30 loc) · 819 Bytes
/
cli.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
#!/usr/bin/env node
const TextToSVG = require('text-to-svg');
const write = require('write')
const fs = require('fs');
const minimist = require('minimist-mini')
function getConfig(path) {
const rawdata = fs.readFileSync(path);
return JSON.parse(rawdata);
}
const opts = [];
opts.boolean = ['help'];
opts.string = ['config'];
const cli = minimist(opts)
// Check config file is set.
// If not exit
const config = cli.get('config');
if (!config){
cli.helpMessage();
process.exit(1);
}
try {
const options = getConfig(config);
const textToSVG = TextToSVG.loadSync(options.font);
const svg = textToSVG.getSVG(options.text, options.options);
write.sync(options.save_path, svg, { overwrite: true });
process.exit(0);
} catch (error) {
console.log(error);
process.exit(1);
}