diff --git a/src/actions/onRunReset.ts b/src/actions/onRunReset.ts index a791a979..47c2d8a7 100644 --- a/src/actions/onRunReset.ts +++ b/src/actions/onRunReset.ts @@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial' import Context from '../services/context/context' import { exec } from '../services/node' import reset from '../services/reset' +import * as hooks from '../services/hooks' import getCommitHashByPosition from '../services/reset/lastHash' type ResetAction = { @@ -30,8 +31,9 @@ const onRunReset = async (action: ResetAction, context: Context): Promise reset({ branch, hash }) // if tutorial.config.reset.command, run it - if (tutorial?.config?.reset?.command) { - await exec({ command: tutorial.config.reset.command }) + const resetActions = tutorial?.config?.reset + if (resetActions) { + hooks.onReset({ commands: resetActions?.commands, vscodeCommands: resetActions?.vscodeCommands }) } } diff --git a/src/commands.ts b/src/commands.ts index f5756696..84f52327 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -3,8 +3,8 @@ import * as TT from 'typings/tutorial' import * as vscode from 'vscode' import createTestRunner from './services/testRunner' import createWebView from './services/webview' -import logger from './services/logger' import * as hooks from './services/hooks' +import logger from './services/logger' export const COMMANDS = { START: 'coderoad.start', diff --git a/src/services/hooks/index.ts b/src/services/hooks/index.ts index 95f5b5de..263539af 100644 --- a/src/services/hooks/index.ts +++ b/src/services/hooks/index.ts @@ -38,6 +38,11 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise => await onRunTest() } +export const onReset = async (actions: TT.StepActions): Promise => { + await runCommands(actions?.commands) + await runVSCodeCommands(actions?.vscodeCommands) +} + export const onError = async (error: Error): Promise => { telemetryOnError(error) } diff --git a/src/services/hooks/utils/loadCommits.ts b/src/services/hooks/utils/loadCommits.ts index 8b134eef..f65b4545 100644 --- a/src/services/hooks/utils/loadCommits.ts +++ b/src/services/hooks/utils/loadCommits.ts @@ -1,7 +1,7 @@ import * as git from '../../git' -const loadCommits = async (commits: string[]): Promise => { - if (commits) { +const loadCommits = async (commits: string[] = []): Promise => { + if (commits && commits.length) { // load the current list of commits for validation for (const commit of commits) { await git.loadCommit(commit) diff --git a/src/services/reset/lastHash.ts b/src/services/reset/lastHash.ts index 34b6337a..723d2819 100644 --- a/src/services/reset/lastHash.ts +++ b/src/services/reset/lastHash.ts @@ -41,7 +41,7 @@ const getLastCommitHash = (position: T.Position, tutorial: TT.Tutorial | null): if (!step) { throw new Error(`No step found matching ${stepId}`) } - const commits = step.setup.commits + const commits = step.setup?.commits || [] if (!commits.length) { throw new Error(`No commits found on step ${stepId}`) } diff --git a/typings/tutorial.d.ts b/typings/tutorial.d.ts index aaa357bb..3f45e558 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -3,7 +3,8 @@ import { ProgressStatus } from './index' export type Maybe = T | null export type ConfigReset = { - command?: string + commands?: string[] + vscodeCommands?: VSCodeCommand[] } export type TutorialConfig = { @@ -57,7 +58,7 @@ export type TutorialSummary = { export type StepActions = { commands?: string[] - commits: string[] + commits?: string[] files?: string[] watchers?: string[] filter?: string