-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
executable file
·34 lines (27 loc) · 955 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const args = process.argv.slice(2);
const inDir = args[0];
const outFile = args[1];
let output = 'this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = {';
try {
if (!fs.existsSync(inDir)) {
throw new Error(`${inDir} does not exists`);
}
if (path.extname(outFile) !== '.js') {
throw new Error(`${outFile} must be a .js file`);
}
const readFiles = fs.readdirSync(inDir, { encoding: 'utf8' });
for (let filename of readFiles) {
const path = `${inDir}/${filename}`;
if (fs.lstatSync(path).isFile()) {
const fileContent = fs.readFileSync(path);
output += `"${filename}":"${fileContent.toString('base64')}",`;
}
}
fs.writeFileSync(outFile, output.substr(0, output.length -1) + '};');
console.log('The fonts were generated.');
} catch (err) {
console.log(err.message);
}