forked from hhkaos/awesome-arcgis
-
Notifications
You must be signed in to change notification settings - Fork 6
/
deploy.js
239 lines (202 loc) · 8.44 KB
/
deploy.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
var fs = require('fs');
var path = require('path');
// Avoid file and folder when checking broken links
var excludeFromLinkChecker = [
"docs", "CONTRIBUTING.md",
"templates", "node_modules"
];
// Avoid this files and folders to create/update their TOCs
var excludeFromDocToc = [
"SUMMARY.md", "CONTRIBUTING.md",
"about/README.md", "./README.md",
"./about", "./node_modules"
];
// Fix capitalization
var summary_titles = ["ArcGIS", "GIS","oAuth", "ESA", "PNOA", "HERE",
"USGS NASA", "MODIS", "CSV", "ECW", "GDB", "GeoCSV",
"GeoJSON", "GML", "GPKG", "GPX", "GTFS", "KML", "KMZ",
"LAS", "MDB", "MMPK", "TopoJSON", "OGC", "CAD", "NC",
"AppStudio", "AWS", "JS", "jQuery", "ExtJS", "iOS",
"ArcCatalog", "ArcMap", "GeoAnalytics", "GeoEvent",
"Power BI", "APIs", "AppBuilder", "BIM", "BI", "TPK",
"GeoNet", "AR", "UAVs", "VR", "REST", "API",
"dotGIS", "SRM", "OSIGris", "COTESA", "NodeJS",
"ArcObjects", "DevOps", "TeamDev", "IKONOS",
"QuickBird", "DGN", "DWG", "DXF"];
//Replacing to remove blacnk splaces
var replace_titles = [
["R And D", "R\&D"], ["Mac OS", "macOS"],
["D 3", "D3.js"], ["Vuejs", "Vue.js"],
["Add Ins", "Add-ins"], ["Drone 2 Map", "Drone2Map"],
["3 D Analyst", "3D Analyst"], ["3 D Data", "3D Data"],
["Survey 123", "Survey123"], ["AR", "Augmented Reality"],
["BI", "Business Intelligence"], ["I 3 S", "I3S"],
["VR", "Virtual Reality"], ["Iot Rt", "IoT & RT"],
["Geoeye 1", "GeoEye-1"],
["ArcGIS For Autocad", "ArcGIS for AutoCAD"],
["ArcGIS For Inspire", "ArcGIS for INSPIRE"]
];
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = path.resolve(dir, file);
basename = path.basename(file);
//console.log("basename=",basename);
if(excludeFromLinkChecker.indexOf(basename) !== -1){
//console.log("excluding ", basename);
if (!--pending) done(null, results);
}else{
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) done(null, results);
});
} else {
var ext = path.extname(file)
if(ext === ".md"){
//console.log("including ", file);
results.push(file);
}
if (!--pending) done(null, results);
}
});
}
});
});
};
var fix_summary_capitalziations = function(){
var fs = require('fs');
var someFile = "SUMMARY.md";
fs.readFile(someFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var i = 0;
var capitalizeFirstLetter = function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
do{
var pattern = capitalizeFirstLetter(summary_titles[i].toLocaleLowerCase());
re = new RegExp("\\b"+pattern+"\\b", "g");
data = data.replace(re, summary_titles[i]);
i++;
}while(summary_titles[i]);
var i = 0;
do{
data = data.replace("["+replace_titles[i][0]+"]", "["+replace_titles[i][1]+"]");
i++;
}while(replace_titles[i]);
fs.writeFile(someFile, data, 'utf8', function (err) {
if (err) return console.log(err);
});
});
};
var build_book = function(build){
if(build){
var cmd = 'node node_modules/gitbook-cli/bin/gitbook.js build';
exec(cmd, function(error, stdout, stderr) {
console.log("Building book: ",stdout);
var cmd = 'mv _book docs';
exec(cmd, function(error, stdout, stderr) {
console.log("Renaming folder ./books to ./docs ",stdout);
});
});
}
}
var links = false,
rm_docs = true,
update_summary = true,
build = true;
process.argv.forEach(function (val, index, array) {
//console.log(index + ': ' + val);
switch(val){
case '--links':
links = true;
break;
case '--summary':
update_summary = true;
break;
}
});
var commandExists = require('command-exists');
[{
app: 'awesome_bot',
url: 'https://github.com/dkhamsing/awesome_bot'
}].forEach(function(elem){
commandExists(elem.app, function(err, commandExists) {
if(!commandExists) {
console.log(elem.app + ' is not installed: '+ elem.url);
process.exit();
}
});
;})
var exec = require('child_process').exec;
if(links){
walk(".", function(err, results) {
if (err) throw err;
var len = results.length,
i = 0;
while(i < len){
var cmd = 'awesome_bot --allow-dupe ' + results[i];
exec(cmd, function(error, stdout, stderr) {
// command output is in stdout
var index = stdout.indexOf("Issues :-(")
var output = [];
console.log(stdout.substring(0,stdout.indexOf("\n")));
if(index !== -1){
var tmp = stdout.split("\n");
output.push(tmp[0]);
stdout = stdout.substring(index);
stdout = stdout.split("\n");
stdout = stdout.slice(2,stdout.length-5);
output = output.concat(stdout);
console.log("\n\n"+output.join("\n"));
}
});
i++;
}
});
// // TODO: Add asyncronous call
// var cmd = 'rm -rf awesomebot-results/* && mv ab-re* awesomebot-results';
// exec(cmd, function(error, stdout, stderr) {
// console.log('Moving results from awesomebot to awesomebot-results');
// });
}else{
if(rm_docs){
var cmd = 'rm -rf docs && rm ab-results*';
exec(cmd, function(error, stdout, stderr) {
console.log("Removing last deploy",stdout);
});
}
var cmd = "node node_modules/gitbook-cli/bin/gitbook.js install";
exec(cmd, function(error, stdout, stderr) {
console.log("Installing/updating pluggins: ",stdout);
});
// comand to remove file summary.md
cmd = "rm SUMMARY.md'";
exec(cmd, function(error, stdout, stderr) {
console.log("Removing old summary ",stdout);
excludeFromDocToc = excludeFromDocToc.map(function(a){return '"'+a.replace("./", "\\./")+'"'});
excludeFromDocToc = excludeFromDocToc.join(" | grep -v ");
cmd = `find . -name "*.md" | grep -v ${excludeFromDocToc} | xargs node ./node_modules/doctoc/doctoc.js --title '**Table of contents**'`;
//console.log(cmd)
exec(cmd, function(error, stdout, stderr) {
console.log("Updating tables of contents: ",stdout);
if(update_summary){
var cmd = 'node node_modules/gitbook-summary/bin/summary.js sm';
exec(cmd, function(error, stdout, stderr) {
console.log("Updating summary: ", stdout);
fix_summary_capitalziations();
build_book(build);
});
}else{
build_book(build);
}
});
});
}