import normalize from 'normalize-path' ; import { ServerRoute as ModernRoute } from '@modern-js/types' ; import { SsgRoute } from '../types' ; export function exist ( route , pageRoutes ) { return pageRoutes . slice ( ) . findIndex ( pageRoute => { const urlEqual = normalize ( pageRoute . urlPath ) === normalize ( route . urlPath ) ; const entryEqual = pageRoute . entryName === route . entryName ; if ( urlEqual && entryEqual ) { return true ; } return false ; } ) ; } export function replaceRoute ( ssgRoutes , pageRoutes ) { const cleanSsgRoutes = ssgRoutes . map ( ssgRoute => { const { output , headers , ... cleanSsgRoute } = ssgRoute ; return Object . assign ( cleanSsgRoute , output ? { entryPath : output } : { } ) as ModernRoute ; } ) ; const freshRoutes = [ ] ; cleanSsgRoutes . forEach ( ssgRoute => { const index = exist ( ssgRoute , pageRoutes ) ; if ( index < 0 ) { freshRoutes . push ( { ... ssgRoute } ) ; } else { pageRoutes [ index ] . entryPath = ssgRoute . entryPath ; } } ) ; pageRoutes . push ( ... freshRoutes ) ; return pageRoutes ; }