-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathFileSystemTutorialContentProvider.ts
More file actions
47 lines (40 loc) · 1.2 KB
/
FileSystemTutorialContentProvider.ts
File metadata and controls
47 lines (40 loc) · 1.2 KB
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
import type {
RawTutorialContent,
TutorialContentProvider,
TutorialId,
} from "@cursorless/common";
import { readFile, readdir } from "node:fs/promises";
import path from "path";
import { loadFixture } from "./loadFixture";
export class FileSystemTutorialContentProvider implements TutorialContentProvider {
private tutorialRootDir: string;
constructor(assetsRoot: string) {
this.tutorialRootDir = path.join(assetsRoot, "tutorial");
}
async loadRawTutorials() {
const tutorialDirs = await readdir(this.tutorialRootDir, {
withFileTypes: true,
});
return await Promise.all(
tutorialDirs
.filter((dirent) => dirent.isDirectory())
.map((dirent) => this.loadTutorialScript(dirent.name as TutorialId)),
);
}
private async loadTutorialScript(
tutorialId: string,
): Promise<RawTutorialContent> {
const buffer = await readFile(
path.join(this.tutorialRootDir, tutorialId, "script.json"),
);
return {
id: tutorialId,
...JSON.parse(buffer.toString()),
};
}
async loadFixture(tutorialId: TutorialId, fixtureName: string) {
return loadFixture(
path.join(this.tutorialRootDir, tutorialId, fixtureName),
);
}
}