Nuxt/docs/scripts/map-redirects.js
renovate[bot] 0b1cdcc70d
chore(deps): update devdependency @nuxtjs/eslint-config-typescript to v12 (#9086)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
2023-01-14 01:13:48 +00:00

32 lines
947 B
JavaScript

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { readFile, writeFile } = require('node:fs/promises')
const netlifyToVercel = (redirects) => {
return JSON.stringify(
{
redirects: redirects.split('\n')
.filter(s => s !== '' && !s.startsWith('#'))
.map((line) => {
const [source, destination] = line.split(' /')
return {
source: source.replace('*', ':path').trim(),
destination: `/${destination.replace(' 302!', '').replace(':splat', ':path').trim()}`,
permanent: false
}
})
}, null, 2)
}
async function transformRedirects () {
try {
const redirectsFile = await readFile('../public/_redirects', 'utf-8')
const vercelConfig = netlifyToVercel(redirectsFile)
console.log(vercelConfig)
await writeFile('../public/vercel.json', vercelConfig)
} catch (e) {
console.error(e)
}
}
transformRedirects()