-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
52 lines (40 loc) · 1.33 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const generateBMFont = require('msdf-bmfont-xml');
const fs = require('fs');
const yargs = require('yargs');
const readline = require('readline');
const { name } = yargs
.usage('Usage: --name <name>')
.option('n', { alias: 'name', describe: 'Font name', type: 'string', demandOption: false })
.argv;
const interface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
if (!name) {
interface.question('Font name : ', start);
} else {
start(name);
}
function start(name) {
const fontConfig = require(`./fonts/${name}/index.js`);
interface.close();
console.log(`\nGenerating font ${name}...`);
try {
generateBMFont(fontConfig.font, fontConfig.options, (error, textures, font) => {
if (error) throw error;
const { outputPath, filename } = fontConfig.options;
textures.forEach((texture) => {
fs.writeFile(`${outputPath}/${filename}.png`, texture.texture, (err) => {
if (err) throw err;
else return 1;
});
});
fs.writeFile(`${outputPath}/${filename}.fnt`, font.data, (err) => {
if (err) throw err;
else return 1;
});
});
} catch (err) {
console.error(err);
}
}