Bilibili-Evolved/registry/lib/components/utils/dev-client/converter.ts
2022-05-24 23:10:45 +08:00

25 lines
808 B
TypeScript

import { getDevClientOptions } from './options'
const options = getDevClientOptions()
export const urlConverter = {
toDevUrl: (originalUrl: string) => {
if (!originalUrl) {
return null
}
const devUrlMatch = originalUrl.match(new RegExp(`localhost:${options.port}\\/registry\\/components\\/(.+)$`))
if (devUrlMatch) {
return originalUrl
}
const localhostMatch = originalUrl.match(/localhost:(\d+?)\/components\/(.+)$/)
if (localhostMatch) {
return `http://localhost:${options.port}/registry/dist/components/${localhostMatch[2]}`
}
const onlineMatch = originalUrl.match(/\/registry\/dist\/components\/(.+)$/)
if (onlineMatch) {
return `http://localhost:${options.port}/registry/dist/components/${onlineMatch[1]}`
}
return null
},
}