| 251 | /* ----- Version ---- */ |
| 252 | |
| 253 | function createVersionFile(done) { |
| 254 | // Get the current date |
| 255 | const currentDate = new Date(); |
| 256 | |
| 257 | // Get the year, month, and day components |
| 258 | const year = currentDate.getFullYear(); |
| 259 | // JavaScript months are 0-indexed, so we add 1 to get the actual month |
| 260 | const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); |
| 261 | const day = currentDate.getDate().toString().padStart(2, '0'); |
| 262 | |
| 263 | // Create the formatted date string in "YYYY-MM-DD" format |
| 264 | const formattedDate = `${year}-${month}-${day}`; |
| 265 | |
| 266 | // Get Git Commit Hash |
| 267 | const gitCommitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim(); |
| 268 | |
| 269 | const packageLockJson = JSON.parse(fs.readFileSync('./package-lock.json', { encoding: 'utf-8' })); |
| 270 | const fpaVersion = packageLockJson['packages']['node_modules/@fparchive/flashpoint-archive']['version']; |
| 271 | |
| 272 | const data = `export const VERSION = '${formattedDate} (${gitCommitHash})'; |
| 273 | export const VERSION_EPOCH = ${Date.now()}; |
| 274 | export const FPA_VERSION = '${fpaVersion}'; |
| 275 | `; |
| 276 | |
| 277 | // Write to src/shared/version.ts |
| 278 | fs.writeFile('src/shared/version.ts', data, (err) => { |
| 279 | if (err) { |
| 280 | throw `Error writing to version.ts: ${err}`; |
| 281 | } else { |
| 282 | console.log(`Build ver: "${formattedDate} (${gitCommitHash})"`); |
| 283 | done(); |
| 284 | } |
| 285 | }); |
| 286 | } |
| 287 | |
| 288 | /* ------ Pack ------ */ |
| 289 | |