forked from ryanburgess/engineer-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (68 loc) · 2.21 KB
/
index.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
'use strict';
const fs = require('fs');
const obj = require('./list.json');
const videos = [];
const podcasts = [];
const books = [];
const articles = [];
const newsletters = [];
const mentoring = [];
let content = '# Engineering Manager Resources \n A list of engineering manager resource links.';
// create lists of resources
for (const resource of obj) {
const title = resource.title;
const url = resource.url;
const cat = resource.cat;
const reason = resource.reason;
const categoryMap = {
book: books,
video: videos,
podcast: podcasts,
article: articles,
newsletter: newsletters,
mentoring: mentoring,
};
categoryMap[cat].push({'title': title, 'url': url, 'reason': reason});
}
// create content of the list of links
const outputLinks = (obj, title) => {
content += `\n\n## ${title}`;
const duplicates = [];
for (const out of obj) {
// avoid duplicates
if (duplicates.indexOf(out.url) === -1) {
duplicates.push(out.url);
// provide a reason why the resource is helpful
let reasonDetails = '';
// if there isn't a reason provided in list.json keep reasonDetails blank
if (out.reason !== undefined && out.reason !== '') {
reasonDetails = ` - ${out.reason}`
}
// create the content that will be output to the Readme
content += (
`\n * [${out.title}](${out.url})${reasonDetails}`
);
}
}
}
outputLinks(mentoring, 'Mentoring');
outputLinks(books, 'Books');
outputLinks(videos, 'Videos');
outputLinks(podcasts, 'Podcasts');
outputLinks(articles, 'Articles');
outputLinks(newsletters, 'Newsletters');
// create contributing instructions
content += ('\n\n## Contributing \n' +
'1. Fork it\n' +
'2. Run `npm install`\n' +
'3. Add your resource to `list.json`\n' +
'4. Run `node index` to update `README.md` with your changes\n' +
'5. Create your feature branch (`git checkout -b my-new-feature`)\n' +
'6. Commit your changes (`git commit -am "Add some feature"`)\n' +
'7. Push to the branch (`git push origin my-new-feature`)\n' +
'8. Create new Pull Request\n');
// create README file
fs.writeFile('./README.md', content, function (err) {
if (err) throw err;
console.log('Updated resource list');
});