UNPKG

3.3 kBJavaScriptView Raw
1const yargs = require('yargs');
2
3const defaultConfig = {
4 gitUsername: 'GH Pages Bot',
5 gitEmail: 'hello@ghbot.com',
6 commitMessage: 'Deploy Storybook to GitHub Pages'
7};
8
9const { argv } = yargs
10 .wrap(yargs.terminalWidth())
11 .option('help', {
12 alias: 'h',
13 desc: 'Show help.',
14 type: 'boolean'
15 })
16 .option('existing-output-dir', {
17 alias: 'e',
18 desc:
19 'If you have previously built your storybook output (through a different CI step, etc) and just need to publish it',
20 type: 'string'
21 })
22 .option('out', {
23 alias: 'o',
24 desc: 'Configure the output directory',
25 type: 'string'
26 })
27 .option('packages', {
28 alias: 'p',
29 desc: 'Directory for package.jsons (monorepo support)',
30 type: 'string'
31 })
32 .option('monorepo-index-generator', {
33 alias: 'm',
34 desc:
35 'Path to file to customize the monorepo index.html. This function should return the html for the page.',
36 type: 'string'
37 })
38 .option('script', {
39 alias: 's',
40 desc: 'Specify the build script in your package.json',
41 type: 'string',
42 defaultValue: 'build-storybook'
43 })
44 .option('ci', {
45 desc: 'Deploy the storybook in CI mode (github only)',
46 type: 'boolean'
47 })
48 .option('dry-run', {
49 desc: 'Run build but hold off on publishing',
50 type: 'boolean'
51 })
52 // Github Variables
53 .option('remote', {
54 desc: 'Git remote to push to',
55 type: 'string',
56 default: 'origin'
57 })
58 .option('branch', {
59 desc: 'Git branch to push to',
60 type: 'string',
61 default: 'gh-pages'
62 })
63 .option('source-branch', {
64 desc: 'Source branch to push from',
65 type: 'string',
66 default: 'master'
67 })
68 .option('host-token-env-variable', {
69 alias: 't',
70 desc: 'Github token for CI publish',
71 type: 'string',
72 default: 'GH_TOKEN'
73 })
74 // AWS Variables
75 .option('aws-profile', {
76 desc:
77 'AWS profile to use for publishing. Use NONE to exclude the --profile flag.',
78 type: 'string',
79 default: 'default'
80 })
81 .option('bucket-path', {
82 desc: 'AWS bucket path to use for publishing',
83 type: 'string'
84 })
85 .option('s3-sync-options', {
86 desc: 'Additional options to pass to AWSCLI s3 sync',
87 type: 'string'
88 });
89
90module.exports = packageJson => {
91 const HOST_TOKEN_ENV_VARIABLE = argv['host-token-env-variable'] || 'GH_TOKEN';
92
93 return {
94 config: Object.assign(
95 {},
96 defaultConfig,
97 packageJson['storybook-deployer'] || defaultConfig
98 ),
99 SKIP_BUILD: Boolean(argv['existing-output-dir']),
100 OUTPUT_DIR:
101 argv.out ||
102 argv['existing-output-dir'] ||
103 'out' + Math.ceil(Math.random() * 9999),
104 PACKAGES_DIRECTORY: argv.packages,
105 MONOREPO_INDEX_GENERATOR: argv['monorepo-index-generator'],
106 NPM_SCRIPT: argv.script || 'build-storybook',
107 CI_DEPLOY: Boolean(argv.ci) || Boolean(process.env.CI),
108 DRY_RUN: Boolean(argv.dryRun),
109 // Git Variables
110 GIT_REMOTE: argv.remote || 'origin',
111 TARGET_BRANCH: argv.branch || 'gh-pages',
112 SOURCE_BRANCH: argv['source-branch'] || 'master',
113 HOST_TOKEN: process.env[HOST_TOKEN_ENV_VARIABLE],
114 // AWS Variables
115 AWS_PROFILE: argv['aws-profile'] || 'default',
116 BUCKET_PATH: argv['bucket-path'],
117 S3_PATH: 's3://' + argv['bucket-path'],
118 S3_SYNC_OPTIONS: argv['s3-sync-options']
119 };
120};