Created
January 1, 2021 11:14
-
-
Save zthxxx/b8afe65f487e1c8dcf7c5d2f806b623b to your computer and use it in GitHub Desktop.
antd-split-components.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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