Skip to content

Commit

Permalink
Update getstorybook CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Vega <clmvega@gmail.com>
  • Loading branch information
alterx authored and ndelangen committed Jul 31, 2017
1 parent 6e1d961 commit 7c3da0e
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/angular-cli/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { configure } from '@storybook/angular';

function loadStories() {
require('../src/stories');
require('../stories');
}

configure(loadStories, module);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { linkTo } from '@storybook/addon-links';

import { Welcome, Button } from '@storybook/angular/demo';

import { AppComponent } from '../app/app.component';
import { AppComponent } from '../src/app/app.component';

storiesOf('Welcome')
.add('to Storybook', () => ({
Expand Down
19 changes: 19 additions & 0 deletions lib/cli/generators/ANGULAR/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mergeDirs = require('merge-dirs').default;
const helpers = require('../../lib/helpers');
const path = require('path');
const latestVersion = require('latest-version');

module.exports = latestVersion('@storybook/angular').then(version => {
mergeDirs(path.resolve(__dirname, 'template'), '.', 'overwrite');

const packageJson = helpers.getPackageJson();

packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies['@storybook/angular'] = `^${version}`;

packageJson.scripts = packageJson.scripts || {};
packageJson.scripts.storybook = 'start-storybook -p 6006';
packageJson.scripts['build-storybook'] = 'build-storybook';

helpers.writePackageJson(packageJson);
});
5 changes: 5 additions & 0 deletions lib/cli/generators/ANGULAR/template/.storybook/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */

import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-notes/register';
9 changes: 9 additions & 0 deletions lib/cli/generators/ANGULAR/template/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */

import { configure } from '@storybook/angular';

function loadStories() {
require('../stories');
}

configure(loadStories, module);
42 changes: 42 additions & 0 deletions lib/cli/generators/ANGULAR/template/stories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { storiesOf } from '@storybook/angular';
import { addonNotes } from '@storybook/addon-notes';
import { action } from '@storybook/addon-actions'
import { linkTo } from '@storybook/addon-links'

import { Welcome, Button } from '@storybook/angular/demo';

storiesOf('Welcome', module)
.add('to Storybook', () => ({
component: Welcome,
props: {}
}))

storiesOf('Button', module)
.add('with text', () => ({
component: Button,
props: {
text: 'Hello Button'
}
}))
.add('with some emoji', addonNotes({ notes: 'My notes on a button with emojis' })(() => ({
component: Button,
props: {
text: '😀 😎 👍 💯'
}
})))
.add('with some emoji and action', addonNotes({ notes: 'My notes on a button with emojis' })(() => ({
component: Button,
props: {
text: '😀 😎 👍 💯',
onClick: action('This was clicked OMG')
}
})))

storiesOf('Another Button', module)
.add('button with link to another story', () => ({
component: Button,
props: {
text: 'Go to Welcome Story',
onClick: linkTo('Welcome')
}
}))
10 changes: 9 additions & 1 deletion lib/cli/lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = function detect(options) {
if (
packageJson.devDependencies['@storybook/react'] ||
packageJson.devDependencies['@storybook/react-native'] ||
packageJson.devDependencies['@storybook/vue']
packageJson.devDependencies['@storybook/vue'] ||
packageJson.devDependencies['@storybook/angular']
) {
return types.ALREADY_HAS_STORYBOOK;
}
Expand Down Expand Up @@ -71,5 +72,12 @@ module.exports = function detect(options) {
return types.REACT;
}

if (
(packageJson.dependencies && packageJson.dependencies['@angular/cli']) ||
(packageJson.devDependencies && packageJson.devDependencies['@angular/cli'])
) {
return types.ANGULAR;
}

return types.UNDETECTED;
};
1 change: 1 addition & 0 deletions lib/cli/lib/project_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
WEBPACK_REACT: 'WEBPACK_REACT',
VUE: 'VUE',
SFC_VUE: 'SFC_VUE',
ANGULAR: 'ANGULAR',
ALREADY_HAS_STORYBOOK: 'ALREADY_HAS_STORYBOOK',
UPDATE_PACKAGE_ORGANIZATIONS: 'UPDATE_PACKAGE_ORGANIZATIONS',
};

0 comments on commit 7c3da0e

Please sign in to comment.