@@ -13,13 +13,14 @@ const mappers = [1, 3, 4, 5];
13
13
const args = process . argv . slice ( 2 ) ;
14
14
15
15
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]
17
17
18
18
-m mapper
19
19
-a faster aeppoz + press select to end game
20
20
-s disable highscores/SRAM
21
21
-k Famicom Keyboard support
22
22
-w force WASM compiler
23
+ -c force PNG to CHR conversion
23
24
-h you are here
24
25
` ) ;
25
26
process . exit ( 0 ) ;
@@ -92,9 +93,18 @@ const dir = path.join(__dirname, 'src', 'chr');
92
93
fs . readdirSync ( dir )
93
94
. filter ( ( name ) => name . endsWith ( '.png' ) )
94
95
. 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
+ }
98
108
} ) ;
99
109
100
110
console . timeEnd ( 'CHR' ) ;
0 commit comments