-
Notifications
You must be signed in to change notification settings - Fork 35.1k
/
plopFile.js
46 lines (41 loc) · 1.46 KB
/
plopFile.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
const { mkdir } = require("fs/promises");
const { join } = require("path");
const { camelCase } = require("case-anything");
const { createExerciseDirectoryName } = require("./generators/helpers");
const { writeReadme } = require("./generators/writeReadme");
const { writeExercise } = require("./generators/writeExercise");
const { writeExerciseSpec } = require("./generators/writeExerciseSpec");
module.exports = function (plop) {
plop.setActionType("createExercise", async function (answers) {
const { exerciseName } = answers;
if (!exerciseName) {
throw new Error(
`Invalid exerciseName. Expected: valid string. Actual: "${exerciseName}"`
);
}
const camelExerciseName = camelCase(exerciseName);
const exerciseDirectoryName = await createExerciseDirectoryName(
camelExerciseName
);
const basePath = join("./", exerciseDirectoryName);
const solutionPath = join(basePath, "solution");
await mkdir(basePath);
await mkdir(solutionPath);
await writeReadme(basePath);
await writeExercise(basePath);
await writeExercise(solutionPath);
await writeExerciseSpec(basePath);
await writeExerciseSpec(solutionPath);
});
plop.setGenerator("Basic", {
description: "Create a basic JavaScript exercise.",
prompts: [
{
type: "input",
name: "exerciseName",
message: "What is the name of the exercise? (camelCase)",
},
],
actions: [{ type: "createExercise" }],
});
};