mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
dc47c64f14
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> Co-authored-by: Pooya Parsa <pooya@pi0.io> Co-authored-by: pooya parsa <pyapar@gmail.com> Co-authored-by: Clément Ollivier <clement.o2p@gmail.com>
31 lines
884 B
JavaScript
31 lines
884 B
JavaScript
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()
|