forked from total-typescript/beginners-typescript-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-stackblitz.js
More file actions
29 lines (23 loc) · 969 Bytes
/
prepare-stackblitz.js
File metadata and controls
29 lines (23 loc) · 969 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
26
27
28
29
const fs = require("fs");
const path = require("path");
/**
* Adds a bunch of scripts, like e-01, e-02 to package.json
* so that StackBlitz can run them programmatically via URL
* commands
*/
const packageJsonPath = path.resolve(__dirname, "../package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const exercises = fs.readdirSync(path.resolve(__dirname, "../src"));
const exerciseFiles = exercises.filter((exercise) =>
exercise.includes(".problem."),
);
const exerciseNames = exerciseFiles.map((exercise) => exercise.split("-")[0]);
const newPackageJson = Object.assign({}, packageJson);
newPackageJson.scripts = {
...packageJson.scripts,
};
exerciseNames.forEach((exercise) => {
newPackageJson.scripts[`e-${exercise}`] = `npm run exercise -- ${exercise}`;
newPackageJson.scripts[`s-${exercise}`] = `npm run solution -- ${exercise}`;
});
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJson, null, 2));