|
1 | | -var shell = require('shelljs'); |
2 | | -var chalk = require('chalk'); |
3 | | -var publishUtils = require('./utils'); |
4 | | -var path = require('path'); |
5 | | -var packageJson = require(path.resolve('./package.json')); |
6 | | - |
7 | | -var OUTPUT_DIR = 'out' + Math.ceil(Math.random() * 9999); |
8 | | - |
9 | | -shell.echo(chalk.bold(`${packageJson.name}@${packageJson.version}\n`)); |
10 | | - |
11 | | -// get GIT url |
12 | | -console.log(chalk.grey('=> Getting the git remote URL')); |
13 | | -var GIT_URL = publishUtils.exec('git config --get remote.origin.url'); |
14 | | -if (!GIT_URL) { |
15 | | - console.log('This project is not configured with a remote git repo'); |
16 | | - process.exit(-1); |
17 | | -} |
18 | | - |
19 | | -// clear and re-create the out directory |
20 | | -shell.rm('-rf', OUTPUT_DIR); |
21 | | -shell.mkdir(OUTPUT_DIR); |
22 | | - |
23 | | -// run our compile script |
24 | | -console.log(chalk.grey('=> Building storybook')); |
25 | | -if (packageJson.scripts['build-storybook']) { |
26 | | - publishUtils.exec('npm run build-storybook -- -o ' + OUTPUT_DIR); |
27 | | -} else { |
28 | | - publishUtils.exec('build-storybook -o ' + OUTPUT_DIR); |
29 | | -} |
30 | | - |
31 | | -// go to the out directory and create a *new* Git repo |
32 | | -shell.cd(OUTPUT_DIR); |
33 | | -publishUtils.exec('git init'); |
34 | | - |
35 | | -// inside this git repo we'll pretend to be a new user |
36 | | -publishUtils.exec('git config user.name "GH Pages Bot"'); |
37 | | -publishUtils.exec('git config user.email "[email protected]"'); |
38 | | - |
39 | | -// The first and only commit to this new Git repo contains all the |
40 | | -// files present with the commit message "Deploy to GitHub Pages". |
41 | | -publishUtils.exec('git add .'); |
42 | | -publishUtils.exec('git commit -m "Deploy Storybook to GitHub Pages"'); |
43 | | - |
44 | | -// Force push from the current repo's master branch to the remote |
45 | | -// repo's gh-pages branch. (All previous history on the gh-pages branch |
46 | | -// will be lost, since we are overwriting it.) We redirect any output to |
47 | | -// /dev/null to hide any sensitive credential data that might otherwise be exposed. |
48 | | -console.log(chalk.grey('=> Deploying storybook')); |
49 | | -publishUtils.exec('git push --force --quiet ' + GIT_URL + ' master:gh-pages') |
50 | | -shell.cd('..'); |
51 | | -shell.rm('-rf', OUTPUT_DIR); |
52 | | - |
53 | | -console.log(); |
54 | | -console.log(chalk.grey('=> Storybook deployed to: ') + |
55 | | - chalk.cyan(publishUtils.getGHPagesUrl(GIT_URL))); |
| 1 | +var shell = require('shelljs'); |
| 2 | +var chalk = require('chalk'); |
| 3 | +var publishUtils = require('./utils'); |
| 4 | +var path = require('path'); |
| 5 | +var packageJson = require(path.resolve('./package.json')); |
| 6 | + |
| 7 | +var OUTPUT_DIR = 'out' + Math.ceil(Math.random() * 9999); |
| 8 | + |
| 9 | +shell.echo(chalk.bold(`${packageJson.name}@${packageJson.version}\n`)); |
| 10 | + |
| 11 | +// get GIT url |
| 12 | +console.log(chalk.grey('=> Getting the git remote URL')); |
| 13 | +var GIT_URL = publishUtils.exec('git config --get remote.origin.url'); |
| 14 | +if (!GIT_URL) { |
| 15 | + console.log('This project is not configured with a remote git repo'); |
| 16 | + process.exit(-1); |
| 17 | +} |
| 18 | + |
| 19 | +// clear and re-create the out directory |
| 20 | +shell.rm('-rf', OUTPUT_DIR); |
| 21 | +shell.mkdir(OUTPUT_DIR); |
| 22 | + |
| 23 | +// run our compile script |
| 24 | +console.log(chalk.grey('=> Building storybook')); |
| 25 | +if (packageJson.scripts['build-storybook']) { |
| 26 | + publishUtils.exec('npm run build-storybook -- -o ' + OUTPUT_DIR); |
| 27 | +} else { |
| 28 | + publishUtils.exec('build-storybook -o ' + OUTPUT_DIR); |
| 29 | +} |
| 30 | + |
| 31 | +// go to the out directory and create a *new* Git repo |
| 32 | +shell.cd(OUTPUT_DIR); |
| 33 | +publishUtils.exec('git init'); |
| 34 | + |
| 35 | +// inside this git repo we'll pretend to be a new user |
| 36 | +publishUtils.exec('git config user.name "GH Pages Bot"'); |
| 37 | +publishUtils.exec('git config user.email "[email protected]"'); |
| 38 | + |
| 39 | +// The first and only commit to this new Git repo contains all the |
| 40 | +// files present with the commit message "Deploy to GitHub Pages". |
| 41 | +publishUtils.exec('git add .'); |
| 42 | +publishUtils.exec('git commit -m "Deploy Storybook to GitHub Pages"'); |
| 43 | + |
| 44 | +// Force push from the current repo's master branch to the remote |
| 45 | +// repo's gh-pages branch. (All previous history on the gh-pages branch |
| 46 | +// will be lost, since we are overwriting it.) We redirect any output to |
| 47 | +// /dev/null to hide any sensitive credential data that might otherwise be exposed. |
| 48 | +console.log(chalk.grey('=> Deploying storybook')); |
| 49 | +publishUtils.exec('git push --force --quiet ' + GIT_URL + ' master:gh-pages') |
| 50 | +shell.cd('..'); |
| 51 | +shell.rm('-rf', OUTPUT_DIR); |
| 52 | + |
| 53 | +console.log(); |
| 54 | +console.log(chalk.grey('=> Storybook deployed to: ') + |
| 55 | + chalk.cyan(publishUtils.getGHPagesUrl(GIT_URL))); |
0 commit comments