Fix UPDATE_PACKAGE_ORGANISATIONS generator

This commit is contained in:
Hypnosphi 2018-12-04 20:38:57 +01:00
parent 6936c27fae
commit f34bf30c66
2 changed files with 28 additions and 12 deletions

View File

@ -1,8 +1,14 @@
/* eslint-disable no-param-reassign */
import path from 'path';
import { spawn } from 'child-process-promise';
import { sync as spawnSync } from 'cross-spawn';
import { packageNames } from '@storybook/codemod';
import { getVersion, installBabel, getPackageJson, writePackageJson } from '../../lib/helpers';
import {
getVersion,
getVersions,
installBabel,
getPackageJson,
writePackageJson,
} from '../../lib/helpers';
async function updatePackage(devDependencies, oldName, newName, npmOptions) {
if (devDependencies[oldName]) {
@ -15,6 +21,15 @@ async function updatePackageJson(npmOptions) {
const packageJson = getPackageJson();
const { devDependencies } = packageJson;
const [actionsVersion, linksVersion] = await getVersions(
npmOptions,
'@storybook/addon-actions',
'@storybook/addon-links'
);
devDependencies['@storybook/addon-actions'] = actionsVersion;
devDependencies['@storybook/addon-links'] = linksVersion;
await Promise.all(
Object.keys(packageNames).map(oldName => {
const newName = packageNames[oldName];
@ -35,19 +50,21 @@ function updateSourceCode(parser) {
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'
);
['update-organisation-name.js', 'move-buildin-addons.js'].forEach(codemod => {
const codemodPath = path.join(
path.dirname(require.resolve('@storybook/codemod')),
'transforms',
codemod
);
const args = ['-t', codemodPath, '--silent', '--ignore-pattern', '"node_modules|dist"', '.'];
if (parser) args.push('--parser', parser);
const args = ['-t', codemodPath, '--silent', '--ignore-pattern', '"node_modules|dist"', '.'];
if (parser) args.push('--parser', parser);
return spawn(jscodeshiftCommand, args, { stdio: 'inherit' });
spawnSync(jscodeshiftCommand, args, { stdio: 'inherit' });
});
}
export default async (parser, npmOptions) => {
await updatePackageJson(npmOptions);
return updateSourceCode(parser);
updateSourceCode(parser);
};

View File

@ -31,7 +31,6 @@
"@babel/register": "^7.0.0",
"@storybook/codemod": "4.1.0-alpha.10",
"chalk": "^2.4.1",
"child-process-promise": "^2.2.1",
"commander": "^2.19.0",
"core-js": "^2.5.7",
"cross-spawn": "^6.0.5",