@@ -2,19 +2,18 @@ import * as T from 'typings'
2
2
import * as TT from 'typings/tutorial'
3
3
import * as E from 'typings/error'
4
4
import * as vscode from 'vscode'
5
- import { satisfies } from 'semver'
6
5
import { setupActions , solutionActions } from './actions/setupActions'
7
- import tutorialConfig from './actions/tutorialConfig'
6
+ import tutorialConfig from './actions/utils/ tutorialConfig'
8
7
import { COMMANDS } from './commands'
9
8
import Context from './services/context/context'
10
9
import logger from './services/logger'
11
- import { version , compareVersions } from './services/dependencies'
10
+ import { version } from './services/dependencies'
12
11
import { openWorkspace , checkWorkspaceEmpty } from './services/workspace'
13
12
import { showOutput } from './services/testRunner/output'
14
13
import { exec } from './services/node'
15
14
import reset from './services/reset'
16
15
import getLastCommitHash from './services/reset/lastHash'
17
- import { onEvent } from './services/telemetry'
16
+
18
17
import * as actions from './actions'
19
18
20
19
interface Channel {
@@ -58,114 +57,7 @@ class Channel implements Channel {
58
57
return
59
58
// configure test runner, language, git
60
59
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 )
169
61
return
170
62
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG' :
171
63
try {