-
Notifications
You must be signed in to change notification settings - Fork 0
/
rev.js
113 lines (93 loc) · 2.97 KB
/
rev.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
#!/usr/bin/env node
var http = require('http');
var path = require('path');
var fs = require('fs');
var spawn = require('child_process').spawn;
var url = process.argv[2];
var dirObj = path.parse(path.resolve());
var theme = dirObj.base;
(function(){
function getCNAME(cb){
fs.readFile(path.resolve() + '/CNAME', 'utf8', function(err, data){
// if(err) return false;
if(data) {
console.log('––––––––––––––––––––––––––')
console.log(' Using CNAME ');
var CNAME = data.split('\n');
if(CNAME[0]){ url = CNAME[0]; }
if(CNAME[1]){ theme = CNAME[1]; }
}
cb();
});
}
function getRemote(){
if(process.argv.find(arg => arg === '-a' || arg === '--auto')){
var fullDir = path.resolve().split(path.sep)
var currDir = fullDir[fullDir.length -1]
theme = currDir
url = theme + '.thrv.xyz'
console.log('url: ' + url)
console.log('themeDir: ' + theme)
}
getCNAME(function(){
if(!url || !theme){
return console.log('revcheck <site-url> [--auto|-a]')
}
if(url.indexOf('http') < 0 ){
url = 'http://' + url;
}
http.get(url + '/wp-content/themes/' + theme + '/VERSION', function(res){
res.setEncoding('utf8');
var str = '';
res.on('data', function(chunk){
str += chunk;
});
res.on('end', function(){
var local = getLocal(str);
});
res.resume();
}).on('error', function(e) {
console.log('Got error: ' + e.message);
});
});
}
function getLocal(remote){
fs.readFile(path.resolve() + '/.git/refs/heads/master', 'utf8', function(err, data){
if(err) console.log(err);
if(data) {
var local = data.substr(0, 7)
if(local.trim() == remote.trim()){
console.log('––––––––––––––––––––––––––')
console.log(' all up to date 😁 ')
console.log('––––––––––––––––––––––––––')
} else if(remote.trim().length < 10 ) {
console.log('–––––––––––––')
console.log('mismatch 🤔')
console.log('local: ' + local.trim())
console.log('remote: ' + remote.trim())
console.log('trying again...')
setTimeout(function(){
getRemote()
}, 5000)
} else {
console.log('––––––––––––––––––––––––––')
console.log(remote)
}
}
})
}
if(process.argv.find(arg => arg === 'push' )){
var gp = spawn('git', ['push']);
gp.stdout.on('data', (data) => {
console.log(`${data}`);
});
gp.stderr.on('data', (data) => {
console.log(`${data}`);
});
gp.on('close', (code) => {
getRemote();
});
} else {
getRemote()
}
})();