Skip to content

Commit

Permalink
improve script and catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Oct 15, 2024
1 parent c50693f commit be5705f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions get-express-version.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { writeFileSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
import { readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'

const NPMURL = 'https://registry.npmjs.org/express'

const response = await fetch(NPMURL).then((res) => res.json())
const response = await (await fetch(NPMURL)).json()

const { next, latest } = response['dist-tags']

const contentFile = await readFile(
path.resolve(path.join('_data', 'express.yml')),
'utf8'
)
.then((content) =>
content.replace(/current_version: ".*"/, `current_version: "${latest}"`)
)
.then((content) =>
content.replace(/next_version: ".*"/, `next_version: "${next}"`)
)
try {
const filePath = path.resolve(path.join('_data', 'express.yml'))
let content = await readFile(filePath, 'utf8')

writeFileSync('_data/express.yml', contentFile)
content = content.replace(/current_version: ".*"/, `current_version: "${latest}"`)
content = content.replace(/next_version: ".*"/, `next_version: "${next}"`)

await writeFile(filePath, content, 'utf8')
} catch (error) {
console.error('Error updating versions in _data/express.yml:', error)
}

0 comments on commit be5705f

Please sign in to comment.