add migration tool buildin addons

This commit is contained in:
Keith Yao 2017-06-27 23:04:36 +02:00
parent da6bd6555e
commit 6ab4ee6fef
6 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,2 @@
/* eslint-disable */
import { storyOf, action, linkTo } from '@storybook/react';

View File

@ -0,0 +1,4 @@
/* eslint-disable */
import { storyOf } from '@storybook/react';
import { linkTo } from '@storybook/addon-links';
import { action } from '@storybook/addon-actions';

View File

@ -0,0 +1,3 @@
/* eslint-disable */
import { storyOf, action } from '@kadira/storybook-addons';
import { storyOf } from '@storybook/react';

View File

@ -0,0 +1,3 @@
/* eslint-disable */
import { storyOf, action } from '@kadira/storybook-addons';
import { storyOf } from '@storybook/react';

View File

@ -0,0 +1,4 @@
import { defineTest } from 'jscodeshift/dist/testUtils';
defineTest(__dirname, 'move-buildin-addons', null, 'move-buildin-addons/default');
defineTest(__dirname, 'move-buildin-addons', null, 'move-buildin-addons/with-no-change');

View File

@ -0,0 +1,29 @@
export default function transformer(file, api) {
const j = api.jscodeshift;
const createImportDeclaration = (specifiers, source) =>
j.importDeclaration(specifiers.map(s => j.importSpecifier(j.identifier(s))), j.literal(source));
const deprecates = {
action: [['action'], '@storybook/addon-actions'],
linkTo: [['linkTo'], '@storybook/addon-links'],
};
const transform = j(file.source)
.find(j.ImportDeclaration)
.filter(i => i.value.source.value === '@storybook/react')
.forEach(i => {
const importStatement = i.value;
importStatement.specifiers = importStatement.specifiers.filter(specifier => {
const item = deprecates[specifier.local.name];
if (item) {
const [specifiers, moduleName] = item;
i.insertAfter(createImportDeclaration(specifiers, moduleName));
return false;
}
return specifier;
});
});
return transform.toSource({ quote: 'single' });
}