29 lines
702 B
TypeScript
29 lines
702 B
TypeScript
export function fixImport(content: string) {
|
|
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
|
const regex = /@\/(.+?)\/((?:.*?\/)?(?:components|ui|hooks|lib))\/([\w-]+)/g
|
|
|
|
const replacement = (
|
|
match: string,
|
|
path: string,
|
|
type: string,
|
|
component: string,
|
|
) => {
|
|
if (type.endsWith('components')) {
|
|
return `@/components/${component}`
|
|
}
|
|
else if (type.endsWith('ui')) {
|
|
return `@/components/ui/${component}`
|
|
}
|
|
else if (type.endsWith('hooks')) {
|
|
return `@/hooks/${component}`
|
|
}
|
|
else if (type.endsWith('lib')) {
|
|
return `@/lib/${component}`
|
|
}
|
|
|
|
return match
|
|
}
|
|
|
|
return content.replace(regex, replacement)
|
|
}
|