/
gh-pages.js
executable file
·131 lines (117 loc) · 4.99 KB
/
gh-pages.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env node
var exec = require('child_process').exec,
fs = require('fs'),
step = require('step'),
colors = require('colors'),
mkdirp = require('mkdirp'),
readline = require('readline');
try {
var conf = require("../config");
} catch(e) {
console.log('Please execute "%s" in haroopress root directory', 'make init'.yellow);
process.exit(1);
}
var rl;
if(fs.existsSync(conf.deployDir)) {
mkdirp.sync(conf.deployDir);
}
process.chdir(conf.deployDir);
rl = readline.createInterface(process.stdin, process.stdout, null);
try {
var deployDir = conf.deployDir +'/.git';
var stat = fs.statSync(deployDir);
if(stat.isDirectory()) {
exec('rm -rf '+ deployDir, function(err, stdout, stderr) {});
}
} catch(e) {}
console.log('haroo> %s', 'Enter the read/write repository for your haroopress site '.yellow);
console.log('"'+'https://github.com/[github-id]/[github-id].github.io.git'.red +'"');
rl.question(' > ', function(repo) {
var user, regx, branch, project;
if(repo.indexOf('https') >= 0) {
regx = /github.com\/([^\/]+)/;
} else {
regx = /:([^\/]+)/;
}
user = repo.match(regx)[1];
branch = (repo.match(/\/[\w-]+.github.io/) == null) ? 'gh-pages' : 'master';
project = (branch == 'gh-pages') ? repo.match(/\/([^\.]+)/)[1] : '';
console.log('haroo> git remote -v¶'.yellow);
exec('git remote -v', function(code, stdout, stderr) {
console.log(stdout);
if (stdout.match(/origin.+?\/haroopress/) != null) {
step(
function gitInit() {
console.log('haroo> Start setting github pages branch ¶'.yellow);
exec('git init', this);
},
function gitRename(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Completed git repository initialize ¶'.yellow);
exec('git remote rename origin haroopress', this);
},
function isMaster(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Repository remote\'s name origin -> haroopress ¶'.yellow);
if (branch == 'master') {
console.log('haroo> Git remote add to origin ¶'.red);
exec('git remote add origin '+ repo, this);
}
},
function setGitConfig(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Added remote %s as origin ¶'.yellow, repo);
exec('git config branch.master.remote origin', this);
},
function setBranch(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Set origin as default remote ¶'.yellow);
exec('git branch -m master source', this);
},
function initHaroog(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Created inex.html ¶'.yellow);
exec('echo "<!-- haroopress init -->" > index.html', this);
},
function gitAdd(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> git add . ¶'.yellow);
exec('git add .', this);
},
function createCommitter(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Copy temp commiter ¶'.yellow);
exec('cp ../bin/git-commit .git-commit', this);
},
function gitCommit(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> git commit ¶'.yellow);
exec('./.git-commit', this);
},
function removeCommiter(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> Remove temp commiter ¶'.yellow);
exec('rm -rf .git-commit', this);
},
/*function gitBranch(err, stdout, stderr) {
console.log('> git branch -m gh-pages')
exec('git branch -m gh-pages', this);
},*/
function gitRemoteAdd(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> git remote add origin ¶'.yellow);
if (branch != 'master') {
console.log('haroo> Git remote add to origin ¶'.red);
exec('git remote add origin '+ repo, this)
}
},
function end(code, stdout, stderr) {
console.log(stdout);
console.log('haroo> completed'.cyan);
}
);
}
});
rl.close();
process.stdin.destroy();
});