forked from TheOdinProject/javascript-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteExercise.js
More file actions
25 lines (21 loc) · 699 Bytes
/
writeExercise.js
File metadata and controls
25 lines (21 loc) · 699 Bytes
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
const { writeFile } = require("fs/promises");
const { join } = require("path");
const { splitDirectoryName } = require("./helpers");
async function writeExercise(exercisePath) {
const { exerciseName } = splitDirectoryName(exercisePath);
const isSolutionFile = exercisePath.includes("/solution");
const exerciseContent = `const ${exerciseName} = function() {
${isSolutionFile ? "// Replace this comment with the solution code" : ""}
};
// Do not edit below this line
module.exports = ${exerciseName};
`;
await writeFile(
join(
exercisePath,
`${exerciseName}${isSolutionFile ? "-solution" : ""}.js`
),
exerciseContent
);
}
module.exports = { writeExercise };