diff --git a/bin/cli.js b/bin/cli.js index e87fb59..4b1153e 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -70,6 +70,10 @@ const TRANSFORMER_INQUIRER_CHOICES = [ name: 'Message', value: 'Message' }, + { + name: 'Drawer', + value: 'Drawer' + } ] function expandFilePathsIfNeeded(filesBeforeExpansion) { diff --git a/test.jsx b/test.jsx index b591e2f..25ee677 100644 --- a/test.jsx +++ b/test.jsx @@ -1,8 +1,11 @@ -import { message } from 'antd' +import { Button, Drawer } from 'antd' +import { Divider, Tabs, TabPane } from '@douyinfe/semi-ui' function Test() { - - message.error('123'); - message.error('123'); + return ( + +

hello

+
+ ) } diff --git a/transforms/Drawer.js b/transforms/Drawer.js new file mode 100644 index 0000000..d649ed8 --- /dev/null +++ b/transforms/Drawer.js @@ -0,0 +1,42 @@ +const { removeAntdImportAndAddSemiImport } = require('./utils') +module.exports = function transformer(file, api) { + const j = api.jscodeshift + const root = j(file.source) + + removeAntdImportAndAddSemiImport(j, root, 'Drawer', 'SideSheet') + + // Find all JSXElements with the name "Drawer" + root + .find(j.JSXElement, { + openingElement: { + name: { + name: 'Drawer' + } + } + }) + .forEach((path) => { + const { openingElement, closingElement } = path.value + + // Replace the name "Drawer" with "SideSheet" + openingElement.name.name = 'SideSheet' + closingElement.name.name = 'SideSheet' + + // Find the "open" attribute and replace it with "visible" + const openAttribute = openingElement.attributes.find( + (attr) => attr.name.name === 'open' + ) + if (openAttribute) { + openAttribute.name.name = 'visible' + } + + // Find the "onClose" attribute and replace it with "onCancel" + const onCloseAttribute = openingElement.attributes.find( + (attr) => attr.name.name === 'onClose' + ) + if (onCloseAttribute) { + onCloseAttribute.name.name = 'onCancel' + } + }) + + return root.toSource() +}