Merge pull request #3535 from Keraito/use-npm

Use the --use-npm flag also for version checking
This commit is contained in:
Filipp Riabchun 2018-05-09 17:37:16 +03:00 committed by GitHub
commit f1e2d47d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 56 additions and 44 deletions

View File

@ -89,24 +89,24 @@ const runGenerator = () => {
return Promise.resolve();
case types.UPDATE_PACKAGE_ORGANIZATIONS:
return updateOrganisationsGenerator(program.parser)
return updateOrganisationsGenerator(program.parser, npmOptions)
.then(() => null) // commmandLog doesn't like to see output
.then(commandLog('Upgrading your project to the new storybook packages.'))
.then(end);
case types.REACT_SCRIPTS:
return reactScriptsGenerator()
return reactScriptsGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Create React App" based project'))
.then(end);
case types.REACT:
return reactGenerator()
return reactGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "React" app'))
.then(end);
case types.REACT_NATIVE_SCRIPTS: {
const app = chalk.bold('"./App.js"');
return reactNativeScriptsGenerator()
return reactNativeScriptsGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Create React Native App" app'))
.then(end)
.then(() => {
@ -120,57 +120,57 @@ const runGenerator = () => {
}
case types.REACT_NATIVE:
return reactNativeGenerator()
return reactNativeGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "React Native" app'))
.then(end);
case types.METEOR:
return meteorGenerator()
return meteorGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Meteor" app'))
.then(end);
case types.WEBPACK_REACT:
return webpackReactGenerator()
return webpackReactGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Webpack React" app'))
.then(end);
case types.REACT_PROJECT:
return reactGenerator()
return reactGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "React" library'))
.then(end);
case types.SFC_VUE:
return sfcVueGenerator()
return sfcVueGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Single File Components Vue" app'))
.then(end);
case types.VUE:
return vueGenerator()
return vueGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Vue" app'))
.then(end);
case types.ANGULAR:
return angularGenerator()
return angularGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Angular" app'))
.then(end);
case types.POLYMER:
return polymerGenerator()
return polymerGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Polymer" app'))
.then(end);
case types.MITHRIL:
return mithrilGenerator()
return mithrilGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Mithril" app'))
.then(end);
case types.MARKO:
return markoGenerator()
return markoGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "Marko" app'))
.then(end);
case types.HTML:
return htmlGenerator()
return htmlGenerator(npmOptions)
.then(commandLog('Adding storybook support to your "HTML" app'))
.then(end);

View File

@ -2,7 +2,7 @@ import mergeDirs from 'merge-dirs';
import path from 'path';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
notesVersion,
@ -10,6 +10,7 @@ export default async () => {
linksVersion,
addonsVersion,
] = await getVersions(
npmOptions,
'@storybook/angular',
'@storybook/addon-notes',
'@storybook/addon-actions',

View File

@ -3,8 +3,9 @@ import path from 'path';
import npmInit from '../../lib/npm_init';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [storybookVersion, babelCoreVersion, babelRuntimeVersion] = await getVersions(
npmOptions,
'@storybook/html',
'babel-core',
'babel-runtime'

View File

@ -2,8 +2,9 @@ import path from 'path';
import mergeDirs from 'merge-dirs';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [storybookVersion, babelCoreVersion, babelRuntimeVersion] = await getVersions(
npmOptions,
'@storybook/marko',
'babel-core',
'babel-runtime'

View File

@ -4,7 +4,7 @@ import JSON5 from 'json5';
import mergeDirs from 'merge-dirs';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -18,6 +18,7 @@ export default async () => {
presetStage1Version,
rootSlashImportVersion,
] = await getVersions(
npmOptions,
'@storybook/react',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -4,7 +4,7 @@ import JSON5 from 'json5';
import mergeDirs from 'merge-dirs';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -13,6 +13,7 @@ export default async () => {
babelCoreVersion,
babelPluginTransformReactJsxVersion,
] = await getVersions(
npmOptions,
'@storybook/mithril',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -2,13 +2,14 @@ import mergeDirs from 'merge-dirs';
import path from 'path';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
babelCoreVersion,
babelRuntimeVersion,
polymerLoaderVarion,
] = await getVersions(
npmOptions,
'@storybook/polymer',
'babel-core',
'babel-runtime',

View File

@ -2,7 +2,7 @@ import path from 'path';
import mergeDirs from 'merge-dirs';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -11,6 +11,7 @@ export default async () => {
babelCoreVersion,
babelRuntimeVersion,
] = await getVersions(
npmOptions,
'@storybook/react',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -4,7 +4,7 @@ import shell from 'shelljs';
import chalk from 'chalk';
import { getVersions, getPackageJson, writePackageJson, paddedLog } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -14,6 +14,7 @@ export default async () => {
babelRuntimeVersion,
propTypesVersion,
] = await getVersions(
npmOptions,
'@storybook/react-native',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -2,7 +2,7 @@ import mergeDirs from 'merge-dirs';
import path from 'path';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -12,6 +12,7 @@ export default async () => {
babelRuntimeVersion,
propTypesVersion,
] = await getVersions(
npmOptions,
'@storybook/react-native',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -3,7 +3,7 @@ import path from 'path';
import fs from 'fs';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -12,6 +12,7 @@ export default async () => {
babelCoreVersion,
babelRuntimeVersion,
] = await getVersions(
npmOptions,
'@storybook/react',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -8,7 +8,7 @@ import {
writeBabelRc,
} from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -17,6 +17,7 @@ export default async () => {
babelCoreVersion,
babelPresetVersion,
] = await getVersions(
npmOptions,
'@storybook/vue',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -4,15 +4,16 @@ import { spawn } from 'child-process-promise';
import { packageNames } from '@storybook/codemod';
import { getVersion, getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
async function updatePackage(devDependencies, oldName, newName) {
async function updatePackage(devDependencies, oldName, newName, npmOptions) {
if (devDependencies[oldName]) {
delete devDependencies[oldName];
devDependencies[newName] = await getVersion(newName);
devDependencies[newName] = await getVersion(npmOptions, newName);
}
}
async function addPeerDependencies(packageJson) {
async function addPeerDependencies(packageJson, npmOptions) {
const [addonsVersion, babelCoreVersion, babelRuntimeVersion] = await getVersions(
npmOptions,
'@storybook/addons',
'babel-core',
'babel-runtime'
@ -30,14 +31,14 @@ async function addPeerDependencies(packageJson) {
}
}
async function updatePackageJson() {
async function updatePackageJson(npmOptions) {
const packageJson = getPackageJson();
const { devDependencies } = packageJson;
await Promise.all(
Object.keys(packageNames).map(oldName => {
const newName = packageNames[oldName];
return updatePackage(devDependencies, oldName, newName);
return updatePackage(devDependencies, oldName, newName, npmOptions);
})
);
@ -45,7 +46,7 @@ async function updatePackageJson() {
throw new Error('Expected to find `@kadira/[react-native]-storybook` in devDependencies');
}
await addPeerDependencies(packageJson);
await addPeerDependencies(packageJson, npmOptions);
writePackageJson(packageJson);
}
@ -66,7 +67,7 @@ function updateSourceCode(parser) {
return spawn(jscodeshiftCommand, args, { stdio: 'inherit' });
}
export default async parser => {
await updatePackageJson();
export default async (parser, npmOptions) => {
await updatePackageJson(npmOptions);
return updateSourceCode(parser);
};

View File

@ -8,7 +8,7 @@ import {
writeBabelRc,
} from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -17,6 +17,7 @@ export default async () => {
babelCoreVersion,
babelPresetVersion,
] = await getVersions(
npmOptions,
'@storybook/vue',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -2,7 +2,7 @@ import mergeDirs from 'merge-dirs';
import path from 'path';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async () => {
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
@ -11,6 +11,7 @@ export default async () => {
babelCoreVersion,
babelRuntimeVersion,
] = await getVersions(
npmOptions,
'@storybook/react',
'@storybook/addon-actions',
'@storybook/addon-links',

View File

@ -9,7 +9,7 @@ import { version, devDependencies } from '../package.json';
const logger = console;
export async function getVersion(packageName) {
export async function getVersion(npmOptions, packageName) {
let current;
if (packageName === '@storybook/cli') {
current = version;
@ -19,7 +19,7 @@ export async function getVersion(packageName) {
let latest;
try {
latest = await latestVersion(packageName);
latest = await latestVersion(npmOptions, packageName);
} catch (e) {
if (current) {
logger.warn(`\n ${chalk.yellow(e.message)}`);
@ -34,8 +34,8 @@ export async function getVersion(packageName) {
return `^${versionToUse}`;
}
export function getVersions(...packageNames) {
return Promise.all(packageNames.map(getVersion));
export function getVersions(npmOptions, ...packageNames) {
return Promise.all(packageNames.map(packageName => getVersion(npmOptions, packageName)));
}
export function getPackageJson() {

View File

@ -1,9 +1,7 @@
import { spawn } from 'cross-spawn';
import hasYarn from './has_yarn';
const packageManager = hasYarn() ? 'yarn' : 'npm';
export default function latestVersion(packageName) {
export default function latestVersion(npmOptions, packageName) {
const packageManager = npmOptions.useYarn ? 'yarn' : 'npm';
return new Promise((resolve, reject) => {
const command = spawn(packageManager, ['info', packageName, 'version', '--json', '--silent'], {
cwd: process.cwd(),