-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathidux.ts
55 lines (49 loc) · 1.43 KB
/
idux.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { ComponentResolver } from "../../types"
import { kebabCase } from "../utils"
export interface IduxResolverOptions {
/**
* import style along with components
*/
importStyle?: 'css' | 'less'
}
/**
* Resolver for `@idux/cdk` and `@idux/components`
*
* @link https://idux.site
*/
export function IduxResolver(options: IduxResolverOptions = {}): ComponentResolver {
return (name: string) => {
if (name.match(/^Ix[A-Z]/)) {
const { importStyle } = options
const compName = name.slice(2)
const kebabCaseName = kebabCase(compName)
const isCdk = cdkNames.includes(kebabCaseName)
const packageName = isCdk ? 'cdk' : 'components'
const dirname = getDirname(kebabCaseName)
const path = `@idux/${packageName}/${dirname}`
const sideEffects = isCdk || !importStyle ? undefined : `${path}/style/${importStyle === 'css' ? 'css' : 'index'}`
return { importName: name, path, sideEffects }
}
}
}
const cdkNames = ['portal', 'resizable', 'virtual-list']
const kebabCaseDirnames = [
'virtual-list',
'auto-complete',
'back-top',
'date-picker',
'input-number',
'time-picker',
'tree-select',
]
function getDirname(compName: string): string {
const dirname = kebabCaseDirnames.find(name => compName.startsWith(name))
if (dirname) {
return dirname
}
const [first] = compName.split('-')
if (first === 'row' || first === 'col') {
return 'grid'
}
return first
}