mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 18:13:54 +00:00
0b1cdcc70d
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
32 lines
947 B
JavaScript
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()
|