(action: T.Action, context: Context)
| 11 | import { setupWebhook } from '../services/hooks/webhooks' |
| 12 | |
| 13 | const onTutorialConfigNew = async (action: T.Action, context: Context): Promise<void> => { |
| 14 | try { |
| 15 | const data: TT.Tutorial = action.payload.tutorial |
| 16 | |
| 17 | onEvent('tutorial_start', { |
| 18 | tutorialId: data.id, |
| 19 | tutorialVersion: data.version, |
| 20 | tutorialTitle: data.summary.title, |
| 21 | }) |
| 22 | |
| 23 | // validate extension version |
| 24 | const expectedAppVersion = data.config?.appVersions?.vscode |
| 25 | if (expectedAppVersion) { |
| 26 | const extension = vscode.extensions.getExtension('coderoad.coderoad') |
| 27 | if (extension) { |
| 28 | const currentAppVersion = extension.packageJSON.version |
| 29 | const satisfied = satisfies(currentAppVersion, expectedAppVersion) |
| 30 | if (!satisfied) { |
| 31 | const error: E.ErrorMessage = { |
| 32 | type: 'UnmetExtensionVersion', |
| 33 | message: `Expected CodeRoad v${expectedAppVersion}, but found v${currentAppVersion}`, |
| 34 | } |
| 35 | send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } }) |
| 36 | return |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // setup tutorial config (save watcher, test runner, etc) |
| 42 | await context.onNew(data) |
| 43 | |
| 44 | // validate dependencies |
| 45 | const dependencies = data.config.dependencies |
| 46 | if (dependencies && dependencies.length) { |
| 47 | for (const dep of dependencies) { |
| 48 | // check dependency is installed |
| 49 | const { version, error: gitError } = await getVersion(dep.name) |
| 50 | if (gitError) { |
| 51 | // git config issue |
| 52 | const error: E.ErrorMessage = { |
| 53 | type: 'GitConfigError', |
| 54 | message: gitError.message, |
| 55 | actions: [ |
| 56 | { |
| 57 | label: 'Check Again', |
| 58 | transition: 'TRY_AGAIN', |
| 59 | }, |
| 60 | ], |
| 61 | } |
| 62 | send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } }) |
| 63 | return |
| 64 | } |
| 65 | if (!version) { |
| 66 | // use a custom error message |
| 67 | const error: E.ErrorMessage = { |
| 68 | type: 'MissingTutorialDependency', |
| 69 | message: dep.message || `Process "${dep.name}" is required but not found. It may need to be installed`, |
| 70 | actions: [ |
nothing calls this directly
no test coverage detected