1 Star 0 Fork 0

GitHub/awesome-xamarin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
update-stars.js 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
Benoit Jadinon 提交于 2018-08-30 00:14 . updated stars
'use strict';
var fs = require('fs'), https = require('https');
var readme = fs.readFileSync('README.md', {encoding: 'utf8'});
var regex = /\[\**([^\]]*)[^\]]*\**\]\((https?:\/\/github.com\/([A-z0-9\-]+\/[A-z0-9\-]+))\)/g
var stars = {};
var promises = [];
var agent = new https.Agent({maxSockets: 1, keepAlive: true});
var requestOptions = {
hostname: 'api.github.com',
auth: 'benoitjadinon:6d5082698188d0863565c74b8b3a52d9a1468cd4',
headers: {'User-Agent':'benoitjadinon'},
method: 'GET',
agent: agent
};
var match;
while ((match = regex.exec(readme)) !== null) {
var promise = new Promise(function(resolve, reject) {
var repo = match[3].slice();
var options = Object.assign({}, requestOptions);
options.path = '/repos/' + repo;
https.request(options, function(res) {
if (res.statusCode != 200) {
resolve();
return;
}
var body = '';
res.on('data', function(chunk) {
body += chunk.toString('utf8');
});
res.on('end', function() {
stars[repo] = JSON.parse(body).stargazers_count;
console.log(repo + ' ' + stars[repo]);
resolve();
});
}).on('error', function(err) {
resolve();
}).end();
});
promises.push(promise);
}
Promise.all(promises).then(function() {
console.log('Writing README...');
readme = readme.replace(regex, function(match, description, url, repo) {
if (stars[repo] === undefined) { return match; }
var text = '[';
if (stars[repo] > 100) {
text += '**';
}
text += description + "" + stars[repo].toLocaleString();
if (stars[repo] > 100) {
text += '**';
}
text += '](' + url + ')';
return text;
});
fs.writeFileSync('README.md', readme);
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/soft_mirrors/awesome-xamarin.git
[email protected]:soft_mirrors/awesome-xamarin.git
soft_mirrors
awesome-xamarin
awesome-xamarin
master

搜索帮助