Skip to content

Commit

Permalink
fix(codemod): update for new package names
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmcadam committed May 18, 2017
1 parent e5d3d63 commit 3732bcd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
/* eslint-disable */
import '@kadira/storybook-addon-knobs/register';
import '@kadira/storybook-addon-options/register';
import '@kadira/storybook/addons';
import { storiesOf } from '@kadira/storybook';
import '@kadira/storybook-addons';
import '@kadira/react-storybook-decorator-centered';
import '@kadira/storybook-addon-comments';
import '@kadira/storybook-addon-graphql';
import '@kadira/storybook-addon-info';
import '@kadira/storybook-addon-knobs';
import '@kadira/storybook-addon-links';
import '@kadira/storybook-addon-notes';
import '@kadira/storybook-addon-options';
import 'storyshots';
import '@kadira/storybook-channels';
import '@kadira/storybook-channel-postmsg';
import '@kadira/storybook-channel-websocket';
import '@kadira/getstorybook';
import '@kadira/react-storybook';
import '@kadira/react-native-storybook';
import '@kadira/storybook-ui';
import { storiesOf } from '@kadira/react-storybook';
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
/* eslint-disable */
import '@storybook/storybook-addon-knobs/register';
import '@storybook/storybook-addon-options/register';
import '@storybook/storybook/addons';
import { storiesOf } from '@storybook/storybook';
import '@storybook/addons';
import '@storybook/addon-centered';
import '@storybook/addon-comments';
import '@storybook/addon-graphql';
import '@storybook/addon-info';
import '@storybook/addon-knobs';
import '@storybook/addon-links';
import '@storybook/addon-notes';
import '@storybook/addon-options';
import '@storybook/addon-storyshots';
import '@storybook/channels';
import '@storybook/channel-postmessage';
import '@storybook/channel-websocket';
import '@storybook/cli';
import '@storybook/react';
import '@storybook/react-native';
import '@storybook/ui';
import { storiesOf } from '@storybook/react';
36 changes: 23 additions & 13 deletions lib/codemod/src/transforms/update-organisation-name.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
// Demo at https://astexplorer.net/#/gist/f2d0b42c37e4556a4f816892be6ca402/latest
export default function transformer(file, api) {
const j = api.jscodeshift;

/**
* Checks whether the node value matches a Storybook package
* @param {ImportDeclaration.Node} the import declaration node
* @returns {boolean} whether the node value matches a Storybook package
*/
const isStorybookPackage = node => node.value.source.value.includes('@kadira');
const packageNames = {
'@kadira/storybook-addons': '@storybook/addons',
'@kadira/react-storybook-decorator-centered': '@storybook/addon-centered',
'@kadira/storybook-addon-comments': '@storybook/addon-comments',
'@kadira/storybook-addon-graphql': '@storybook/addon-graphql',
'@kadira/storybook-addon-info': '@storybook/addon-info',
'@kadira/storybook-addon-knobs': '@storybook/addon-knobs',
'@kadira/storybook-addon-links': '@storybook/addon-links',
'@kadira/storybook-addon-notes': '@storybook/addon-notes',
'@kadira/storybook-addon-options': '@storybook/addon-options',
storyshots: '@storybook/addon-storyshots',
'@kadira/storybook-channels': '@storybook/channels',
'@kadira/storybook-channel-postmsg': '@storybook/channel-postmessage',
'@kadira/storybook-channel-websocket': '@storybook/channel-websocket',
'@kadira/getstorybook': '@storybook/cli',
'@kadira/react-storybook': '@storybook/react',
'@kadira/react-native-storybook': '@storybook/react-native',
'@kadira/storybook-ui': '@storybook/ui',
};

/**
* Returns the name of the Storybook packages with the organisation name,
* replacing the old `@storybook/` prefix.
* replacing the old `@kadira/` prefix.
* @param {string} oldPackageName the name of the old package
* @return {string} the new package name
* @example
* // returns '@storybook/storybook'
* getNewPackageName('@storybook/storybook')
* // returns '@storybook/react'
* getNewPackageName('@kadira/react-storybook')
*/
const getNewPackageName = oldPackageName => {
const packageNameWithoutPrefix = oldPackageName.slice(7);
const packageNameWithOrganisation = `@storybook${packageNameWithoutPrefix}`;
const packageNameWithOrganisation = packageNames[oldPackageName];

return packageNameWithOrganisation;
};
Expand All @@ -39,7 +50,6 @@ export default function transformer(file, api) {

return j(file.source)
.find(j.ImportDeclaration)
.filter(isStorybookPackage)
.replaceWith(updatePackageName)
.toSource({ quote: 'single' });
}

0 comments on commit 3732bcd

Please sign in to comment.