This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
/
storybook_to_ghpages
executable file
·92 lines (80 loc) · 2.62 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 argv = require('yargs').argv;
const parseRepo = require('parse-repo');
const parseArgs = require('../src/parse-args');
const build = require('../src/build');
const { config, ...args } = parseArgs(packageJson, argv);
// 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
);
// go to the out directory and create a *new* Git repo
shell.cd(args.OUTPUT_DIR);
publishUtils.exec('git init');
// 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 repositoryDetails = parseRepo(GIT_URL);
if (repositoryDetails.host === 'github.com' && args.HOST_TOKEN) {
GIT_URL =
'https://' +
args.HOST_TOKEN +
'@' +
repositoryDetails.host +
'/' +
repositoryDetails.repository;
}
}
publishUtils.exec(
'git push --force --quiet ' +
GIT_URL +
' ' +
args.SOURCE_BRANCH +
':' +
args.TARGET_BRANCH
);
shell.cd('..');
shell.rm('-rf', args.OUTPUT_DIR);
if (args.TARGET_BRANCH !== 'gh-pages') {
const rawGitUrl =
GIT_URL.replace('github.com', 'rawgit.com')
.replace('.git', '')
.replace(/\/$/, '') +
'/' +
args.TARGET_BRANCH +
'/index.html';
console.log('=> Storybook deployed to: ' + rawGitUrl);
} else {
console.log(
'=> Storybook deployed to: ' + publishUtils.getGHPagesUrl(GIT_URL)
);
}