Skip to content

Commit 92f729d

Browse files
committed
only build CHR when needed
1 parent 694d69c commit 92f729d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

build.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ const mappers = [1, 3, 4, 5];
1313
const args = process.argv.slice(2);
1414

1515
if (args.includes('-h')) {
16-
console.log(`usage: node [-h] [-v] [-m<${mappers.join('|')}>] [-a] [-s] [-k] [-w]
16+
console.log(`usage: node build.js [-h] [-v] [-m<${mappers.join('|')}>] [-a] [-s] [-k] [-w]
1717
1818
-m mapper
1919
-a faster aeppoz + press select to end game
2020
-s disable highscores/SRAM
2121
-k Famicom Keyboard support
2222
-w force WASM compiler
23+
-c force PNG to CHR conversion
2324
-h you are here
2425
`);
2526
process.exit(0);
@@ -92,9 +93,18 @@ const dir = path.join(__dirname, 'src', 'chr');
9293
fs.readdirSync(dir)
9394
.filter((name) => name.endsWith('.png'))
9495
.forEach((name) => {
95-
const chr = png2chr(fs.readFileSync(path.join(dir, name)));
96-
const dst = path.join(dir, name.replace('.png', '.chr'));
97-
fs.writeFileSync(dst, chr);
96+
const png = path.join(dir, name);
97+
const chr = path.join(dir, name.replace('.png', '.chr'));
98+
99+
const pngStat = fs.statSync(png, { throwIfNoEntry: false });
100+
const chrStat = fs.statSync(chr, { throwIfNoEntry: false });
101+
102+
const staleCHR = !chrStat || chrStat.mtime < pngStat.mtime;
103+
104+
if (staleCHR || args.includes('-c')) {
105+
console.log(`${name} => ${path.basename(chr)}`);
106+
fs.writeFileSync(chr, png2chr(fs.readFileSync(png)));
107+
}
98108
});
99109

100110
console.timeEnd('CHR');

0 commit comments

Comments
 (0)