This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
storybook_to_ghpages
executable file
·92 lines (74 loc) · 2.65 KB
/
storybook_to_ghpages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
const shell = require('shelljs');
const publishUtils = require('../src/utils');
const path = require('path');
const packageJson = require(path.resolve('./package.json'));
const parseRepo = require('parse-repo');
const parseArgs = require('../src/parse-args');
const build = require('../src/build');
const { config, ...args } = parseArgs(packageJson);
// get GIT url
console.log('=> Getting the git remote URL');
let GIT_URL = publishUtils.exec(
`git config --get remote.${args.GIT_REMOTE}.url`
);
if (!GIT_URL) {
console.log('This project is not configured with a remote git repo');
process.exit(-1);
}
build(
args.SKIP_BUILD,
args.OUTPUT_DIR,
packageJson,
args.PACKAGES_DIRECTORY,
args.NPM_SCRIPT,
args.MONOREPO_INDEX_GENERATOR
);
if (args.DRY_RUN) {
return;
}
// go to the out directory and create a *new* Git repo
shell.cd(args.OUTPUT_DIR);
publishUtils.exec('git init');
// if --source-branch specified, it needs to exist in the new repo too
const { SOURCE_BRANCH } = args;
if (!!SOURCE_BRANCH) {
publishUtils.exec(`git checkout -b ${SOURCE_BRANCH}`);
}
// inside this git repo we'll pretend to be a new user
publishUtils.exec(`git config user.name ${JSON.stringify(config.gitUsername)}`);
publishUtils.exec(`git config user.email ${JSON.stringify(config.gitEmail)}`);
// disable GPG signing
publishUtils.exec('git config commit.gpgsign false');
// The first and only commit to this new Git repo contains all the
// files present with the commit message "Deploy to GitHub Pages".
publishUtils.exec('git add .');
publishUtils.exec(`git commit -m ${JSON.stringify(config.commitMessage)}`);
// Force push from the current repo's source branch (master by default) to the remote
// repo's gh-pages branch. (All previous history on the gh-pages branch
// will be lost, since we are overwriting it.) We redirect any output to
// /dev/null to hide any sensitive credential data that might otherwise be exposed.
console.log('=> Deploying storybook');
if (args.CI_DEPLOY) {
const { host, repository } = parseRepo(GIT_URL);
if (args.HOST_TOKEN) {
GIT_URL = `https://${args.HOST_TOKEN}@${host}/${repository}`;
}
}
const { TARGET_BRANCH } = args;
publishUtils.exec(
`git push --force --quiet ${GIT_URL} ${SOURCE_BRANCH}:${TARGET_BRANCH}`
);
shell.cd('..');
shell.rm('-rf', args.OUTPUT_DIR);
if (TARGET_BRANCH !== 'gh-pages') {
const host = GIT_URL.replace('github.com', 'rawgit.com')
.replace('.git', '')
.replace(/\/$/, '');
const rawGitUrl = `${host}/${TARGET_BRANCH}/index.html`;
console.log(`=> Storybook deployed to: ${rawGitUrl}`);
} else {
console.log(
`=> Storybook deployed to: ${publishUtils.getGHPagesUrl(GIT_URL)}`
);
}