fix: Fix using __dirname in the games_list.md generator tool

This commit is contained in:
CosminPerRam 2023-11-12 19:53:35 +02:00
parent 371fad3eab
commit 4092fe38d7
2 changed files with 26 additions and 21 deletions

View file

@ -0,0 +1,26 @@
#!/usr/bin/env node
import * as fs from 'node:fs'
import GameResolver from '../lib/GameResolver.js'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
const gameResolver = new GameResolver()
const generated = gameResolver.printReadme()
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const readmeFilename = __dirname + '/../GAMES_LIST.md'
const readme = fs.readFileSync(readmeFilename, { encoding: 'utf8' })
const markerTop = '<!--- BEGIN GENERATED GAMES -->'
const markerBottom = '<!--- END GENERATED GAMES -->'
let start = readme.indexOf(markerTop)
start += markerTop.length
const end = readme.indexOf(markerBottom)
const updated = readme.substring(0, start) + '\n\n' + generated + '\n' + readme.substring(end)
fs.writeFileSync(readmeFilename, updated)

View file

@ -1,21 +0,0 @@
#!/usr/bin/env node
import * as fs from 'node:fs'
import GameResolver from '../lib/GameResolver.js'
const gameResolver = new GameResolver()
const generated = gameResolver.printReadme()
const readmeFilename = __dirname + '/../README.md'
const readme = fs.readFileSync(readmeFilename, { encoding: 'utf8' })
const marker_top = '<!--- BEGIN GENERATED GAMES -->'
const marker_bottom = '<!--- END GENERATED GAMES -->'
let start = readme.indexOf(marker_top)
start += marker_top.length
const end = readme.indexOf(marker_bottom)
const updated = readme.substring(0, start) + '\n\n' + generated + '\n' + readme.substring(end)
fs.writeFileSync(readmeFilename, updated)