storybook 0.0.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +8 -0
- package/CHANGELOG.md +7 -0
- package/README.md +90 -0
- package/bin/generate.js +167 -0
- package/docs/getstorybook.png +0 -0
- package/generators/.eslintrc.js +12 -0
- package/generators/METEOR/index.js +81 -0
- package/generators/METEOR/template/.stories/index.js +20 -0
- package/generators/METEOR/template/.storybook/addons.js +2 -0
- package/generators/METEOR/template/.storybook/config.js +7 -0
- package/generators/REACT/index.js +25 -0
- package/generators/REACT/template/.storybook/addons.js +2 -0
- package/generators/REACT/template/.storybook/config.js +7 -0
- package/generators/REACT/template/stories/index.js +13 -0
- package/generators/REACT_NATIVE/index.js +53 -0
- package/generators/REACT_NATIVE/template/storybook/addons.js +2 -0
- package/generators/REACT_NATIVE/template/storybook/index.android.js +3 -0
- package/generators/REACT_NATIVE/template/storybook/index.ios.js +3 -0
- package/generators/REACT_NATIVE/template/storybook/stories/Button/index.android.js +19 -0
- package/generators/REACT_NATIVE/template/storybook/stories/Button/index.ios.js +17 -0
- package/generators/REACT_NATIVE/template/storybook/stories/CenterView/index.js +16 -0
- package/generators/REACT_NATIVE/template/storybook/stories/CenterView/style.js +8 -0
- package/generators/REACT_NATIVE/template/storybook/stories/Welcome/index.js +53 -0
- package/generators/REACT_NATIVE/template/storybook/stories/index.js +25 -0
- package/generators/REACT_NATIVE/template/storybook/storybook.js +15 -0
- package/generators/REACT_NATIVE_SCRIPTS/index.js +37 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/addons.js +2 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/index.js +11 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/Button/index.android.js +17 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/Button/index.ios.js +17 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/CenterView/index.js +12 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/CenterView/style.js +8 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/Welcome/index.js +52 -0
- package/generators/REACT_NATIVE_SCRIPTS/template/storybook/stories/index.js +25 -0
- package/generators/REACT_SCRIPTS/index.js +32 -0
- package/generators/REACT_SCRIPTS/template/.storybook/addons.js +2 -0
- package/generators/REACT_SCRIPTS/template/.storybook/config.js +7 -0
- package/generators/REACT_SCRIPTS/template/src/stories/index.js +13 -0
- package/generators/SFC_VUE/index.js +25 -0
- package/generators/SFC_VUE/template/.storybook/addons.js +2 -0
- package/generators/SFC_VUE/template/.storybook/config.js +7 -0
- package/generators/SFC_VUE/template/src/stories/MyButton.vue +28 -0
- package/generators/SFC_VUE/template/src/stories/Welcome.vue +120 -0
- package/generators/SFC_VUE/template/src/stories/index.js +24 -0
- package/generators/UPDATE_PACKAGE_ORGANIZATIONS/index.js +51 -0
- package/generators/VUE/index.js +25 -0
- package/generators/VUE/template/.storybook/addons.js +2 -0
- package/generators/VUE/template/.storybook/config.js +7 -0
- package/generators/VUE/template/stories/MyButton.js +29 -0
- package/generators/VUE/template/stories/Welcome.js +121 -0
- package/generators/VUE/template/stories/index.js +23 -0
- package/generators/WEBPACK_REACT/index.js +25 -0
- package/generators/WEBPACK_REACT/template/.storybook/config.js +7 -0
- package/generators/WEBPACK_REACT/template/.storybook/webpack.config.js +18 -0
- package/generators/WEBPACK_REACT/template/stories/index.js +13 -0
- package/lib/detect.js +87 -0
- package/lib/has_yarn.js +6 -0
- package/lib/helpers.js +104 -0
- package/lib/project_types.js +14 -0
- package/package.json +35 -6
- package/yarn.lock +2380 -0
- package/index.js +0 -0
package/.npmignore
ADDED
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Storybook (CLI)
|
|
2
|
+
|
|
3
|
+
[](https://greenkeeper.io/)
|
|
4
|
+
[](https://circleci.com/gh/storybooks/storybook)
|
|
5
|
+
[](https://www.codefactor.io/repository/github/storybooks/storybook)
|
|
6
|
+
[](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847)
|
|
7
|
+
[](https://bettercodehub.com/results/storybooks/storybook) [](https://codecov.io/gh/storybooks/storybook)
|
|
8
|
+
[](https://now-examples-slackin-nqnzoygycp.now.sh/)
|
|
9
|
+
[](#backers) [](#sponsors)
|
|
10
|
+
|
|
11
|
+
* * *
|
|
12
|
+
|
|
13
|
+
This package provides a CLI for adding [Storybook](https://github.com/storybooks/storybook) to your project.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
The quickest way to add Storybook to your project is to run this package via [npx](https://www.npmjs.com/package/npx):
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
cd your-project-folder
|
|
22
|
+
npx storybook
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That's all you've to do.
|
|
26
|
+
|
|
27
|
+
If you don't use npx install this CLI globally.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm i -g storybook
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then go to your project's folder and run:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
storybook
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
* * *
|
|
40
|
+
|
|
41
|
+
After that run Storybook by
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm run storybook
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
or
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
yarn storybook
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For more information visit: [storybook.js.org](https://storybook.js.org)
|
|
54
|
+
|
|
55
|
+
* * *
|
|
56
|
+
|
|
57
|
+
## [Yarn](https://github.com/yarnpkg/yarn) support
|
|
58
|
+
|
|
59
|
+
It also supports yarn.
|
|
60
|
+
If you have installed yarn in your system, it'll detect it and use `yarn` instead of `npm`.
|
|
61
|
+
|
|
62
|
+
If you don't want to use `yarn` always you can use the `--use-npm` option like this:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
storybook --use-npm
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
* * *
|
|
69
|
+
|
|
70
|
+
## [Flow](https://flow.org/) support
|
|
71
|
+
|
|
72
|
+
It also supports flow files. By default, [jscodeshift](https://github.com/facebook/jscodeshift), the tool used to transform the source files, uses babel to read the files. To be able to transform any flow annotated file, you need to use the flow parser.
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
storybook --parser flow
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Credits
|
|
79
|
+
|
|
80
|
+
npm package: https://www.npmjs.com/package/storybook
|
|
81
|
+
|
|
82
|
+
github repo: https://github.com/storybooks/storybook-package
|
|
83
|
+
|
|
84
|
+
Storybook monorepo: https://github.com/storybooks/storybook
|
|
85
|
+
|
|
86
|
+
in order to have the latest Storybook [CLI](https://github.com/storybooks/storybook/tree/master/lib/cli) install:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npm i -g @storybook/cli
|
|
90
|
+
```
|
package/bin/generate.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const updateNotifier = require('update-notifier');
|
|
4
|
+
const program = require('commander');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const detect = require('../lib/detect');
|
|
7
|
+
const hasYarn = require('../lib/has_yarn');
|
|
8
|
+
const types = require('../lib/project_types');
|
|
9
|
+
const commandLog = require('../lib/helpers').commandLog;
|
|
10
|
+
const codeLog = require('../lib/helpers').codeLog;
|
|
11
|
+
const paddedLog = require('../lib/helpers').paddedLog;
|
|
12
|
+
const installDeps = require('../lib/helpers').installDeps;
|
|
13
|
+
|
|
14
|
+
const logger = console;
|
|
15
|
+
|
|
16
|
+
const pkg = require('../package.json');
|
|
17
|
+
|
|
18
|
+
program
|
|
19
|
+
.version(pkg.version)
|
|
20
|
+
.option('-f --force', 'Forcely add storybook')
|
|
21
|
+
.option('-N --use-npm', 'Use npm to install deps')
|
|
22
|
+
.option('-p --parser <babel | babylon | flow>', 'jscodeshift parser')
|
|
23
|
+
.parse(process.argv);
|
|
24
|
+
|
|
25
|
+
const welcomeMessage = 'Storybook\'s CLI - The simplest way to add a storybook to your project.';
|
|
26
|
+
logger.log(chalk.inverse(`\n ${welcomeMessage} \n`));
|
|
27
|
+
|
|
28
|
+
const useYarn = Boolean(program.useNpm !== true) && hasYarn();
|
|
29
|
+
|
|
30
|
+
const npmOptions = {
|
|
31
|
+
useYarn,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const runStorybookCommand = useYarn ? 'yarn run storybook' : 'npm run storybook';
|
|
35
|
+
|
|
36
|
+
// Update notify code.
|
|
37
|
+
updateNotifier({
|
|
38
|
+
pkg,
|
|
39
|
+
updateCheckInterval: 1000 * 60 * 60, // every hour (we could increase this later on.)
|
|
40
|
+
}).notify();
|
|
41
|
+
|
|
42
|
+
let projectType;
|
|
43
|
+
|
|
44
|
+
const done = commandLog('Detecting project type');
|
|
45
|
+
try {
|
|
46
|
+
projectType = detect({
|
|
47
|
+
force: program.force,
|
|
48
|
+
});
|
|
49
|
+
} catch (ex) {
|
|
50
|
+
done(ex.message);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
done();
|
|
54
|
+
|
|
55
|
+
const end = () => {
|
|
56
|
+
installDeps(npmOptions);
|
|
57
|
+
|
|
58
|
+
logger.log('\nTo run your storybook, type:\n');
|
|
59
|
+
codeLog([runStorybookCommand]);
|
|
60
|
+
logger.log('\nFor more information visit:', chalk.cyan('https://storybook.js.org'));
|
|
61
|
+
|
|
62
|
+
// Add a new line for the clear visibility.
|
|
63
|
+
logger.log();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const CRNA_DISCUSSION =
|
|
67
|
+
'https://github.com/storybooks/storybook/blob/master/app/react-native/docs/manual-setup.md';
|
|
68
|
+
|
|
69
|
+
switch (projectType) {
|
|
70
|
+
case types.ALREADY_HAS_STORYBOOK:
|
|
71
|
+
logger.log();
|
|
72
|
+
paddedLog('There seems to be a storybook already available in this project.');
|
|
73
|
+
paddedLog('Apply following command to force:\n');
|
|
74
|
+
codeLog(['storybook -f']);
|
|
75
|
+
|
|
76
|
+
// Add a new line for the clear visibility.
|
|
77
|
+
logger.log();
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case types.UPDATE_PACKAGE_ORGANIZATIONS:
|
|
81
|
+
// eslint-disable-next-line
|
|
82
|
+
require('../generators/UPDATE_PACKAGE_ORGANIZATIONS')(program.parser)
|
|
83
|
+
.then(() => null) // commmandLog doesn't like to see output
|
|
84
|
+
.then(commandLog('Upgrading your project to the new storybook packages.'))
|
|
85
|
+
.then(end);
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case types.REACT_SCRIPTS:
|
|
89
|
+
// eslint-disable-next-line
|
|
90
|
+
require('../generators/REACT_SCRIPTS')
|
|
91
|
+
.then(commandLog('Adding storybook support to your "Create React App" based project'))
|
|
92
|
+
.then(end);
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case types.REACT:
|
|
96
|
+
// eslint-disable-next-line
|
|
97
|
+
require('../generators/REACT')
|
|
98
|
+
.then(commandLog('Adding storybook support to your "React" app'))
|
|
99
|
+
.then(end);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case types.REACT_NATIVE_SCRIPTS: {
|
|
103
|
+
const app = chalk.bold('"./App.js"');
|
|
104
|
+
// eslint-disable-next-line
|
|
105
|
+
require('../generators/REACT_NATIVE_SCRIPTS')
|
|
106
|
+
.then(commandLog('Adding storybook support to your "Create React Native App" app'))
|
|
107
|
+
.then(end)
|
|
108
|
+
.then(() => {
|
|
109
|
+
logger.log(chalk.red('NOTE: CRNA app installation is not 100% automated.'));
|
|
110
|
+
logger.log(`To quickly run storybook, replace contents of ${app} with:\n`);
|
|
111
|
+
codeLog(["export default from './storybook';"]); // eslint-disable-line
|
|
112
|
+
logger.log('\nFor a more complete discussion of options, see:\n');
|
|
113
|
+
logger.log(chalk.cyan(CRNA_DISCUSSION));
|
|
114
|
+
logger.log();
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
case types.REACT_NATIVE:
|
|
120
|
+
// eslint-disable-next-line
|
|
121
|
+
require('../generators/REACT_NATIVE')
|
|
122
|
+
.then(commandLog('Adding storybook support to your "React Native" app'))
|
|
123
|
+
.then(end);
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case types.METEOR:
|
|
127
|
+
// eslint-disable-next-line
|
|
128
|
+
require('../generators/METEOR')
|
|
129
|
+
.then(commandLog('Adding storybook support to your "Meteor" app'))
|
|
130
|
+
.then(end);
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case types.WEBPACK_REACT:
|
|
134
|
+
// eslint-disable-next-line
|
|
135
|
+
require('../generators/WEBPACK_REACT')
|
|
136
|
+
.then(commandLog('Adding storybook support to your "Webpack React" app'))
|
|
137
|
+
.then(end);
|
|
138
|
+
break;
|
|
139
|
+
|
|
140
|
+
case types.REACT_PROJECT:
|
|
141
|
+
// eslint-disable-next-line
|
|
142
|
+
require('../generators/REACT')
|
|
143
|
+
.then(commandLog('Adding storybook support to your "React" library'))
|
|
144
|
+
.then(end);
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case types.SFC_VUE:
|
|
148
|
+
// eslint-disable-next-line
|
|
149
|
+
require('../generators/SFC_VUE')
|
|
150
|
+
.then(commandLog('Adding storybook support to your "Single File Components Vue" app'))
|
|
151
|
+
.then(end);
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case types.VUE:
|
|
155
|
+
// eslint-disable-next-line
|
|
156
|
+
require('../generators/VUE')
|
|
157
|
+
.then(commandLog('Adding storybook support to your "Vue" app'))
|
|
158
|
+
.then(end);
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
default:
|
|
162
|
+
paddedLog(`Unsupported Project type. (code: ${projectType})`);
|
|
163
|
+
paddedLog('Visit https://storybook.js.org for more information.');
|
|
164
|
+
|
|
165
|
+
// Add a new line for the clear visibility.
|
|
166
|
+
logger.log();
|
|
167
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const mergeDirs = require('merge-dirs').default;
|
|
2
|
+
const helpers = require('../../lib/helpers');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const JSON5 = require('json5');
|
|
6
|
+
const latestVersion = require('latest-version');
|
|
7
|
+
|
|
8
|
+
module.exports = Promise.all([
|
|
9
|
+
latestVersion('@storybook/react'),
|
|
10
|
+
latestVersion('@storybook/addon-actions'),
|
|
11
|
+
latestVersion('@storybook/addon-links'),
|
|
12
|
+
latestVersion('react'),
|
|
13
|
+
latestVersion('react-dom'),
|
|
14
|
+
latestVersion('babel-preset-env'),
|
|
15
|
+
latestVersion('babel-preset-react'),
|
|
16
|
+
latestVersion('babel-preset-stage-1'),
|
|
17
|
+
latestVersion('babel-root-slash-import'),
|
|
18
|
+
]).then(
|
|
19
|
+
(
|
|
20
|
+
[
|
|
21
|
+
storybookVersion,
|
|
22
|
+
actionsVersion,
|
|
23
|
+
linksVersion,
|
|
24
|
+
reactVersion,
|
|
25
|
+
reactDomVersion,
|
|
26
|
+
presetEnvVersion,
|
|
27
|
+
presetReactVersion,
|
|
28
|
+
presetStage1Version,
|
|
29
|
+
rootSlashImportVersion,
|
|
30
|
+
]
|
|
31
|
+
) => {
|
|
32
|
+
mergeDirs(path.resolve(__dirname, 'template/'), '.', 'overwrite');
|
|
33
|
+
|
|
34
|
+
const packageJson = helpers.getPackageJson();
|
|
35
|
+
packageJson.devDependencies = packageJson.devDependencies || {};
|
|
36
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
37
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
38
|
+
|
|
39
|
+
// create or update .babelrc
|
|
40
|
+
let babelrc = null;
|
|
41
|
+
if (fs.existsSync('.babelrc')) {
|
|
42
|
+
const babelrcContent = fs.readFileSync('.babelrc', 'utf8');
|
|
43
|
+
babelrc = JSON5.parse(babelrcContent);
|
|
44
|
+
babelrc.plugins = babelrc.plugins || [];
|
|
45
|
+
|
|
46
|
+
if (babelrc.plugins.indexOf('babel-root-slash-import') < 0) {
|
|
47
|
+
babelrc.plugins.push('babel-root-slash-import');
|
|
48
|
+
packageJson.devDependencies['babel-root-slash-import'] = `^${rootSlashImportVersion}`;
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
babelrc = {
|
|
52
|
+
presets: ['env', 'react', 'stage-1'],
|
|
53
|
+
plugins: ['babel-root-slash-import'],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
packageJson.devDependencies['babel-preset-env'] = `^${presetEnvVersion}`;
|
|
57
|
+
packageJson.devDependencies['babel-preset-react'] = `^${presetReactVersion}`;
|
|
58
|
+
packageJson.devDependencies['babel-preset-stage-1'] = `^${presetStage1Version}`;
|
|
59
|
+
packageJson.devDependencies['babel-root-slash-import'] = `^${rootSlashImportVersion}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.writeFileSync('.babelrc', JSON.stringify(babelrc, null, 2), 'utf8');
|
|
63
|
+
|
|
64
|
+
// write the new package.json.
|
|
65
|
+
packageJson.devDependencies['@storybook/react'] = `^${storybookVersion}`;
|
|
66
|
+
packageJson.devDependencies['@storybook/addon-actions'] = `^${actionsVersion}`;
|
|
67
|
+
packageJson.devDependencies['@storybook/addon-links'] = `^${linksVersion}`;
|
|
68
|
+
packageJson.scripts.storybook = 'start-storybook -p 6006';
|
|
69
|
+
packageJson.scripts['build-storybook'] = 'build-storybook';
|
|
70
|
+
|
|
71
|
+
// add react packages.
|
|
72
|
+
if (!packageJson.dependencies.react) {
|
|
73
|
+
packageJson.dependencies.react = `^${reactVersion}`;
|
|
74
|
+
}
|
|
75
|
+
if (!packageJson.dependencies['react-dom']) {
|
|
76
|
+
packageJson.dependencies['react-dom'] = `^${reactDomVersion}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
helpers.writePackageJson(packageJson);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { storiesOf } from '@storybook/react';
|
|
4
|
+
import { action } from '@storybook/addon-actions';
|
|
5
|
+
import { linkTo } from '@storybook/addon-links';
|
|
6
|
+
|
|
7
|
+
import { Button, Welcome } from '@storybook/react/demo';
|
|
8
|
+
|
|
9
|
+
storiesOf('Welcome', module)
|
|
10
|
+
.add('to Storybook', () => (
|
|
11
|
+
<Welcome showApp={linkTo('Button')}/>
|
|
12
|
+
));
|
|
13
|
+
|
|
14
|
+
storiesOf('Button', module)
|
|
15
|
+
.add('with text', () => (
|
|
16
|
+
<Button onClick={action('clicked')}>Hello Button</Button>
|
|
17
|
+
))
|
|
18
|
+
.add('with some emoji', () => (
|
|
19
|
+
<Button onClick={action('clicked')}>😀 😎 👍 💯</Button>
|
|
20
|
+
));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mergeDirs = require('merge-dirs').default;
|
|
2
|
+
const helpers = require('../../lib/helpers');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const latestVersion = require('latest-version');
|
|
5
|
+
|
|
6
|
+
module.exports = Promise.all([
|
|
7
|
+
latestVersion('@storybook/react'),
|
|
8
|
+
latestVersion('@storybook/addon-actions'),
|
|
9
|
+
latestVersion('@storybook/addon-links'),
|
|
10
|
+
]).then(([storybookVersion, actionsVersion, linksVersion]) => {
|
|
11
|
+
mergeDirs(path.resolve(__dirname, 'template/'), '.', 'overwrite');
|
|
12
|
+
|
|
13
|
+
const packageJson = helpers.getPackageJson();
|
|
14
|
+
|
|
15
|
+
packageJson.devDependencies = packageJson.devDependencies || {};
|
|
16
|
+
packageJson.devDependencies['@storybook/react'] = `^${storybookVersion}`;
|
|
17
|
+
packageJson.devDependencies['@storybook/addon-actions'] = `^${actionsVersion}`;
|
|
18
|
+
packageJson.devDependencies['@storybook/addon-links'] = `^${linksVersion}`;
|
|
19
|
+
|
|
20
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
21
|
+
packageJson.scripts.storybook = 'start-storybook -p 6006';
|
|
22
|
+
packageJson.scripts['build-storybook'] = 'build-storybook';
|
|
23
|
+
|
|
24
|
+
helpers.writePackageJson(packageJson);
|
|
25
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { storiesOf } from '@storybook/react';
|
|
4
|
+
import { action } from '@storybook/addon-actions';
|
|
5
|
+
import { linkTo } from '@storybook/addon-links';
|
|
6
|
+
|
|
7
|
+
import { Button, Welcome } from '@storybook/react/demo';
|
|
8
|
+
|
|
9
|
+
storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);
|
|
10
|
+
|
|
11
|
+
storiesOf('Button', module)
|
|
12
|
+
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)
|
|
13
|
+
.add('with some emoji', () => <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const mergeDirs = require('merge-dirs').default;
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const shell = require('shelljs');
|
|
4
|
+
const latestVersion = require('latest-version');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const helpers = require('../../lib/helpers');
|
|
7
|
+
|
|
8
|
+
module.exports = Promise.all([
|
|
9
|
+
latestVersion('@storybook/react-native'),
|
|
10
|
+
latestVersion('@storybook/addon-actions'),
|
|
11
|
+
latestVersion('@storybook/addon-links'),
|
|
12
|
+
latestVersion('prop-types'),
|
|
13
|
+
]).then(([storybookVersion, actionsVersion, linksVersion, propTypesVersion]) => {
|
|
14
|
+
// copy all files from the template directory to project directory
|
|
15
|
+
mergeDirs(path.resolve(__dirname, 'template/'), '.', 'overwrite');
|
|
16
|
+
|
|
17
|
+
// set correct project name on entry files if possible
|
|
18
|
+
const dirname = shell.ls('-d', 'ios/*.xcodeproj').stdout;
|
|
19
|
+
const projectName =
|
|
20
|
+
dirname && dirname.slice('ios/'.length, dirname.length - '.xcodeproj'.length - 1);
|
|
21
|
+
if (projectName) {
|
|
22
|
+
shell.sed('-i', '%APP_NAME%', projectName, 'storybook/storybook.js');
|
|
23
|
+
} else {
|
|
24
|
+
helpers.paddedLog(
|
|
25
|
+
chalk.red(
|
|
26
|
+
'ERR: Could not determine project name, to fix: https://github.com/storybooks/storybook/issues/1277'
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const packageJson = helpers.getPackageJson();
|
|
32
|
+
|
|
33
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
34
|
+
packageJson.devDependencies = packageJson.devDependencies || {};
|
|
35
|
+
|
|
36
|
+
packageJson.devDependencies['@storybook/react-native'] = `^${storybookVersion}`;
|
|
37
|
+
packageJson.devDependencies['@storybook/addon-actions'] = `^${actionsVersion}`;
|
|
38
|
+
packageJson.devDependencies['@storybook/addon-links'] = `^${linksVersion}`;
|
|
39
|
+
|
|
40
|
+
if (!packageJson.dependencies['react-dom'] && !packageJson.devDependencies['react-dom']) {
|
|
41
|
+
const reactVersion = packageJson.dependencies.react;
|
|
42
|
+
packageJson.devDependencies['react-dom'] = reactVersion;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!packageJson.dependencies['prop-types'] && !packageJson.devDependencies['prop-types']) {
|
|
46
|
+
packageJson.devDependencies['prop-types'] = `^${propTypesVersion}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
50
|
+
packageJson.scripts.storybook = 'storybook start -p 7007';
|
|
51
|
+
|
|
52
|
+
helpers.writePackageJson(packageJson);
|
|
53
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { TouchableNativeFeedback } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export default function Button(props) {
|
|
6
|
+
return (
|
|
7
|
+
<TouchableNativeFeedback onPress={props.onPress}>{props.children}</TouchableNativeFeedback>
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Button.defaultProps = {
|
|
12
|
+
children: null,
|
|
13
|
+
onPress: () => {},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Button.propTypes = {
|
|
17
|
+
children: PropTypes.node,
|
|
18
|
+
onPress: PropTypes.func,
|
|
19
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { TouchableHighlight } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export default function Button(props) {
|
|
6
|
+
return <TouchableHighlight onPress={props.onPress}>{props.children}</TouchableHighlight>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Button.defaultProps = {
|
|
10
|
+
children: null,
|
|
11
|
+
onPress: () => {},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
Button.propTypes = {
|
|
15
|
+
children: PropTypes.node,
|
|
16
|
+
onPress: PropTypes.func,
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import style from './style';
|
|
5
|
+
|
|
6
|
+
export default function CenterView(props) {
|
|
7
|
+
return <View style={style.main}>{props.children}</View>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
CenterView.defaultProps = {
|
|
11
|
+
children: null,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
CenterView.propTypes = {
|
|
15
|
+
children: PropTypes.node,
|
|
16
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { View, Text } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export default class Welcome extends React.Component {
|
|
6
|
+
styles = {
|
|
7
|
+
wrapper: {
|
|
8
|
+
flex: 1,
|
|
9
|
+
padding: 24,
|
|
10
|
+
justifyContent: 'center',
|
|
11
|
+
},
|
|
12
|
+
header: {
|
|
13
|
+
fontSize: 18,
|
|
14
|
+
marginBottom: 18,
|
|
15
|
+
},
|
|
16
|
+
content: {
|
|
17
|
+
fontSize: 12,
|
|
18
|
+
marginBottom: 10,
|
|
19
|
+
lineHeight: 18,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
showApp(event) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (this.props.showApp) this.props.showApp();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
return (
|
|
30
|
+
<View style={this.styles.wrapper}>
|
|
31
|
+
<Text style={this.styles.header}>Welcome to React Native Storybook</Text>
|
|
32
|
+
<Text style={this.styles.content}>
|
|
33
|
+
This is a UI Component development environment for your React Native app. Here you can
|
|
34
|
+
display and interact with your UI components as stories. A story is a single state of one
|
|
35
|
+
or more UI components. You can have as many stories as you want. In other words a story is
|
|
36
|
+
like a visual test case.
|
|
37
|
+
</Text>
|
|
38
|
+
<Text style={this.styles.content}>
|
|
39
|
+
We have added some stories inside the "storybook/stories" directory for examples. Try
|
|
40
|
+
editing the "storybook/stories/Welcome.js" file to edit this message.
|
|
41
|
+
</Text>
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Welcome.defaultProps = {
|
|
48
|
+
showApp: null,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Welcome.propTypes = {
|
|
52
|
+
showApp: PropTypes.func,
|
|
53
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { storiesOf } from '@storybook/react-native';
|
|
5
|
+
import { action } from '@storybook/addon-actions';
|
|
6
|
+
import { linkTo } from '@storybook/addon-links';
|
|
7
|
+
|
|
8
|
+
import Button from './Button';
|
|
9
|
+
import CenterView from './CenterView';
|
|
10
|
+
import Welcome from './Welcome';
|
|
11
|
+
|
|
12
|
+
storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);
|
|
13
|
+
|
|
14
|
+
storiesOf('Button', module)
|
|
15
|
+
.addDecorator(getStory => <CenterView>{getStory()}</CenterView>)
|
|
16
|
+
.add('with text', () => (
|
|
17
|
+
<Button onPress={action('clicked-text')}>
|
|
18
|
+
<Text>Hello Button</Text>
|
|
19
|
+
</Button>
|
|
20
|
+
))
|
|
21
|
+
.add('with some emoji', () => (
|
|
22
|
+
<Button onPress={action('clicked-emoji')}>
|
|
23
|
+
<Text>😀 😎 👍 💯</Text>
|
|
24
|
+
</Button>
|
|
25
|
+
));
|