-
Notifications
You must be signed in to change notification settings - Fork 9
/
generate.js
132 lines (97 loc) · 2.54 KB
/
generate.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
const request = require('request');
const dataUrl = 'https://raw.githubusercontent.com/v-braun/cocoa-rocks/master/src/data/data.compiled.json';
const log = require('colorprint');
const fs = require('fs');
function createEntry(rec){
let md = `**[${rec.github.name}](${rec.repo})**
*from [${rec.github.owner.login}](${rec.github.owner.html_url}):*
> *${rec.github.description}*
`
return md
}
function createList(recByTag){
let result = '';
for (let tag in recByTag) {
if (!recByTag.hasOwnProperty(tag)) continue;
let records = recByTag[tag];
result += `
## ${tag}
`;
for(let rec of records){
let entry = createEntry(rec);
result += entry + '\n\n';
}
}
return result;
}
function createNew(data){
let max = data.length;
if(max > 10){
max = 10
}
let newEntries = [];
for(let i = 0; i < max; i++ ){
let entry = createEntry(data[i]);
entry += `
![](${data[i].banner})
`;
newEntries.push(entry);
}
let result = newEntries.join(`
--------------------------
`);
return result;
}
function createRecByTag(data){
let recByTag = {};
for(let rec of data){
let tag = rec.tags[0];
if(!recByTag[tag]){
recByTag[tag] = [];
}
recByTag[tag].push(rec);
}
return recByTag;
}
function createTOC(recByTag){
let result = `
# Content
- [New](#new)
- [By Category](#By-Category)
`
for (let tag in recByTag) {
if (!recByTag.hasOwnProperty(tag)) continue;
let space1 = ' ';
result += `${space1}- [${tag}](#${tag})\n`
}
return result;
}
request.get({uri: dataUrl}, (err, response, body) => {
if(err){
log.fatal('fetch for data failed');
log.error(err);
return process.exit(1);
}
let data = JSON.parse(body);
log.notice(`data file downloaded with ${data.length}`);
let recByTag = createRecByTag(data);
let toc = createTOC(recByTag)
let list = createList(recByTag);
let newList = createNew(data);
let mdAll = `
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
![PR Welcome](https://img.shields.io/badge/PR-welcome-green.svg)
# awesome-cocoa
A curated list of awesome cocoa libraries.
# Contributing
Want to share a new Cocoa Control?
Add your repo's information to my [cocoa-rocks](https://github.com/v-braun/cocoa-rocks) repository.
Your repo will be published on the [cocoa.rocks](https://cocoa.rocks) website and here.
${toc}
# New
${newList}
# By Category
${list}
`;
fs.writeFileSync('README.md', mdAll);
})