mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-18 01:30:39 +01:00
fix: Fix using __dirname in the games_list.md generator tool
This commit is contained in:
parent
371fad3eab
commit
4092fe38d7
2 changed files with 26 additions and 21 deletions
26
tools/generate_games_list.js
Normal file
26
tools/generate_games_list.js
Normal 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)
|
|
@ -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)
|
|
Loading…
Reference in a new issue