66 ReadOnlyHatMap ,
77 ScopeType ,
88 TextEditor ,
9+ TutorialContentProvider ,
910 TutorialId ,
1011 TutorialInfo ,
1112 TutorialState ,
@@ -16,22 +17,18 @@ import {
1617} from "@cursorless/common" ;
1718import { produce } from "immer" ;
1819import { isEqual } from "lodash-es" ;
19- import { readdir } from "node:fs/promises" ;
20- import path from "path" ;
2120import { CommandRunner } from "../CommandRunner" ;
2221import { CommandRunnerDecorator } from "../api/CursorlessEngineApi" ;
2322import { Tutorial , TutorialContent , TutorialStep } from "../api/Tutorial" ;
23+ import { Debouncer } from "../core/Debouncer" ;
2424import { CustomSpokenFormGeneratorImpl } from "../generateSpokenForm/CustomSpokenFormGeneratorImpl" ;
2525import { ide } from "../singletons/ide.singleton" ;
26- import { Debouncer } from "../core/Debouncer" ;
2726import { TutorialError } from "./TutorialError" ;
2827import { TutorialScriptParser } from "./TutorialScriptParser" ;
29- import { loadTutorialScript } from "./loadTutorialScript" ;
3028
3129const HIGHLIGHT_COLOR = "highlight0" ;
3230
3331export class TutorialImpl implements Tutorial , CommandRunnerDecorator {
34- private tutorialRootDir : string ;
3532 private editor ?: TextEditor ;
3633 private state_ : TutorialState = { type : "loading" } ;
3734 private notifier : Notifier < [ TutorialState ] > = new Notifier ( ) ;
@@ -42,13 +39,12 @@ export class TutorialImpl implements Tutorial, CommandRunnerDecorator {
4239 constructor (
4340 private hatTokenMap : HatTokenMap ,
4441 private customSpokenFormGenerator : CustomSpokenFormGeneratorImpl ,
42+ private contentProvider : TutorialContentProvider ,
4543 ) {
4644 this . setupStep = this . setupStep . bind ( this ) ;
4745 this . reparseCurrentTutorial = this . reparseCurrentTutorial . bind ( this ) ;
4846 const debouncer = new Debouncer ( ( ) => this . checkPreconditions ( ) , 100 ) ;
4947
50- this . tutorialRootDir = path . join ( ide ( ) . assetsRoot , "tutorial" ) ;
51-
5248 this . loadTutorialList ( ) ;
5349
5450 this . disposables . push (
@@ -85,30 +81,16 @@ export class TutorialImpl implements Tutorial, CommandRunnerDecorator {
8581 }
8682
8783 async loadTutorialList ( ) {
88- const tutorialDirs = await readdir ( this . tutorialRootDir , {
89- withFileTypes : true ,
90- } ) ;
91-
9284 const tutorialProgress = ide ( ) . globalState . get ( "tutorialProgress" ) ;
9385
94- this . tutorials = await Promise . all (
95- tutorialDirs
96- . filter ( ( dirent ) => dirent . isDirectory ( ) )
97- . map ( async ( dirent ) => {
98- const tutorialId = dirent . name as TutorialId ;
99- const rawContent = await loadTutorialScript (
100- this . tutorialRootDir ,
101- tutorialId ,
102- ) ;
103-
104- return {
105- id : tutorialId ,
106- title : rawContent . title ,
107- version : rawContent . version ,
108- stepCount : rawContent . steps . length ,
109- currentStep : tutorialProgress [ tutorialId ] ?. currentStep ?? 0 ,
110- } ;
111- } ) ,
86+ this . tutorials = ( await this . contentProvider . getRawTutorials ( ) ) . map (
87+ ( rawContent ) => ( {
88+ id : rawContent . id ,
89+ title : rawContent . title ,
90+ version : rawContent . version ,
91+ stepCount : rawContent . steps . length ,
92+ currentStep : tutorialProgress [ rawContent . id ] ?. currentStep ?? 0 ,
93+ } ) ,
11294 ) ;
11395
11496 this . setState ( {
@@ -163,13 +145,11 @@ export class TutorialImpl implements Tutorial, CommandRunnerDecorator {
163145
164146 const tutorialId = this . state_ . id ;
165147
166- const rawContent = await loadTutorialScript (
167- this . tutorialRootDir ,
168- tutorialId ,
169- ) ;
148+ const rawContent =
149+ await this . contentProvider . loadTutorialScript ( tutorialId ) ;
170150
171151 const parser = new TutorialScriptParser (
172- this . tutorialRootDir ,
152+ this . contentProvider ,
173153 tutorialId ,
174154 this . customSpokenFormGenerator ,
175155 ) ;
@@ -207,13 +187,11 @@ export class TutorialImpl implements Tutorial, CommandRunnerDecorator {
207187 tutorialId = this . tutorials [ tutorialId ] . id ;
208188 }
209189
210- const rawContent = await loadTutorialScript (
211- this . tutorialRootDir ,
212- tutorialId ,
213- ) ;
190+ const rawContent =
191+ await this . contentProvider . loadTutorialScript ( tutorialId ) ;
214192
215193 const parser = new TutorialScriptParser (
216- this . tutorialRootDir ,
194+ this . contentProvider ,
217195 tutorialId ,
218196 this . customSpokenFormGenerator ,
219197 ) ;
0 commit comments