forked from CodingTrain/website-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkVariations.js
90 lines (80 loc) · 2.7 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require("fs");
const yaml = require("yaml-front-matter");
const GitHub = require("octocat");
const challenges = [];
require("dotenv").config();
const client = new GitHub({
token: process.env.OCTOCAT_KEY
});
(async () => {
let current_data = await client.get(`/gists/${process.env.GIST_ID}`);
current_data = current_data.body.files["CodingChallenge_Variations.md"].content;
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);
challenges.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,
contributions: parsed_content.contributions || []
});
}
let result_table =
"| Number | Name | p5.js | Web Editor | Processing | Other | Number of Contributions |\n| --- | --- | --- | --- | --- | --- | --- | \n";
for (const challenge of challenges) {
if (!challenge.repo) continue;
const subdirectories = fs.readdirSync(`./CodingChallenges/${challenge.repo}`);
let line = `| ${challenge.id} | ${challenge.title} | `;
console.log(`Processing Challenge ${challenge.id}: ${challenge.title}`);
//p5.js
if (subdirectories.includes("P5")) {
challenge.p5 = true;
line += "<ul><li> - [x] </li></ul> |";
} else {
line += "<ul><li> - [ ] </li></ul> |";
}
//Web Editor
if (challenge.web_editor) {
line += "<ul><li> - [x] </li></ul> |";
} else {
line += "<ul><li> - [ ] </li></ul> |";
}
//Processing
if (subdirectories.includes("Processing")) {
challenge.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)) challenge.other = true;
});
if (challenge.other) {
line += "<ul><li> - [x] </li></ul> |";
} else {
line += "<ul><li> - [ ] </li></ul> |";
}
line += `${challenge.contributions.length} \n`;
result_table += line;
}
if (current_data === result_table) {
console.log("\x1b[35m", "Aborting. The data has not changed.");
process.exit(0);
}
//Upload content to GitHub Gist
console.log("\x1b[32m", `Uploading result to GitHub Gist. Gist ID: ${process.env.GIST_ID}`);
client.patch(`/gists/${process.env.GIST_ID}`, {
files: {
"CodingChallenge_Variations.md": {
content: result_table
}
}
});
})();