Skip to content

Instantly share code, notes, and snippets.

@zthxxx
Created January 1, 2021 11:14
Show Gist options
  • Save zthxxx/b8afe65f487e1c8dcf7c5d2f806b623b to your computer and use it in GitHub Desktop.
Save zthxxx/b8afe65f487e1c8dcf7c5d2f806b623b to your computer and use it in GitHub Desktop.
antd-split-components.js
import fs from 'fs'
import path from 'path'
const libs = [
'Affix',
'Alert',
'Anchor',
'AutoComplete',
'BackTop',
'Badge',
'Breadcrumb',
'Calendar',
'Card',
'Carousel',
'Cascader',
'Checkbox',
'Col',
'Comment',
'ConfigProvider',
'DatePicker',
'Descriptions',
'Divider',
'Dropdown',
'Empty',
'Form',
'Input',
'Layout',
'List',
'LocaleProvider',
'Mention',
'Mentions',
'PageHeader',
'Popconfirm',
'Popover',
'Progress',
'Radio',
'Rate',
'Result',
'Row',
'Skeleton',
'Slider',
'Statistic',
'Steps',
'Switch',
'Table',
'Tabs',
'Tag',
'TimePicker',
'Timeline',
'Transfer',
'Tree',
'TreeSelect',
'Typography',
'Upload',
'message',
]
function transCamel(_str, symbol) {
const str = _str[0].toLowerCase() + _str.substr(1);
return str.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`);
}
const genLibPath = (item) => `antd/es/${transCamel(item, '-')}`
const genIndexFile = (item) => ([
`import '${genLibPath(item)}/style'`,
`export { default } from '${genLibPath(item)}'`,
'',
].join('\n'))
const chunks = libs.map((item) => ([
item,
genIndexFile(item),
]))
const createLib = (item, file) => {
const dir = `./src/components/Common/${item}`
fs.mkdirSync(dir, { recursive: true })
fs.writeFileSync(`${dir}/index.ts`, file)
console.log(`export { default as ${item} } from './${item}'`)
}
for (const [item, file] of chunks) {
const dir = `./src/components/Common/${item}`
if (fs.existsSync(dir)) {
console.log('[exist]', item)
continue
}
createLib(item, file)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment