forked from angular-schule/angular-cli-ghpages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (57 loc) · 1.89 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var path = require('path'),
fs = require('fs'),
ghpages = require('gh-pages'),
denodeify = require('denodeify');
exports.run = function (options) {
options = options || {};
if (options.silent === undefined) {
options.silent = true;
}
if (options.dotfiles === undefined) {
options.dotfiles = true;
}
if (options['name'] && options['email']) {
options.user = {
name: options['name'],
email: options['email']
}
};
// gh-pages: forwards messages to console
options.logger = function (message) { console.log(message + "\n"); }
var dir = path.join(process.cwd(), options.dir);
if (process.env.TRAVIS) {
options.message += '\n\n' +
'Triggered by commit: https://github.com/' + process.env.TRAVIS_REPO_SLUG + '/commit/' + process.env.TRAVIS_COMMIT + '\n' +
'Travis build: https://travis-ci.org/' + process.env.TRAVIS_REPO_SLUG + '/builds/' + process.env.TRAVIS_BUILD_ID;
}
// for your convenience - here you can hack credentials into the repository URL
if (process.env.GH_TOKEN && options.repo) {
options.repo = options.repo.replace('GH_TOKEN', process.env.GH_TOKEN);
}
// always clean the cache directory.
// avoids "Error: Remote url mismatch."
ghpages.clean();
var access = publish = denodeify(fs.access);
var publish = denodeify(ghpages.publish);
function go() {
return Promise.resolve();
}
return go()
.then(function () {
return access(dir, fs.F_OK)
})
.catch(function (error) {
console.error('Dist folder does not exist. Check the dir --dir parameter or build the project first!\n');
return Promise.reject(error);
})
.then(function () {
return publish(dir, options)
})
.then(function () {
console.log('Successfully published!\n');
})
.catch(function (error) {
console.error('An error occurred!\n');
return Promise.reject(error);
});
};