@@ -9,11 +9,12 @@ import tutorialConfig from '../actions/tutorialConfig'
99import { COMMANDS } from '../editor/commands'
1010import logger from '../services/logger'
1111import Context from './context'
12- import { version } from '../services/dependencies'
12+ import { version , compareVersions } from '../services/dependencies'
1313import { openWorkspace , checkWorkspaceEmpty } from '../services/workspace'
1414import { readFile } from 'fs'
1515import { join } from 'path'
1616import { promisify } from 'util'
17+ import { compare } from 'semver'
1718
1819const readFileAsync = promisify ( readFile )
1920
@@ -95,6 +96,53 @@ class Channel implements Channel {
9596 await this . context . setTutorial ( this . workspaceState , data )
9697
9798 // validate dependencies
99+ if ( data . config . dependencies ) {
100+ for ( const dep of data . config . dependencies ) {
101+ // check dependency is installed
102+ const currentVersion : string | null = await version ( name )
103+ if ( ! currentVersion ) {
104+ // use a custom error message
105+ const error = {
106+ type : 'MissingTutorialDependency' ,
107+ message : dep . message || `Process ${ name } is required but not found. It may need to be installed` ,
108+ actions : [
109+ {
110+ label : 'Check Again' ,
111+ transition : 'TRY_AGAIN' ,
112+ } ,
113+ ] ,
114+ }
115+ this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
116+ return
117+ }
118+
119+ // check dependency version
120+ const satisfiedDependency = await compareVersions ( currentVersion , dep . version ) . catch ( ( error : Error ) => ( {
121+ type : 'UnmetTutorialDependency' ,
122+ message : error . message ,
123+ actions : [
124+ {
125+ label : 'Check Again' ,
126+ transition : 'TRY_AGAIN' ,
127+ } ,
128+ ] ,
129+ } ) )
130+ if ( satisfiedDependency !== true ) {
131+ const error = satisfiedDependency || {
132+ type : 'UnknownError' ,
133+ message : `Something went wrong comparing dependency for ${ name } ` ,
134+ actions : [
135+ {
136+ label : 'Try Again' ,
137+ transition : 'TRY_AGAIN' ,
138+ } ,
139+ ] ,
140+ }
141+ this . send ( { type : 'TUTORIAL_CONFIGURE_FAIL' , payload : { error } } )
142+ return
143+ }
144+ }
145+ }
98146
99147 const error : E . ErrorMessage | void = await tutorialConfig ( { config : data . config } ) . catch ( ( error : Error ) => ( {
100148 type : 'UnknownError' ,
0 commit comments