-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an upgrade mode to getstorybook
This allows us to go from 2.x -> 3.0 A future version of storybook may include a version # that allows us to be more subtle, but we don't need it yet.
- Loading branch information
Showing
8 changed files
with
106 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const helpers = require('../../lib/helpers'); | ||
const latestVersion = require('latest-version'); | ||
const spawn = require('child-process-promise').spawn; | ||
const path = require('path'); | ||
|
||
const packageNames = require('@storybook/codemod').packageNames; | ||
|
||
function updatePackage(devDependencies, oldName, newName) { | ||
if (devDependencies[oldName]) { | ||
return latestVersion(newName).then(version => { | ||
delete devDependencies[oldName]; | ||
devDependencies[newName] = version; | ||
}); | ||
} else { | ||
return Promise.resolve(null); | ||
} | ||
} | ||
|
||
function updatePackageJson() { | ||
const packageJson = helpers.getPackageJson(); | ||
const { devDependencies } = packageJson; | ||
|
||
return Promise.all( | ||
Object.entries(packageNames).map(([oldName, newName]) => | ||
updatePackage(devDependencies, oldName, newName) | ||
) | ||
).then(() => { | ||
if (!devDependencies['@storybook/react'] && !devDependencies['@storybook/react-native']) { | ||
throw new Error('Expected to find `@kadira/[react-native]-storybook` in devDependencies'); | ||
} | ||
helpers.writePackageJson(packageJson); | ||
}); | ||
} | ||
|
||
function updateSourceCode() { | ||
const jscodeshiftPath = path.dirname(require.resolve('jscodeshift')); | ||
const jscodeshiftCommand = path.join(jscodeshiftPath, 'bin', 'jscodeshift.sh'); | ||
|
||
const codemodPath = path.join( | ||
path.dirname(require.resolve('@storybook/codemod')), | ||
'transforms', | ||
'update-organisation-name.js' | ||
); | ||
|
||
const args = ['-t', codemodPath, '--silent', '--ignore-pattern', '"node_modules|dist"', '.']; | ||
|
||
return spawn(jscodeshiftCommand, args, { stdio: 'inherit' }); | ||
} | ||
|
||
module.exports = updatePackageJson().then(updateSourceCode); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/* eslint import/prefer-default-export: "off" */ | ||
|
||
export { default as updateOrganisationName } from './transforms/update-organisation-name'; | ||
export { | ||
default as updateOrganisationName, | ||
packageNames, | ||
} from './transforms/update-organisation-name'; |
This file contains 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