Skip to content

Commit

Permalink
Merge pull request #4069 from scarletsky/improve-codemod
Browse files Browse the repository at this point in the history
[codemod] Improve the path migration
  • Loading branch information
nathanmarks committed Apr 23, 2016
2 parents 252bc5c + 5a5d28d commit 390108d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/material-ui-codemod/transforms/v0.15.0/import-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const pathConversion = {
'divider': 'Divider',
'grid-list/grid-list': 'GridList/GridList',
'grid-list/grid-tile': 'GridList/GridTile',
'font-icon': 'FontIcon',
'svg-icon': 'SvgIcon',
'left-nav': 'Drawer',
'lists/list': 'List/List',
'lists/list-item': 'List/ListItem',
Expand All @@ -28,10 +30,12 @@ const pathConversion = {
'popover/popover': 'Popover',
'circular-progress': 'CircularProgress',
'linear-progress': 'LinearProgress',
'refresh-indicator': 'RefreshIndicator',
'select-field': 'SelectField',
'slider': 'Slider',
'checkbox': 'Checkbox',
'radio-button': 'RadioButton',
'radio-button-group': 'RadioButton/RadioButtonGroup',
'toggle': 'Toggle',
'snackbar': 'Snackbar',
'table/table': 'Table/Table',
Expand All @@ -40,6 +44,7 @@ const pathConversion = {
'table/table-header': 'Table/TableHeader',
'table/table-row-column': 'Table/TableRowColumn',
'table/table-body': 'Table/TableBody',
'table/table-footer': 'Table/TableFooter',
'tabs/tab': 'Tabs/Tab',
'tabs/tabs': 'Tabs/Tabs',
'text-field': 'TextField',
Expand Down Expand Up @@ -83,14 +88,14 @@ export default function transformer(file, api) {
(path) => {
const pathOld = path.value.source.value;
const pathsBase = getPathsBase(pathOld);
const pathPrefix = pathOld.substring(pathsBase[0].length);
const pathSuffix = pathOld.substring(pathsBase[0].length);

let pathNew;

if (pathConversion[pathPrefix]) {
pathNew = pathsBase[1] + pathConversion[pathPrefix];
if (pathConversion[pathSuffix]) {
pathNew = pathsBase[1] + pathConversion[pathSuffix];
} else {
pathNew = pathOld;
pathNew = pathsBase[1] + pathSuffix;
}

return j.importDeclaration(path.node.specifiers, j.literal(pathNew));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import FlatButton from 'material-ui/src/flat-button';
import RaisedButton from 'material-ui/lib/raised-button';
import SvgIcon from 'material-ui/lib/svg-icon';
import Colors from 'material-ui/lib/styles/colors';
import NavigationExpandMoreIcon from 'material-ui/lib/svg-icons/navigation/expand-more';
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import FlatButton from 'material-ui/src/FlatButton';
import RaisedButton from 'material-ui/RaisedButton';
import SvgIcon from 'material-ui/SvgIcon';
import Colors from 'material-ui/styles/colors';
import NavigationExpandMoreIcon from 'material-ui/svg-icons/navigation/expand-more';

0 comments on commit 390108d

Please sign in to comment.