Repository navigation
Expand file tree
/
Copy pathdeploy.js
More file actions
49 lines (47 loc) · 1.81 KB
/
Copy pathdeploy.js
File metadata and controls
49 lines (47 loc) · 1.81 KB
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
const simpleGit = require('simple-git');
const child_process = require('child_process');
const { exit } = require('process');
const ghpages = require('gh-pages');
// create SimpleGit instance with shousetsubook directory
console.log(process.cwd() + '/dist')
var shousetsubook = simpleGit();
shousetsubook.fetch('--all').status(onStatus).getRemotes(true,onGetRemotes).revparse('HEAD', onRevparse);
var gitConditions = [];
function onStatus (err, statusResult) {
console.log(statusResult)
if (!statusResult.isClean()) {
gitConditions.push('working directory is not clean');
}
if (statusResult.current !== "main") {
gitConditions.push('current branch is not main');
}
if (statusResult.tracking !== "origin/main") {
gitConditions.push('current branch is not tracking origin/main');
}
if (statusResult.ahead !== 0 || statusResult.behind !== 0) {
gitConditions.push('current branch is not up-to-date with origin/main');
}
}
function onGetRemotes(err, getRemotesResult) {
correctRemote = false;
getRemotesResult.forEach(remote => {
if (remote.name == 'origin' && remote.refs.push == 'git@github.com:shousetsubook/shousetsubook.github.io.git' && remote.refs.push == remote.refs.fetch) {
correctRemote = true;
}
})
if (!correctRemote) {
gitConditions.push('remote origin with correct refs does not exist');
}
}
function onRevparse (err, commit) {
if (gitConditions.length > 0) {
console.log('Could not deploy because ' + gitConditions.join(', '));
exit(1);
}
exit(0);
child_process.execSync('npm run build',{stdio:[0,1,2]});
console.log('Publishing to gh-pages branch with message: ' + commit)
ghpages.publish('dist', {
message: commit
});
}