-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathdeploy:demo.js
51 lines (47 loc) · 1.36 KB
/
deploy:demo.js
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
/* eslint-disable no-console */
const ghpages = require('gh-pages');
const pkg = require('./../package.json');
const path = require('path');
const chalk = require('chalk');
const fs = require('fs');
const distPath = path.join(__dirname, '../demo/dist');
const deploy = (options = {}) => {
ghpages.publish(distPath, Object.assign({
message: pkg.version
}, options), (err) => {
if (err) {
error([err]);
return;
}
console.log(chalk.green('Demo has succesfully deployed.'));
});
};
const error = (errs = []) => {
errs.forEach((err) => {
console.log(chalk.red(err));
});
process.exit(1);
};
try {
fs.accessSync(distPath, fs.F_OK);
if (process.env.TRAVIS) {
if (process.env.GITHUB_TOKEN) {
deploy({
repo: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.TRAVIS_REPO_SLUG}.git`,
user: {
name: 'Travis CI'
}
});
} else {
error(['process.env.GITHUB_TOKEN with "repo" access is required to deploy gh-pages.']);
}
} else {
// Deploys using git origin, username and email.
deploy();
}
} catch (e) {
error([
`${distPath} does not exist.`,
'Please run "npm i && npm run i:demo && npm run build:demo" and try again.'
]);
}