You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.1 KiB
77 lines
2.1 KiB
import fs from 'fs'
|
|
import path from 'path'
|
|
import type {
|
|
ComponentResolver,
|
|
SideEffectsInfo,
|
|
} from 'unplugin-vue-components/types'
|
|
|
|
function existCss(compName) {
|
|
if (
|
|
fs.existsSync(
|
|
path.resolve(
|
|
__dirname,
|
|
'./lib/' +
|
|
compName[0].toLowerCase() +
|
|
compName.slice(1) +
|
|
'/style.css'
|
|
)
|
|
)
|
|
) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
function existTheme(compName) {
|
|
if (
|
|
fs.existsSync(
|
|
path.resolve(
|
|
__dirname,
|
|
'./theme-chalk/ps-' +
|
|
compName[0].toLowerCase() +
|
|
compName.slice(1) +
|
|
'.css'
|
|
)
|
|
)
|
|
) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
export default (): ComponentResolver => {
|
|
return {
|
|
type: 'component',
|
|
resolve: (componentName: string) => {
|
|
if (componentName.startsWith('Ps')) {
|
|
let css = []
|
|
const n = componentName.slice(2)
|
|
if (existCss(n)) {
|
|
css.push(
|
|
(function getSideEffects(
|
|
compName: string
|
|
): SideEffectsInfo {
|
|
return `princess-ui/lib/${
|
|
compName[0].toLowerCase() + compName.slice(1)
|
|
}/style.css`
|
|
})(n)
|
|
)
|
|
}
|
|
if (existTheme(n)) {
|
|
css.push(
|
|
(function getSideEffects(
|
|
compName: string
|
|
): SideEffectsInfo {
|
|
return `princess-ui/theme-chalk/ps-${
|
|
compName[0].toLowerCase() + compName.slice(1)
|
|
}.css`
|
|
})(n)
|
|
)
|
|
}
|
|
return {
|
|
name: componentName,
|
|
from: 'princess-ui',
|
|
sideEffects: css,
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|