-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added an upgrade mode to getstorybook #1146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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.keys(packageNames).map(oldName => { | ||
const newName = packageNames[oldName]; | ||
return 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,12 @@ | |
"type": "git", | ||
"url": "git+https://github.com/storybooks/storybook.git" | ||
}, | ||
"main": "src/index.js", | ||
"main": "dist/index.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if the old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This package is never ever required by anything. This explains why this bug was never found. |
||
"dependencies": { | ||
"jscodeshift": "^0.3.30" | ||
}, | ||
"scripts": { | ||
"prepublish": "node ../../scripts/prepublish.js && mv dist/transforms/* dist" | ||
"prepublish": "node ../../scripts/prepublish.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ndelangen you should perhaps check this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this to shorten the paths, if this is removed the manual needs to be updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the README for the package, was there anything else that needed to change? |
||
}, | ||
"devDependencies": { | ||
"shelljs": "^0.7.7" | ||
|
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a reliable way to get the path to the compiled package?
jscodeshift
doesn't appear to offer its commandline functionality via an APIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you found this method to be unreliable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but it feels a little hacky. For instance it hard codes the path of the binary into this file (rather than
npm run jscodeshift
which uses thebin
field ofjscodeshift
'spackage.json
).