Skip to content

Commit

Permalink
refactor: format code style for resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 19, 2021
1 parent 627e8af commit 9b36122
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 158 deletions.
17 changes: 10 additions & 7 deletions src/resolvers/element-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ export interface ElementPlusResolverOptions {
* @author @develar
* @link https://element-plus.org/#/en-US
*/
export const ElementPlusResolver = (options: ElementPlusResolverOptions = {}): ComponentResolver => (name: string) => {
const { importStyle = true } = options
if (name.startsWith('El')) {
const partialName = name[2].toLowerCase() + name.substring(3).replace(/[A-Z]/g, l => `-${l.toLowerCase()}`)
return {
path: `element-plus/es/el-${partialName}`,
sideEffects: importStyle ? `element-plus/packages/theme-chalk/src/${partialName}.scss` : undefined,
export function ElementPlusResolver(options: ElementPlusResolverOptions = {}): ComponentResolver {
return (name: string) => {
const { importStyle = true } = options

if (name.startsWith('El')) {
const partialName = name[2].toLowerCase() + name.substring(3).replace(/[A-Z]/g, l => `-${l.toLowerCase()}`)
return {
path: `element-plus/es/el-${partialName}`,
sideEffects: importStyle ? `element-plus/packages/theme-chalk/src/${partialName}.scss` : undefined,
}
}
}
}
5 changes: 3 additions & 2 deletions src/resolvers/element-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function getSideEffects(
* @version @element-ui ^2.15.3, @vue ^2.6.14
* @author @nabaonan
*/
export const ElementUiResolver = (options: ElementUiResolverOptions = {}): ComponentResolver =>
(name: string) => {
export function ElementUiResolver(options: ElementUiResolverOptions = {}): ComponentResolver {
return (name: string) => {
if (name.startsWith('El')) {
const compName = name.slice(2)
const partialName = kebabCase(compName)
Expand All @@ -53,3 +53,4 @@ export const ElementUiResolver = (options: ElementUiResolverOptions = {}): Compo
}
}
}
}
8 changes: 5 additions & 3 deletions src/resolvers/headless-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const components = [
*
* @link https://github.com/tailwindlabs/headlessui
*/
export const HeadlessUiResolver = (): ComponentResolver => (name: string) => {
if (components.includes(name))
return { importName: name, path: '@headlessui/vue' }
export function HeadlessUiResolver(): ComponentResolver {
return (name: string) => {
if (components.includes(name))
return { importName: name, path: '@headlessui/vue' }
}
}
10 changes: 5 additions & 5 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './antdv'
export * from './element-plus'
export * from './element-ui'
export * from './headless-ui'
export * from './vant'
export * from './vuetify'
export * from './vueuse'
export * from './naive-ui'
export * from './varlet-ui'
export * from './element-ui'
export * from './prime-vue'
export * from './vant'
export * from './varlet-ui'
export * from './view-ui'
export * from './vuetify'
export * from './vueuse'
8 changes: 5 additions & 3 deletions src/resolvers/naive-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { ComponentResolver } from '../types'
* @author @antfu
* @link https://www.naiveui.com/
*/
export const NaiveUiResolver = (): ComponentResolver => (name: string) => {
if (name.match(/^N[A-Z]/))
return { importName: name, path: 'naive-ui' }
export function NaiveUiResolver(): ComponentResolver {
return (name: string) => {
if (name.match(/^N[A-Z]/))
return { importName: name, path: 'naive-ui' }
}
}
196 changes: 99 additions & 97 deletions src/resolvers/prime-vue.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
import { ComponentResolver } from "../types"
import { ComponentResolver, SideEffectsInfo } from '../types'

const components = [
"AutoComplete",
"Calendar",
"CascadeSelect",
"Checkbox",
"Chips",
"ColorPicker",
"Dropdown",
"Editor",
"InputMask",
"InputNumber",
"InputSwitch",
"InputText",
"Knob",
"Listbox",
"MultiSelect",
"Password",
"RadioButton",
"Rating",
"SelectButton",
"Slider",
"Textarea",
"ToggleButton",
"TreeSelect",
"TriStateCheckbox",
"Button",
"SplitButton",
"DataTable",
"Column",
"ColumnGroup",
"DataView",
"FullCalendar",
"OrderList",
"OrganizationChart",
"Paginator",
"PickList",
"Timelist",
"Tree",
"TreeTable",
"Accordion",
"AccordionTab",
"Card",
"DeferredContent",
"Divider",
"Fieldset",
"Panel",
"Splitter",
"SplitterPanel",
"ScrollPanel",
"TabView",
"TabPanel",
"Toolbar",
"ConfirmDialog",
"ConfirmPopup",
"Dialog",
"OverlayPanel",
"Sidebar",
"Tooltip",
"FileUpload",
"Breadcrumb",
"ContextMenu",
"MegaMenu",
"Menu",
"Menubar",
"PanelMenu",
"Steps",
"TabMenu",
"TieredMenu",
"Chart",
"Message",
"Toast",
"Carousel",
"Galleria",
"Avatar",
"AvatarGroup",
"Badge",
"Chip",
"BlockUI",
"Inplace",
"ScrollTop",
"Skeleton",
"ProgressBar",
"ProgressSpiner",
"Tag",
"Terminal",
"TerminalService",
'AutoComplete',
'Calendar',
'CascadeSelect',
'Checkbox',
'Chips',
'ColorPicker',
'Dropdown',
'Editor',
'InputMask',
'InputNumber',
'InputSwitch',
'InputText',
'Knob',
'Listbox',
'MultiSelect',
'Password',
'RadioButton',
'Rating',
'SelectButton',
'Slider',
'Textarea',
'ToggleButton',
'TreeSelect',
'TriStateCheckbox',
'Button',
'SplitButton',
'DataTable',
'Column',
'ColumnGroup',
'DataView',
'FullCalendar',
'OrderList',
'OrganizationChart',
'Paginator',
'PickList',
'Timelist',
'Tree',
'TreeTable',
'Accordion',
'AccordionTab',
'Card',
'DeferredContent',
'Divider',
'Fieldset',
'Panel',
'Splitter',
'SplitterPanel',
'ScrollPanel',
'TabView',
'TabPanel',
'Toolbar',
'ConfirmDialog',
'ConfirmPopup',
'Dialog',
'OverlayPanel',
'Sidebar',
'Tooltip',
'FileUpload',
'Breadcrumb',
'ContextMenu',
'MegaMenu',
'Menu',
'Menubar',
'PanelMenu',
'Steps',
'TabMenu',
'TieredMenu',
'Chart',
'Message',
'Toast',
'Carousel',
'Galleria',
'Avatar',
'AvatarGroup',
'Badge',
'Chip',
'BlockUI',
'Inplace',
'ScrollTop',
'Skeleton',
'ProgressBar',
'ProgressSpiner',
'Tag',
'Terminal',
'TerminalService',
]

export interface PrimeVueResolverOptions {
Expand Down Expand Up @@ -116,25 +116,27 @@ export interface PrimeVueResolverOptions {
*
* @link https://github.com/primefaces/primevue
*/
export const PrimeVueResolver =
(options: PrimeVueResolverOptions = {}): ComponentResolver =>
(name: string) => {
const sideEffects = []
if (options.importStyle) {
sideEffects.push("primevue/resources/primevue.min.css")
}
if (options.importIcons) {
sideEffects.push("primeicons/primeicons.css")
}
export function PrimeVueResolver(options: PrimeVueResolverOptions = {}): ComponentResolver {
return (name: string) => {
const sideEffects: SideEffectsInfo = []

if (options.importStyle)
sideEffects.push('primevue/resources/primevue.min.css')

if (options.importIcons)
sideEffects.push('primeicons/primeicons.css')

if (options.importTheme) {
sideEffects.push(
`primevue/resources/themes/${options.importTheme}/theme.css`
`primevue/resources/themes/${options.importTheme}/theme.css`,
)
}

if (components.includes(name)) {
return {
path: `primevue/${name}/${name}.vue`,
sideEffects,
}
}
}
}
19 changes: 11 additions & 8 deletions src/resolvers/vant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ export interface VantResolverOptions {
*
* @link https://github.com/youzan/vant
*/
export const VantResolver = (options: VantResolverOptions = {}): ComponentResolver => (name: string) => {
const { importStyle = true } = options
if (name.startsWith('Van')) {
const partialName = name.slice(3)
return {
importName: partialName,
path: 'vant/es',
sideEffects: importStyle ? `vant/es/${kebabCase(partialName)}/style` : undefined,
export function VantResolver(options: VantResolverOptions = {}): ComponentResolver {
return (name: string) => {
const { importStyle = true } = options

if (name.startsWith('Van')) {
const partialName = name.slice(3)
return {
importName: partialName,
path: 'vant/es',
sideEffects: importStyle ? `vant/es/${kebabCase(partialName)}/style` : undefined,
}
}
}
}
30 changes: 16 additions & 14 deletions src/resolvers/view-ui.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { ComponentResolver } from '../types'
import { kebabCase } from '../utils'

const getSideEffects: (
compName: string,
) => string[] = (compName) => {
function getSideEffects(componentName: string) {
const sideEffects = [
'view-design/dist/styles/iview.css',
'popper.js/dist/umd/popper.js',
]

if (/^Table/.test(compName))
if (/^Table/.test(componentName))
sideEffects.push('element-resize-detector')

if (/^Date/.test(compName))
if (/^Date/.test(componentName))
sideEffects.push('js-calendar')

return sideEffects
Expand All @@ -25,8 +23,8 @@ const matchComponents = [
},
]

const getCompDir = (compName: string): string => {
let compPath: string|undefined
function getCompDir(compName: string): string {
let compPath: string | undefined

const total = matchComponents.length
for (let i = 0; i < total; i++) {
Expand All @@ -36,7 +34,9 @@ const getCompDir = (compName: string): string => {
break
}
}
if (!compPath) compPath = kebabCase(compName)
if (!compPath)
compPath = kebabCase(compName)

return compPath
}

Expand All @@ -49,12 +49,14 @@ const getCompDir = (compName: string): string => {
* - select component render error PR: https://github.com/view-design/ViewUI/pull/944, choose can't display value,because click option trigger twice,at second time,select value turn into undefined.
* - scroll component has a template syntax called lang='html',it is require html-loader,but vite plugin not support yet,remove it can run.
*/
export const ViewUiResolver = (): ComponentResolver => (name: string) => {
if (name.match(/^I[A-Z]/)) {
const compName = name.slice(1)
return {
path: `view-design/src/components/${getCompDir(compName)}`,
sideEffects: getSideEffects(compName),
export function ViewUiResolver(): ComponentResolver {
return (name: string) => {
if (name.match(/^I[A-Z]/)) {
const compName = name.slice(1)
return {
path: `view-design/src/components/${getCompDir(compName)}`,
sideEffects: getSideEffects(compName),
}
}
}
}
Loading

0 comments on commit 9b36122

Please sign in to comment.