@@ -2,19 +2,18 @@ import * as T from 'typings'
22import * as TT from 'typings/tutorial'
33import * as E from 'typings/error'
44import * as vscode from 'vscode'
5- import { satisfies } from 'semver'
65import { setupActions , solutionActions } from './actions/setupActions'
7- import tutorialConfig from './actions/tutorialConfig'
6+ import tutorialConfig from './actions/utils/ tutorialConfig'
87import { COMMANDS } from './commands'
98import Context from './services/context/context'
109import logger from './services/logger'
11- import { version , compareVersions } from './services/dependencies'
10+ import { version } from './services/dependencies'
1211import { openWorkspace , checkWorkspaceEmpty } from './services/workspace'
1312import { showOutput } from './services/testRunner/output'
1413import { exec } from './services/node'
1514import reset from './services/reset'
1615import getLastCommitHash from './services/reset/lastHash'
17- import { onEvent } from './services/telemetry'
16+
1817import * as actions from './actions'
1918
2019interface Channel {
@@ -58,114 +57,7 @@ class Channel implements Channel {
5857 return
5958 // configure test runner, language, git
6059 case 'EDITOR_TUTORIAL_CONFIG' :
61- try {
62- const data : TT . Tutorial = action . payload . tutorial
63-
64- onEvent ( 'tutorial_start' , {
65- tutorial_id : data . id ,
66- tutorial_version : data . version ,
67- tutorial_title : data . summary . title ,
68- } )
69-
70- // validate extension version
71- const expectedAppVersion = data . config ?. appVersions ?. vscode
72- if ( expectedAppVersion ) {
73- const extension = vscode . extensions . getExtension ( 'coderoad.coderoad' )
74- if ( extension ) {
75- const currentAppVersion = extension . packageJSON . version
76- const satisfied = satisfies ( currentAppVersion , expectedAppVersion )
77- if ( ! satisfied ) {
78- const error : E . ErrorMessage = {
79- type : 'UnmetExtensionVersion' ,
80- message : `Expected CodeRoad v${ expectedAppVersion } , but found v${ currentAppVersion } ` ,
81- }
82- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
83- return
84- }
85- }
86- }
87-
88- // setup tutorial config (save watcher, test runner, etc)
89- await this . context . setTutorial ( this . workspaceState , data )
90-
91- // validate dependencies
92- const dependencies = data . config . dependencies
93- if ( dependencies && dependencies . length ) {
94- for ( const dep of dependencies ) {
95- // check dependency is installed
96- const currentVersion : string | null = await version ( dep . name )
97- if ( ! currentVersion ) {
98- // use a custom error message
99- const error : E . ErrorMessage = {
100- type : 'MissingTutorialDependency' ,
101- message :
102- dep . message || `Process "${ dep . name } " is required but not found. It may need to be installed` ,
103- actions : [
104- {
105- label : 'Check Again' ,
106- transition : 'TRY_AGAIN' ,
107- } ,
108- ] ,
109- }
110- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
111- return
112- }
113-
114- // check dependency version
115- const satisfiedDependency = await compareVersions ( currentVersion , dep . version )
116-
117- if ( ! satisfiedDependency ) {
118- const error : E . ErrorMessage = {
119- type : 'UnmetTutorialDependency' ,
120- message : `Expected ${ dep . name } to have version ${ dep . version } , but found version ${ currentVersion } ` ,
121- actions : [
122- {
123- label : 'Check Again' ,
124- transition : 'TRY_AGAIN' ,
125- } ,
126- ] ,
127- }
128- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
129- return
130- }
131-
132- if ( satisfiedDependency !== true ) {
133- const error : E . ErrorMessage = satisfiedDependency || {
134- type : 'UnknownError' ,
135- message : `Something went wrong comparing dependency for ${ name } ` ,
136- actions : [
137- {
138- label : 'Try Again' ,
139- transition : 'TRY_AGAIN' ,
140- } ,
141- ] ,
142- }
143- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
144- return
145- }
146- }
147- }
148-
149- const error : E . ErrorMessage | void = await tutorialConfig ( { data } ) . catch ( ( error : Error ) => ( {
150- type : 'UnknownError' ,
151- message : `Location: tutorial config.\n\n${ error . message } ` ,
152- } ) )
153-
154- // has error
155- if ( error && error . type ) {
156- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
157- return
158- }
159-
160- // report back to the webview that setup is complete
161- this . send ( { type : 'TUTORIAL_CONFIGURED' } )
162- } catch ( e ) {
163- const error = {
164- type : 'UnknownError' ,
165- message : `Location: EditorTutorialConfig.\n\n ${ e . message } ` ,
166- }
167- this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
168- }
60+ actions . onTutorialConfig ( action , this . context , this . workspaceState , this . send )
16961 return
17062 case 'EDITOR_TUTORIAL_CONTINUE_CONFIG' :
17163 try {
0 commit comments