forked from CodingTrain/website-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckVariations.js
76 lines (65 loc) · 2.09 KB
/
checkVariations.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
const fs = require('fs');
const yaml = require('yaml-front-matter');
const results = [];
(() => {
const yaml_files = fs.readdirSync('_CodingChallenges');
for (const yaml_file of yaml_files) {
const content = fs.readFileSync(`./_CodingChallenges/${yaml_file}`, 'UTF8');
const parsed_content = yaml.loadFront(content);
results.push({
id: parsed_content.video_number,
title: parsed_content.title,
repo: parsed_content.repository || null,
p5: false,
processing: false,
web_editor: parsed_content.web_editor || false,
other: false
});
}
let result_table =
'| Number | Name | p5.js | Web Editor | Processing | Other | Folder |\n';
result_table +=
'| --- | --- | --- | --- | --- | --- | --- | \n';
for (const result of results) {
if (!result.repo) continue;
const subdirectories = fs.readdirSync(`./CodingChallenges/${result.repo}`);
let line = `| ${result.id} | ${result.title} | `;
console.log(`Updating Challenge ${result.id}: ${result.title}`);
//p5.js
if (subdirectories.includes('P5')) {
result.p5 = true;
line += '<ul><li> - [x] </li></ul> |';
} else {
line += '<ul><li> - [ ] </li></ul> |';
};
//Web Editor
if (result.web_editor) {
line += '<ul><li> - [x] </li></ul> |';
} else {
line += '<ul><li> - [ ] </li></ul> |';
}
//Processing
if (subdirectories.includes('Processing')) {
result.processing = true;
line += '<ul><li> - [x] </li></ul> |';
} else {
line += '<ul><li> - [ ] </li></ul> |';
};
//Other
const others = ['Node', 'JavaScript'];
others.forEach(elt => {
if (subdirectories.includes(elt)) result.other = true;
});
if (result.other) {
line += '<ul><li> - [x] </li></ul> |';
} else {
line += '<ul><li> - [ ] </li></ul> |';
}
line += `${result.repo} \n`
result_table += line;
}
if (fs.existsSync('CodingChallenge_Variations.md')) {
fs.unlinkSync('CodingChallenge_Variations.md');
}
fs.writeFileSync('CodingChallenge_Variations.md', result_table, 'UTF8');
})();