From 77b259e26b284d076e6069679e694d940e439ce6 Mon Sep 17 00:00:00 2001 From: Travis Bloom Date: Wed, 18 Oct 2017 12:52:43 -0400 Subject: [PATCH] Add a new CLI config "existing-output-dir" that allows users to pass in a previously built storybook directory. stylistic tweaks fixes --- README.md | 8 ++++++++ bin/storybook_to_ghpages | 26 ++++++++++++++------------ package.json | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 027da86..94151b2 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,14 @@ If you customize the build configuration with some additional params (like stati > Make sure to set the output directory as **`.out`**. +### Skip Build Step + +If you have previously built your storybook output (through a different CI step, etc) and just need to publish it, specify the directory with like this: + +```js + npm run deploy-storybook -- --existing-output-dir=.out +``` + ### Custom deploy configuration If you want to customize Git username, email or commit message, add this to `package.json`: diff --git a/bin/storybook_to_ghpages b/bin/storybook_to_ghpages index 7743a36..3b9bd73 100755 --- a/bin/storybook_to_ghpages +++ b/bin/storybook_to_ghpages @@ -6,7 +6,8 @@ var path = require('path'); var packageJson = require(path.resolve('./package.json')); var argv = require('yargs').argv; -var OUTPUT_DIR = 'out' + Math.ceil(Math.random() * 9999); +var SKIP_BUILD = Boolean(argv['existing-output-dir']) +var OUTPUT_DIR = argv['existing-output-dir'] || 'out' + Math.ceil(Math.random() * 9999); var defaultConfig = { gitUsername: 'GH Pages Bot', @@ -29,16 +30,18 @@ if (!GIT_URL) { process.exit(-1); } -// clear and re-create the out directory -shell.rm('-rf', OUTPUT_DIR); -shell.mkdir(OUTPUT_DIR); +if (!SKIP_BUILD) { + // clear and re-create the out directory + shell.rm('-rf', OUTPUT_DIR); + shell.mkdir(OUTPUT_DIR); -// run our compile script -console.log('=> Building storybook'); -if (packageJson.scripts[NPM_SCRIPT]) { - publishUtils.exec('npm run ' + NPM_SCRIPT + ' -- -o ' + OUTPUT_DIR); -} else { - publishUtils.exec('node ./node_modules/.bin/build-storybook -o ' + OUTPUT_DIR); + // run our compile script + console.log('=> Building storybook'); + if (packageJson.scripts[NPM_SCRIPT]) { + publishUtils.exec('npm run ' + NPM_SCRIPT + ' -- -o ' + OUTPUT_DIR); + } else { + publishUtils.exec('node ./node_modules/.bin/build-storybook -o ' + OUTPUT_DIR); + } } // go to the out directory and create a *new* Git repo @@ -66,8 +69,7 @@ publishUtils.exec('git push --force --quiet ' + GIT_URL + ' ' + SOURCE_BRANCH + shell.cd('..'); shell.rm('-rf', OUTPUT_DIR); -console.log(); -if(TARGET_BRANCH !== 'gh-pages') { +if (TARGET_BRANCH !== 'gh-pages') { var rawgit_url = GIT_URL.replace('github.com', 'rawgit.com').replace('.git', '/') + TARGET_BRANCH + '/index.html'; console.log('=> Storybook deployed to: ' + rawgit_url); diff --git a/package.json b/package.json index 2c3df1b..862ee07 100644 --- a/package.json +++ b/package.json @@ -25,4 +25,4 @@ "shelljs": "^0.7.0", "yargs": "^8.0.1" } -} +} \ No newline at end of file