|
1 | | -const { cd, exec, echo, touch } = require("shelljs") |
2 | | -const { readFileSync } = require("fs") |
3 | | -const url = require("url") |
| 1 | +const { cd, exec, echo, touch } = require('shelljs') |
| 2 | +const { readFileSync } = require('fs') |
| 3 | +const url = require('url') |
4 | 4 |
|
5 | | -let repoUrl |
6 | | -let pkg = JSON.parse(readFileSync("package.json") as any) |
7 | | -if (typeof pkg.repository === "object") { |
8 | | - if (!pkg.repository.hasOwnProperty("url")) { |
9 | | - throw new Error("URL does not exist in repository section") |
10 | | - } |
11 | | - repoUrl = pkg.repository.url |
12 | | -} else { |
13 | | - repoUrl = pkg.repository |
| 5 | +const info = { |
| 6 | + TRAVIS_BRANCH: process.env.TRAVIS_BRANCH, |
| 7 | + TRAVIS_PULL_REQUEST: process.env.TRAVIS_PULL_REQUEST, |
| 8 | + TRAVIS_PULL_REQUEST_BRANCH: process.env.TRAVIS_PULL_REQUEST_BRANCH, |
14 | 9 | } |
| 10 | +echo(`running on branch ${JSON.stringify(info)}`) |
| 11 | + |
| 12 | +if (info.TRAVIS_BRANCH === 'master' && info.TRAVIS_PULL_REQUEST === 'false') { |
| 13 | + const pkg = JSON.parse(readFileSync('package.json') as any) |
| 14 | + let repoUrl |
| 15 | + if (typeof pkg.repository === 'object') { |
| 16 | + if (!pkg.repository.hasOwnProperty('url')) { |
| 17 | + throw new Error('URL does not exist in repository section') |
| 18 | + } |
| 19 | + repoUrl = pkg.repository.url |
| 20 | + } else { |
| 21 | + repoUrl = pkg.repository |
| 22 | + } |
15 | 23 |
|
16 | | -let parsedUrl = url.parse(repoUrl) |
17 | | -let repository = (parsedUrl.host || "") + (parsedUrl.path || "") |
18 | | -let ghToken = process.env.GH_TOKEN |
| 24 | + const parsedUrl = url.parse(repoUrl) |
| 25 | + const repository = (parsedUrl.host || '') + (parsedUrl.path || '') |
| 26 | + const ghToken = process.env.GH_TOKEN |
19 | 27 |
|
20 | | -echo("Deploying docs!!!") |
21 | | -cd("dist/docs") |
22 | | -touch(".nojekyll") |
23 | | -exec("git init") |
24 | | -exec("git add .") |
25 | | -exec('git config user.name "Michael Wittwer"') |
26 | | -exec('git config user.email "[email protected]"') |
27 | | -exec('git commit -m "docs(docs): update gh-pages"') |
28 | | -exec( |
29 | | - `git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages` |
30 | | -) |
31 | | -echo("Docs deployed!!") |
| 28 | + echo('Deploying docs!!!') |
| 29 | + cd('dist/docs') |
| 30 | + touch('.nojekyll') |
| 31 | + exec('git init') |
| 32 | + exec('git add .') |
| 33 | + exec('git config user.name "Michael Wittwer"') |
| 34 | + exec('git config user.email "[email protected]"') |
| 35 | + exec('git commit -m "docs(docs): update gh-pages"') |
| 36 | + exec( |
| 37 | + `git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages` |
| 38 | + ) |
| 39 | + echo('Docs deployed!!') |
| 40 | +} else { |
| 41 | + echo('Not running on master -> skipping docs deployment') |
| 42 | +} |
0 commit comments