From d652457e7bc02d20f28d6fcec4d2ebd0e3e530a4 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 2 Aug 2020 16:46:55 -0700 Subject: [PATCH 1/2] support multiple reset commands Signed-off-by: shmck --- src/actions/onRunReset.ts | 6 +++++- src/commands.ts | 2 +- src/services/hooks/index.ts | 4 ++++ typings/tutorial.d.ts | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/actions/onRunReset.ts b/src/actions/onRunReset.ts index a791a979..5d5748ca 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 = { @@ -29,9 +30,12 @@ const onRunReset = async (action: ResetAction, context: Context): Promise // load timeline until last pass commit reset({ branch, hash }) + // TODO: @deprecate command in favor of commands // if tutorial.config.reset.command, run it if (tutorial?.config?.reset?.command) { - await exec({ command: tutorial.config.reset.command }) + hooks.onReset([tutorial?.config?.reset?.command]) + } else if (tutorial?.config?.reset?.commands) { + hooks.onReset(tutorial?.config?.reset?.commands) } } 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..34167b33 100644 --- a/src/services/hooks/index.ts +++ b/src/services/hooks/index.ts @@ -38,6 +38,10 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise => await onRunTest() } +export const onReset = async (commands: string[]): Promise => { + await runCommands(commands) +} + export const onError = async (error: Error): Promise => { telemetryOnError(error) } diff --git a/typings/tutorial.d.ts b/typings/tutorial.d.ts index aaa357bb..1b22f888 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -4,6 +4,7 @@ export type Maybe = T | null export type ConfigReset = { command?: string + commands?: string[] } export type TutorialConfig = { From fc384778abd2c9dd148dc905bac1cf417bddbeb2 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 2 Aug 2020 16:54:23 -0700 Subject: [PATCH 2/2] allow vscode commands with reset Signed-off-by: shmck --- src/actions/onRunReset.ts | 8 +++----- src/services/hooks/index.ts | 5 +++-- src/services/hooks/utils/loadCommits.ts | 4 ++-- src/services/reset/lastHash.ts | 2 +- typings/tutorial.d.ts | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/actions/onRunReset.ts b/src/actions/onRunReset.ts index 5d5748ca..47c2d8a7 100644 --- a/src/actions/onRunReset.ts +++ b/src/actions/onRunReset.ts @@ -30,12 +30,10 @@ const onRunReset = async (action: ResetAction, context: Context): Promise // load timeline until last pass commit reset({ branch, hash }) - // TODO: @deprecate command in favor of commands // if tutorial.config.reset.command, run it - if (tutorial?.config?.reset?.command) { - hooks.onReset([tutorial?.config?.reset?.command]) - } else if (tutorial?.config?.reset?.commands) { - hooks.onReset(tutorial?.config?.reset?.commands) + const resetActions = tutorial?.config?.reset + if (resetActions) { + hooks.onReset({ commands: resetActions?.commands, vscodeCommands: resetActions?.vscodeCommands }) } } diff --git a/src/services/hooks/index.ts b/src/services/hooks/index.ts index 34167b33..263539af 100644 --- a/src/services/hooks/index.ts +++ b/src/services/hooks/index.ts @@ -38,8 +38,9 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise => await onRunTest() } -export const onReset = async (commands: string[]): Promise => { - await runCommands(commands) +export const onReset = async (actions: TT.StepActions): Promise => { + await runCommands(actions?.commands) + await runVSCodeCommands(actions?.vscodeCommands) } export const onError = async (error: Error): Promise => { 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 1b22f888..3f45e558 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -3,8 +3,8 @@ import { ProgressStatus } from './index' export type Maybe = T | null export type ConfigReset = { - command?: string commands?: string[] + vscodeCommands?: VSCodeCommand[] } export type TutorialConfig = { @@ -58,7 +58,7 @@ export type TutorialSummary = { export type StepActions = { commands?: string[] - commits: string[] + commits?: string[] files?: string[] watchers?: string[] filter?: string