Skip to content
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

React native - Use Core #4942

Merged
merged 85 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bedfbff
Use core/devServer in RN
igor-dv Dec 6, 2018
4edd60c
Delete unneeded code
igor-dv Dec 6, 2018
b4fdbc7
Move all the client files to client dir like in other apps
igor-dv Dec 6, 2018
8d5b625
Remove unneeded deps from RN
igor-dv Dec 6, 2018
ac095a4
Add rn-options-preset.js preset to pass options into manager
igor-dv Dec 6, 2018
16e246c
Extend manager-preset to use custom managerEntry + use the original m…
igor-dv Dec 6, 2018
b5dbf50
Merge remote-tracking branch 'origin/next' into react-native/use-core…
igor-dv Dec 6, 2018
c1b334d
Simplify dev-server
igor-dv Dec 6, 2018
b88d8b6
Update deps in the crna app
igor-dv Dec 6, 2018
bbd4e5f
Upgrade sdk to 31 to solve babel7 issue + downgrade react to 16.5.1 t…
igor-dv Dec 7, 2018
05daaa7
Update sdk in app.json
igor-dv Dec 7, 2018
da631e4
Merge remote-tracking branch 'origin/next' into react-native/use-core…
igor-dv Dec 12, 2018
6d3d634
Use `standalone` to build RN manager instead of just dev-server
igor-dv Dec 12, 2018
24ca226
Set storybook folder to `.storybook`.
Gongreg Dec 18, 2018
4a53666
Removed build command.
Gongreg Dec 18, 2018
53550c6
Merge next
Gongreg Dec 19, 2018
93a6139
Removed config.
Gongreg Dec 19, 2018
07d5078
@storybook/react-native dependency now works.
Gongreg Dec 19, 2018
59d3a15
renamed storybook to .storybook in react-native example
Gongreg Dec 19, 2018
f989509
Merge branch 'next' into react-native/use-core-for-server
igor-dv Dec 20, 2018
2ebab69
moving react to peer dependency.
Gongreg Dec 20, 2018
e420f7b
Delete conflict files
igor-dv Dec 20, 2018
77089f2
Set eventemitter3 to deps in client-api
igor-dv Dec 20, 2018
d2889d6
Fix rn generators linter
igor-dv Dec 20, 2018
b266e26
Add missing deps to rn-server
igor-dv Dec 20, 2018
6532c4f
Fix linter one more time
igor-dv Dec 20, 2018
060a80b
Merge remote-tracking branch 'origin/react-native/use-core-for-server…
Gongreg Dec 20, 2018
69a0e96
storyshots should also relate to the .storybook dir
igor-dv Dec 20, 2018
608ed63
Merge remote-tracking branch 'origin/react-native/use-core-for-server…
Gongreg Dec 20, 2018
ff2236e
Asks if you want to install @storybook/react-native-server
Gongreg Dec 20, 2018
bb7370b
Not all props from options were passed to the provider
igor-dv Dec 20, 2018
e216ee5
Reverting back to storybook.
Gongreg Dec 21, 2018
7b1fb75
Reverting back to storybook.
Gongreg Dec 21, 2018
d92675b
Creates http server, so websockets can connect to it.
Gongreg Dec 21, 2018
b23243e
Revert few more .storybook changes
igor-dv Dec 29, 2018
09abe35
Merge branch 'next' into react-native/use-core-for-server
igor-dv Dec 29, 2018
ab18fc2
Updated documentation.
Gongreg Jan 17, 2019
e5dcfa6
Updated server documentation.
Gongreg Jan 17, 2019
511d89a
updated argument
Gongreg Jan 17, 2019
5a56263
Merge remote-tracking branch 'origin/next' into react-native/use-core…
igor-dv Feb 8, 2019
3f7f5d6
Bring back files deleted in merge
igor-dv Feb 8, 2019
af3a4d5
Fix linter
igor-dv Feb 8, 2019
0ead28c
Merge branch 'next' into react-native/use-core-for-server
ndelangen Feb 9, 2019
82620d0
FIX tests a bit
ndelangen Feb 9, 2019
c7c49c8
Merge branch 'next' into react-native/use-core-for-server
ndelangen Feb 9, 2019
1c1b228
ADD --yes option to CLI init command && USE --yes command to skip que…
ndelangen Feb 9, 2019
0720ac2
FIX the --yes switch for RN
ndelangen Feb 9, 2019
16d57ae
FIX an issue with storyshots-puppeteer tests.
ndelangen Feb 9, 2019
fd7f3f1
Merge branch 'next' into react-native/use-core-for-server
ndelangen Feb 9, 2019
1962c9f
ADD prepare to react-native package
ndelangen Feb 9, 2019
d8d1042
WIP
ndelangen Feb 15, 2019
4cd54be
WIP
ndelangen Feb 15, 2019
9454636
WIP
gorhgorh Feb 15, 2019
d4e0688
WIP: Set up RN story store in getStorybookUI
shilman Feb 15, 2019
589fa90
Merge branch 'next' into react-native/use-core-for-server
ndelangen Feb 23, 2019
869fc80
BRING the reactnative example into the workspace
ndelangen Feb 23, 2019
02546c0
Restore crna-kitchen-sink
benoitdion Feb 23, 2019
75c2588
Disable preview for now to avoid crashing the server
benoitdion Feb 23, 2019
ecc6959
Give parameters defaults
benoitdion Feb 23, 2019
e6aa78d
Fix app/react-native
benoitdion Feb 23, 2019
137d5f9
CHANGE to run server from workspace, without the example being in the…
ndelangen Feb 23, 2019
fdd662f
Fix event names
benoitdion Feb 23, 2019
3cbeccd
Disable preview since it hasn't been implemented yet
benoitdion Feb 23, 2019
38888d0
Some documentation
benoitdion Feb 23, 2019
45f0c38
Merge remote-tracking branch 'upstream/react-native/use-core-for-serv…
benoitdion Feb 23, 2019
9f0ac56
Merge branch 'next' into react-native/use-core-for-server
ndelangen Feb 24, 2019
c2fc7ae
Merge branch 'next' into react-native/use-core-for-server
ndelangen Mar 2, 2019
396348a
Merge branch 'next' into react-native/use-core-for-server
ndelangen Mar 5, 2019
1780e92
Merge remote-tracking branch 'upstream/next' into react-native/use-co…
benoitdion Mar 12, 2019
68a5f2a
update versions to 5.1.0-alpha.4
benoitdion Mar 12, 2019
2e52e7a
fix android host
benoitdion Mar 12, 2019
33ac94a
Fix server story list rendering
benoitdion Mar 13, 2019
219e6cf
Merge branch 'next' into react-native/use-core-for-server
ndelangen Mar 13, 2019
556ba17
FIX missing .tgz
ndelangen Mar 13, 2019
288627f
ADD note to MIGRATION.MD about the change to the start command for ht…
ndelangen Mar 13, 2019
ad41158
IMRPOVE the readme description for the RN server package
ndelangen Mar 13, 2019
7da871d
CHANGE the react-native package to use the dist
ndelangen Mar 13, 2019
c157f60
ADD react-native-server to cli fixtures tests
ndelangen Mar 13, 2019
f4a4e2b
Merge branch 'next' into react-native/use-core-for-server
ndelangen Mar 14, 2019
5397b51
UPGRADE the react-native-scripts to latest expo && ADD app/react-nati…
ndelangen Mar 14, 2019
36a2242
FIX location of tgz
ndelangen Mar 14, 2019
4b35ffc
Use rn-host-detect to identify host
benoitdion Mar 15, 2019
07b873c
Clean up imports
benoitdion Mar 15, 2019
be10d83
Merge branch 'next' into react-native/use-core-for-server
benoitdion Mar 15, 2019
d3f6663
FIX docs yarn.lock
ndelangen Mar 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@ https://url-of-storybook?path=/story/<storyId>

The structure of `storyId` is a slugified `<selectedKind>--<selectedStory>` (slugified = lowercase, hyphen-separated). Each `storyId` must be unique. We plan to build more features into Storybook in upcoming versions based on this new structure.

## Rename of the `--secure` cli parameter to `--https`

Storybook for React Native's start commands & the Web versions' start command were a bit different, for no reason.
We've changed the start command for Reactnative to match the other.

This means that when you previously used the `--secure` flag like so:

```sh
start-storybook --secure
# or
start-storybook --s
```

You have to replace it with:

```sh
start-storybook --https
```

## From version 4.0.x to 4.1.x

There are are a few migrations you should be aware of in 4.1, including one unintentionally breaking change for advanced addon usage.
Expand Down
3 changes: 2 additions & 1 deletion addons/ondevice-knobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@storybook/addons": "5.1.0-alpha.6",
"@storybook/core-events": "5.1.0-alpha.6",
"core-js": "^2.6.5",
"deep-equal": "^1.0.1",
"prop-types": "^15.7.2",
Expand All @@ -32,7 +33,7 @@
"react-native-switch": "^1.5.0"
},
"peerDependencies": {
"@storybook/addon-knobs": "5.0.0-alpha.5",
"@storybook/addon-knobs": "5.1.0-alpha.6",
"react": "*",
"react-native": "*"
},
Expand Down
23 changes: 11 additions & 12 deletions addons/ondevice-knobs/src/panel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import PropTypes from 'prop-types';

import { SELECT_STORY, FORCE_RE_RENDER } from '@storybook/core-events';
import { SET, SET_OPTIONS, RESET, CHANGE, CLICK } from '@storybook/addon-knobs/events';
import GroupTabs from './GroupTabs';
import PropForm from './PropForm';

Expand Down Expand Up @@ -29,18 +30,16 @@ export default class Panel extends React.Component {
componentDidMount() {
const { channel } = this.props;

channel.on('addon:knobs:setKnobs', this.setKnobs);
channel.on('addon:knobs:setOptions', this.setOptions);

channel.on('selectStory', this.reset);

channel.emit('forceReRender');
channel.on(SET, this.setKnobs);
channel.on(SET_OPTIONS, this.setOptions);
channel.on(SELECT_STORY, this.reset);
channel.emit(FORCE_RE_RENDER);
}

componentWillUnmount() {
const { channel } = this.props;
channel.removeListener('addon:knobs:setKnobs', this.setKnobs);
channel.removeListener('selectStory', this.reset);
channel.removeListener(SET, this.setKnobs);
channel.removeListener(SELECT_STORY, this.reset);
}

onGroupSelect(name) {
Expand All @@ -60,12 +59,12 @@ export default class Panel extends React.Component {
reset = () => {
const { channel } = this.props;
this.setState({ knobs: {} });
channel.emit('addon:knobs:reset');
channel.emit(RESET);
};

emitChange(changedKnob) {
const { channel } = this.props;
channel.emit('addon:knobs:knobChange', changedKnob);
channel.emit(CHANGE, changedKnob);
}

handleChange(changedKnob) {
Expand All @@ -86,7 +85,7 @@ export default class Panel extends React.Component {
handleClick(knob) {
const { channel } = this.props;

channel.emit('addon:knobs:knobClick', knob);
channel.emit(CLICK, knob);
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion addons/storyshots/storyshots-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"regenerator-runtime": "^0.12.1"
},
"peerDependencies": {
"@storybook/addon-storyshots": "5.0.0-alpha.5"
"@storybook/addon-storyshots": "5.1.0-alpha.6"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 2 additions & 0 deletions app/react-native-server/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs
.babelrc
3 changes: 3 additions & 0 deletions app/react-native-server/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server');
46 changes: 46 additions & 0 deletions app/react-native-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@storybook/react-native-server",
"version": "5.1.0-alpha.6",
"description": "A better way to develop React Native Components for your app",
"keywords": [
"react",
"react-native",
"storybook"
],
"homepage": "https://github.com/storybooks/storybook/tree/master/app/react-native-server",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybooks/storybook.git"
},
"license": "MIT",
"bin": {
"start-storybook": "./bin/index.js",
"storybook-server": "./bin/index.js"
},
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.1.0-alpha.6",
"@storybook/channel-websocket": "5.1.0-alpha.6",
"@storybook/core": "5.1.0-alpha.6",
"@storybook/core-events": "5.1.0-alpha.6",
"@storybook/ui": "5.1.0-alpha.6",
"commander": "^2.19.0",
"global": "^4.3.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"uuid": "^3.3.2",
"webpack": "^4.23.1",
"ws": "^6.1.0"
},
"peerDependencies": {
"babel-loader": "^7.0.0 || ^8.0.0"
},
"publishConfig": {
"access": "public"
}
}
13 changes: 13 additions & 0 deletions app/react-native-server/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Storybook Server for React Native
Additional package for @storybook/react-native to support a web server and browser UI that runs alongside the RN on-device UI

For more information visit: [storybook.js.org](https://storybook.js.org)

## Usage
After setting up Storybook for React Native install this package.

```shell
npm install --save-dev @storybook/react-native-server
```

Then run `npx storybook start`
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ export default class ReactProvider extends Provider {
super();
this.options = options;
this.selection = null;
try {
this.channel = addons.getChannel();
} catch (err) {
this.channel = undefined;
}

const { secured, host, port } = options;
const websocketType = secured ? 'wss' : 'ws';
Expand All @@ -38,30 +33,37 @@ export default class ReactProvider extends Provider {
}
}

renderPreview(kind, story) {
this.selection = { kind, story };
this.channel.emit(Events.SET_CURRENT_STORY, { kind, story });
const renderPreview = addons.getPreview();
getElements(type) {
return addons.getElements(type);
}

renderPreview(state, api) {
if (state.storiesHash[state.storyId]) {
const { kind, story } = state.storiesHash[state.storyId];

const innerPreview = renderPreview ? renderPreview(kind, story) : null;
return innerPreview || <PreviewHelp />;
this.selection = { kind, story };
api.emit(Events.SET_CURRENT_STORY, { kind, story });
// FIXME: getPreview not implemented yet.
if (addons.getPreview) {
const renderPreview = addons.getPreview();
if (renderPreview) {
return renderPreview(kind, story);
}
}
}
return <PreviewHelp />;
}

handleAPI(api) {
addons.loadAddons(api);

api.onStory((kind, story) => {
this.selection = { kind, story };
this.channel.emit(Events.SET_CURRENT_STORY, this.selection);
});
this.channel.on(Events.SELECT_STORY, ({ kind, story }) => {
api.selectStory(kind, story);
api.emit(Events.SET_CURRENT_STORY, this.selection);
});
this.channel.on(Events.SET_STORIES, data => {
api.setStories(data.stories);
api.on(Events.GET_CURRENT_STORY, () => {
api.emit(Events.SET_CURRENT_STORY, this.selection);
});
this.channel.on(Events.GET_CURRENT_STORY, () => {
this.channel.emit(Events.SET_CURRENT_STORY, this.selection);
});
this.channel.emit(Events.GET_STORIES);
addons.loadAddons(api);
api.emit(Events.GET_STORIES);
}
}
39 changes: 39 additions & 0 deletions app/react-native-server/src/server/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path';
import program from 'commander';

export function parseList(str) {
return str.split(',');
}

function getCli() {
program
.option('-h, --host <host>', 'host to listen on', 'localhost')
.option('-p, --port <port>', 'port to listen on', 7007)
.option('-e, --environment [environment]', 'DEVELOPMENT/PRODUCTION environment for webpack')
.option('-i, --manual-id', 'allow multiple users to work with same storybook')
.option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from')
.option(
'--https',
'Serve Storybook over HTTPS. Note: You must provide your own certificate information.'
)
.option(
'--ssl-ca <ca>',
'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)',
parseList
)
.option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)')
.option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)')
.option('--smoke-test', 'Exit after successful start')
.option('--ci', "CI mode (skip interactive prompts, don't open browser")
.option('--quiet', 'Suppress verbose build output')
.parse(process.argv);

const configDir = path.resolve(program.configDir || './storybook');

return {
...program,
configDir,
};
}

export default getCli;
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import express from 'express';
#!/usr/bin/env node

import querystring from 'querystring';
import http from 'http';
import ws from 'ws';
import storybook from './middleware';
import storybook from '@storybook/core/standalone';

import extendOptions from './options';
import getCli from './cli';

export default class Server {
constructor(options) {
this.options = options;
this.httpServer = http.createServer();
this.expressApp = express();
this.expressApp.use(storybook(options));
this.httpServer.on('request', this.expressApp);
this.wsServer = new ws.Server({ server: this.httpServer });
this.attachWS = this.attachWS.bind(this);
this.options = extendOptions(options, this.attachWS);
}

start() {
return storybook(this.options);
}

attachWS(server) {
this.wsServer = new ws.Server({ server });
this.wsServer.on('connection', (s, req) => this.handleWS(s, req));
}

Expand All @@ -32,8 +39,7 @@ export default class Server {
});
});
}

listen(...args) {
this.httpServer.listen(...args);
}
}

const server = new Server(getCli());
server.start();
27 changes: 27 additions & 0 deletions app/react-native-server/src/server/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { managerPreset } from '@storybook/core/server';
import packageJson from '../../package.json';

function extendOptions(options, extendServer) {
const { manualId, https: secured, host, port } = options;
const storybookOptions = { manualId, secured, host, port };

return {
...options,
extendServer,
packageJson,
mode: 'dev',
ignorePreview: true,
corePresets: [
{
name: managerPreset,
options: { managerEntry: require.resolve('../client/manager') },
},
{
name: require.resolve('./rn-options-preset.js'),
options: { storybookOptions },
},
],
};
}

export default extendOptions;
15 changes: 15 additions & 0 deletions app/react-native-server/src/server/rn-options-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import webpack from 'webpack';

export async function managerWebpack(config, options) {
const { storybookOptions } = options;

return {
...config,
plugins: [
...config.plugins,
new webpack.DefinePlugin({
storybookOptions: JSON.stringify(storybookOptions),
}),
],
};
}
3 changes: 2 additions & 1 deletion app/react-native/docs/manual-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ RN application, e.g. on a tab or within an admin screen.

## Server support

If you want to support having a storybook server running add following NPM script into your `package.json` file:
If you want to support having a storybook server running install storybook server `npm install --save-dev @storybook/react-native-server`
and add following NPM script into your `package.json` file:

```json
{
Expand Down
5 changes: 1 addition & 4 deletions app/react-native/docs/server.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Storybook server
The default usage of React Native Storybook till version 4 involved starting Storybook server.
Starting from v4 we do not expect user to start the server since in most cases it is not really necessary.

In case you still want to run Storybook server simply call `npm run storybook` or `npx storybook start`.
Since storybook v5 the storybook server is a standalone package. To keep using storybook server make sure to install @storybook/react-native-server package.

## Benefits of storybook server

Expand Down
Loading