-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.js
28 lines (22 loc) · 889 Bytes
/
setup.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
var path = require('path');
var fs = require('fs');
var prettier = require('prettier');
var questionsFolder = path.join(__dirname, '/public/question_answer_pairs');
// Get paths to each question directory
fs.readdir(questionsFolder, (error, directories) => {
if (error) {
console.log("There was an error reading the public/question_answer_pairs directory: ", error);
}
const dirObjects = directories.map(directory => {
return `{question: '/question_answer_pairs/${directory}/question.md', answer: '/question_answer_pairs/${directory}/answer.md'},`
}).join('');
const qaPairsFile = `
// PLEASE NOTE THAT THIS IS AN AUTO-GENERATED FILE.
// PLEASE DO NOT UPDATE
const qaPairs = [
${dirObjects}
];
export default qaPairs;
`;
fs.writeFileSync(path.join(__dirname, '/src/qa_pairs.js'), prettier.format(qaPairsFile, { parser: 'babel' }));
});