-
Notifications
You must be signed in to change notification settings - Fork 634
/
index.js
104 lines (90 loc) · 3.1 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
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
// Generate README.md file based on JSON data
const fs = require('fs');
const questionsJson = require('./questions.json');
function sortQuestions(a, b) {
// case insensitive sort
const qA = a.question.en.toUpperCase();
const qB = b.question.en.toUpperCase();
if (qA < qB) {
return -1;
}
if (qA > qB) {
return 1;
}
return 0;
}
function stringToSlug(string) {
return string
.toLowerCase()
.replace(/ /g, '-')
.replace(/[^\w-]+/g, '');
}
function categoryMapReducer(accumulator, item) {
if (accumulator[item.category]) {
accumulator[item.category] = [...accumulator[item.category], item];
} else {
accumulator[item.category] = [item];
}
return accumulator;
};
function generateQuestionSectionReducer(lang, i18nCategories) {
return function questionSectionReducer (accumulator, [category, items]) {
const i18nCategory = i18nCategories[category] && i18nCategories[category][lang];
return [
...accumulator,
`\n## ${i18nCategory || category}`,
...items.sort(sortQuestions).map((item) => `* ${item.question[lang] || item.question.en}`)
];
}
}
function getReadmeName(lang) {
if (lang === 'en') {
return 'README.md';
}
return `README.${lang}.md`;
}
function tableOfContentsReducer(accumulator, category) {
return [
...accumulator,
`\n- [${category}](#${stringToSlug(category)})`
];
}
const title = `# 1 on 1 Meeting Questions
Mega list compiled from a variety to sources. Also available here: http://www.managersclub.com/mega-list-of-1-on-1-meeting-questions/
I wrote a book about 1 on 1 meetings. You can find it here: https://www.amazon.com/Effective-One-Ones-Productive-Meaningful-ebook/dp/B0BY89ZZP4
## Applications using this data
Simple React app from @shershen08 that displays random questions from the list
https://compassionate-bose-f21503.netlify.app/
repo here: https://github.com/shershen08/react-tailwind-question-generator
Another app from @perlin, https://1on1questions.netlify.app/
`;
const faq = `
## FAQ
Why is there also a JSON file?
- It can be directly consumed by apps
- README.md can be generated from json file so you only have to make changes in one place`;
const contributing = `
## Contributing
1. Fork repo
2. Add your question to \`questions.json\`.
3. Create new Pull Request
You can update the README manually running \`npm start\` but there is GitHub action that will automatically update the README with your questions.
`;
const categoryMap = questionsJson.questions.reduce(categoryMapReducer, {});
for (const lang of questionsJson.languages) {
const questionsBySection = Object.entries(categoryMap).reduce(generateQuestionSectionReducer(lang, questionsJson.i18nCategories), []);
const tableOfContents = Object.keys(categoryMap).reduce(tableOfContentsReducer, ['\n## Table of Contents']).join('');
const content = [
title,
tableOfContents,
...questionsBySection,
faq,
contributing
];
// create README file
const readmeName = getReadmeName(lang);
fs.writeFile(`./${readmeName}`, content.join('\n'), function (err) {
if (err) throw err;
console.log(`Updated ${readmeName}`);
});
}