Skip to content

Commit 94f483b

Browse files
authored
add onContinue hook (#561)
* add onContinue hook Signed-off-by: shmck <shawn.j.mckay@gmail.com> * cleanup typo Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent 122bd53 commit 94f483b

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to the "coderoad-vscode" extension will be documented in thi
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
# [0.19.0]
8+
9+
- Add the ability to run scripts on continue to address an issue where continued tutorials weren't configured correctly.
10+
- adds a "continue" webhook
11+
- adds a `tutorial.config.continue` that lets you run `commands` or `vscodeCommands`
12+
713
## [0.18.0]
814

915
- Improved error logging in output channel "CodeRoad (Logs)"
@@ -18,10 +24,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1824

1925
## [0.17.0]
2026

21-
- auto-launch a continued tutorial
27+
- Auto-launch a continued tutorial
2228
## [0.16.0]
2329

24-
- add support for writing session state to a file. This is useful in multi-container environments where local storage is not necessarily preserved across sessions.
30+
- Add support for writing session state to a file. This is useful in multi-container environments where local storage is not necessarily preserved across sessions.
2531

2632
## [0.15.1]
2733

src/actions/onTutorialConfigContinue.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import tutorialConfig from './utils/tutorialConfig'
66
import { COMMANDS, send } from '../commands'
77
import logger from '../services/logger'
88
import { setupWebhook } from '../services/hooks/webhooks'
9+
import * as hooks from '../services/hooks'
910

1011
const onTutorialConfigContinue = async (action: T.Action, context: Context): Promise<void> => {
1112
try {
@@ -25,6 +26,15 @@ const onTutorialConfigContinue = async (action: T.Action, context: Context): Pro
2526
if (tutorialToContinue.config?.webhook) {
2627
setupWebhook(tutorialToContinue.config.webhook)
2728
}
29+
30+
// if tutorial.config.reset.command, run it
31+
const continueActions = tutorialToContinue?.config?.continue
32+
if (continueActions) {
33+
hooks.onContinue(
34+
{ commands: continueActions?.commands, vscodeCommands: continueActions?.vscodeCommands },
35+
tutorialToContinue?.id as string,
36+
)
37+
}
2838
} catch (e: any) {
2939
const error = {
3040
type: 'UnknownError',

src/services/hooks/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ export const onReset = async (actions: TT.StepActions, tutorialId: string): Prom
5656
})
5757
}
5858

59+
// run when a tutorial is continued
60+
export const onContinue = async (actions: TT.StepActions, tutorialId: string): Promise<void> => {
61+
await runCommands(actions?.commands)
62+
await runVSCodeCommands(actions?.vscodeCommands)
63+
webhooks.onContinue({
64+
tutorialId,
65+
})
66+
}
67+
5968
// run when an uncaught exception is thrown
6069
export const onError = async (error: Error): Promise<void> => {
6170
telemetry.onError(error)

src/services/hooks/webhooks.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WEBHOOK_TOKEN } from '../../environment'
66
const WEBHOOK_EVENTS = {
77
init: false,
88
reset: false,
9+
continue: false,
910
step_complete: false,
1011
level_complete: false,
1112
tutorial_complete: false,
@@ -76,6 +77,16 @@ export const onReset = (event: WebhookEventReset): void => {
7677
}
7778
}
7879

80+
type WebhookEventContinue = {
81+
tutorialId: string
82+
}
83+
84+
export const onContinue = (event: WebhookEventReset): void => {
85+
if (WEBHOOK_EVENTS.continue) {
86+
callWebhookEndpoint<WebhookEventContinue>(event)
87+
}
88+
}
89+
7990
type WebhookEventStepComplete = { tutorialId: string; version?: string; levelId: string; stepId: string }
8091

8192
export const onStepComplete = (event: WebhookEventStepComplete): void => {

typings/tutorial.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ProgressStatus } from './index'
22

33
export type Maybe<T> = T | null
44

5-
export type ConfigReset = {
5+
export type ConfigCommands = {
66
commands?: string[]
77
vscodeCommands?: VSCodeCommand[]
88
}
@@ -13,7 +13,8 @@ export type TutorialConfig = {
1313
repo: TutorialRepo
1414
dependencies?: TutorialDependency[]
1515
setup?: StepActions
16-
reset?: ConfigReset
16+
continue?: ConfigCommands
17+
reset?: ConfigCommands
1718
webhook?: WebhookConfig
1819
}
1920

@@ -97,6 +98,7 @@ export type VSCodeCommand = string | [string, any]
9798
export interface WebhookConfigEvents {
9899
init?: boolean
99100
reset?: boolean
101+
continue?: boolean
100102
step_complete?: boolean
101103
level_complete?: boolean
102104
tutorial_complete?: boolean

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy