Skip to content

Commit

Permalink
Patch RN changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jan 30, 2024
1 parent c6cfb0d commit 26af9f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
27 changes: 15 additions & 12 deletions code/lib/cli/src/generators/REACT_NATIVE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const generator = async (

const missingReactDom =
!packageJson.dependencies['react-dom'] && !packageJson.devDependencies['react-dom'];

const reactVersion = packageJson.dependencies.react;

const packagesToResolve = [
Expand All @@ -24,24 +25,26 @@ const generator = async (
'@storybook/react-native',
];

// change these to latest version once v6 stable is released
const packagesWithFixedVersion = [
'@storybook/addon-actions@^6.5.16',
'@storybook/addon-controls@^6.5.16',
];
const packagesWithFixedVersion: string[] = [];

const versionedPackages = await packageManager.getVersionedPackages(packagesToResolve);

const babelDependencies = await getBabelDependencies(packageManager, packageJson);

const packages = [
...babelDependencies,
...packagesWithFixedVersion,
...versionedPackages,
missingReactDom && reactVersion && `react-dom@${reactVersion}`,
].filter(Boolean);
const packages: string[] = [];

packages.push(...babelDependencies);

packages.push(...packagesWithFixedVersion);

packages.push(...versionedPackages);

if (missingReactDom && reactVersion) {
packages.push(`react-dom@${reactVersion}`);
}

await packageManager.addDependencies({ ...npmOptions, packageJson }, packages);

packageManager.addScripts({
'storybook-generate': 'sb-rn-get-stories',
'storybook-watch': 'sb-rn-watcher',
Expand All @@ -52,7 +55,7 @@ const generator = async (
await copyTemplateFiles({
packageManager,
renderer: 'react-native',
language: SupportedLanguage.JAVASCRIPT,
language: SupportedLanguage.TYPESCRIPT_3_8,
destination: storybookConfigFolder,
includeCommonAssets: false,
});
Expand Down
30 changes: 20 additions & 10 deletions code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { readdirSync } from 'fs-extra';
import { lt, prerelease } from 'semver';
import { installableProjectTypes, ProjectType } from './project_types';
import { detect, isStorybookInstantiated, detectLanguage, detectPnp } from './detect';
import { commandLog, codeLog, paddedLog } from './helpers';
import { commandLog, paddedLog } from './helpers';
import angularGenerator from './generators/ANGULAR';
import emberGenerator from './generators/EMBER';
import reactGenerator from './generators/REACT';
Expand Down Expand Up @@ -401,15 +401,25 @@ export async function doInitiate(
}

if (projectType === ProjectType.REACT_NATIVE) {
logger.log();
logger.log(chalk.yellow('NOTE: installation is not 100% automated.\n'));
logger.log(`To quickly run Storybook, replace contents of your app entry with:\n`);
codeLog(["export {default} from './.storybook';"]);
logger.log('\n Then to run your Storybook, type:\n');
codeLog([packageManager.getRunCommand('start')]);
logger.log('\n For more in information, see the github readme:\n');
logger.log(chalk.cyan('https://github.com/storybookjs/react-native'));
logger.log();
logger.log(dedent`
${chalk.yellow('NOTE: installation is not 100% automated.')}
To run Storybook, you will need to:
1. Replace the contents of your app entry with the following
${chalk.inverse("export {default} from './.storybook';")}
2. Enable transformer.unstable_allowRequireContext in your metro config
For a more detailed guide go to:
${chalk.cyan('https://github.com/storybookjs/react-native#existing-project')}
Then to run your Storybook, type:
${chalk.inverse(` ${packageManager.getRunCommand('start')} `)}
`);

return { shouldRunDev: false };
}
Expand Down

0 comments on commit 26af9f2

Please sign in to comment.