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

feat(cli): support storybook flags #40

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 21 additions & 2 deletions docs/content/en/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ To start Storybook in development environment:
</code-block>
</code-group>

By default, it will start the development server on [http://localhost:3003](http://localhost:3003), you can configure the port in the [options](/options#port).
By default, it will start the development server on [http://localhost:3003](http://localhost:3003), you can configure the port in the [options](/options#port) or with CLI options.

### CLI Options
Development command have some options you can pass to alter storybook behaviors.
```
-p, --port [number] Port to run Storybook.
-h, --host [string] Host to run Storybook
-s, --static-dir <dir-names> Directory where to load static files from, comma-separated list. By default it loads Nuxt static dir
--smoke-test Exit after successful start
--ci CI mode (skip interactive prompts, don't open browser)
--quiet Suppress verbose build output
```

## Export

Expand All @@ -52,4 +63,12 @@ Export your Storybook into a static web application to deploy it to GitHub pages
</code-block>
</code-group>

This command will output a `storybook-static/` directory.
By default this command will output a `storybook-static/` directory. See command option to change output directory.

### CLI Options
Build command have some options you can pass to alter storybook behaviors.
```
-s, --static-dir <dir-names> Directory where to load static files from, comma-separated list. By default it loads Nuxt static dir
-o, --output-dir [dir-name] Directory where to store built files
--quiet
```
23 changes: 19 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ import { start, build } from './index'
export const usage = 'nuxt storybook [`dev`|`build`] [`dir`]'

function _run () {
const args = arg({})
const args = arg({
'--static-dir': String,
'-s': '--static-dir',
'--output-dir': String,
'-o': '--output-dir',
'--quiet': Boolean,
'--smoke-test': Boolean,
'--ci': Boolean,
'--port': Number,
'-p': '--port',
'--host': String,
'-h': '--host'
})
const { _, ...flags } = args

let [mode, _dir] = args._
let [mode, _dir] = _
if (!_dir && fs.existsSync(mode)) {
_dir = mode || '.'
mode = 'dev'
Expand All @@ -25,12 +38,14 @@ function _run () {
case 'build':
return build({
rootDir,
mode
mode,
...flags
})
case 'dev':
return start({
rootDir,
mode
mode,
...flags
})
default:
logger.error(`Command "${mode}" not found`)
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async function getStorybookConfig (options: StorybookOptions) {
nuxtBuilder,
nuxtWebpackConfig,
nuxtStorybookConfig,
...options,
frameworkPresets: [
...vueOptions.frameworkPresets,
require.resolve('./preset')
Expand Down
7 changes: 7 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ export interface WebpackExtras {
export interface StorybookOptions {
rootDir: string;
mode: string;
outputDir?: string;
staticDir?: string;
quiet?: boolean;
smokeTest?: Boolean;
ci?: Boolean;
port?: Number;
host?: String;
}