Permalink
Browse files

docs, feat: add awesome sync tool.

  • Loading branch information...
xicilion committed Sep 27, 2017
1 parent d5d1196 commit ec4958dfc9050b3be5034fa1cfb6cf54e0c1f9a7
Showing with 48 additions and 0 deletions.
  1. +48 −0 tools/awesome.js
View
@@ -0,0 +1,48 @@
var fs = require("fs");
var ssl = require("ssl");
var http = require("http");
var path = require('path');
var coroutine = require('coroutine');
ssl.loadRootCerts();
var docsFolder = path.join(__dirname, "../docs/docs/awesome/");
function clean_folder(p) {
var dir = fs.readdir(p);
console.log("clean", p);
dir.forEach(function (name) {
var fname = path.join(p, name);
var f = fs.stat(fname);
if (f.isDirectory()) {
clean_folder(fname);
fs.rmdir(fname);
} else
fs.unlink(fname);
});
}
clean_folder(docsFolder);
fs.mkdir(path.join(docsFolder, 'module'));
var list = new Buffer(http.get("https://api.github.com/repos/fibjs/awesome/readme", {
"Authorization": "token e9dd2316e2373af6bae66c9f6116c5fecf1ce536"
}).json().content, 'base64').toString();
var ls = [];
list = list.replace(/- \[(.+?)\]\((.+?)\)/g, (s, s1, s2) => {
var u = s2.replace(/^https:\/\/github.com\//, 'https://api.github.com/repos/') + '/readme';
console.log('getting', u);
coroutine.sleep(100);
var doc = new Buffer(http.get(u, {
"Authorization": "token e9dd2316e2373af6bae66c9f6116c5fecf1ce536"
}).json().content, 'base64').toString();
fs.writeTextFile(path.join(docsFolder, 'module', s1 + '.md'), doc);
var s = `[${s1}](./module/${s1}.md)`
ls.push('* ' + s);
return '- ' + s;
});
fs.writeTextFile(path.join(docsFolder, 'README.md'), list);
fs.writeTextFile(path.join(docsFolder, 'SUMMARY.md'), ls.join('\n'));

0 comments on commit ec4958d

Please sign in to comment.