Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21af0c8

Browse files
committed
update hooks/actions docs
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent5de0214 commit21af0c8

File tree

2 files changed

+108
-12
lines changed

2 files changed

+108
-12
lines changed

‎docs/docs/hooks-actions.md

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,108 @@ title: Hooks & Actions
44
sidebar_label:Hooks & Actions
55
---
66

7-
To make a functional tutorial, tutorial creators need a bit more control over what can be run and when. For example, a test runner wouldn't really work if the package dependencies for that test runner weren't installed.
7+
To make a functional tutorial, tutorial creators need a bit more control over what can be run and when.
88

9-
An action is a piece of functionality that can be run. These include:
10-
11-
-`commands` - a list of cli commands to run. For example, "npm install"
12-
-`vscodeCommands` - a list of vscode API commands to run. For example, "setLayout" to change the layout of windows
13-
-`watchers` - a list of files to listen to. If a file changes, the test runner will run automatically
14-
-`files` - a list of files to open in the users workspace to drive the users attention.
15-
-`subtasks` - a task made up of multiple other tests where all must pass to continue
16-
-`filter` - a regex passed into the test runner to limit the tests returned
9+
##Hooks
1710

18-
A hook in CodeRoad is a place where a tutorialcreatorcan tap in to run an action. Hooks include:
11+
A hook in CodeRoad is a place where a tutorial can tap in to run an action. Hooks include:
1912

2013
-`config.setup` - when the tutorial setup. This is a great place to setup your test runner.
21-
-`task.setup` - when a task is started
22-
-`task.solution` - when a solution is loaded from a reset
14+
-`step.setup` - when a task is started
15+
-`step.solution` - when a solution is loaded from a reset
2316

2417
Hooks and actions combine to provide a flexible environment for tutorial development.
18+
19+
To see which hooks run where, consult[the hooks list in the codebase](https://github.com/coderoad/coderoad-vscode/blob/master/src/services/hooks/index.ts).
20+
21+
##Actions
22+
23+
An action is a piece of functionality that can be run. These include:
24+
25+
###`commands` (string[])
26+
27+
A list of cli commands to run. For example, "npm install"
28+
29+
```yaml
30+
setup:
31+
commands:
32+
-'npm install'
33+
```
34+
35+
In the example above,`npm install` will run in the root of the workspace.
36+
37+
### `vscodeCommands` (string[] | [command: string, params: any][])
38+
39+
A list of vscode API commands to run. Commands may be a single string, or an array with the command, and params.
40+
41+
```yaml
42+
setup:
43+
vscodeCommands:
44+
- 'workbench.action.terminal.toggleTerminal' # toggle terminal
45+
- [
46+
'setEditorLayout',
47+
{ orientation: 0, groups: [{ groups: [{}, {}], size: 0.5 }, { groups: [{}, {}], size: 0.5 }] },
48+
] # set the orientation of windows and sizes
49+
```
50+
51+
For example, "toggleTerminal" toggles the terminal, while "setLayout" changes the layout of windows.
52+
53+
There are a number of options in the VSCode API. More info at:
54+
55+
-[vscode commands API](https://code.visualstudio.com/api/references/vscode-api#commands)
56+
-[commands with params](https://code.visualstudio.com/api/references/commands)
57+
-[commands without params](https://code.visualstudio.com/docs/getstarted/keybindings)
58+
59+
### `watchers` (string[])
60+
61+
A list of files globs to listen to. If a file changes that matches the pattern, the test runner will run automatically.
62+
63+
```yaml
64+
setup:
65+
watchers:
66+
- 'package.json'
67+
- 'node_modules/express'
68+
```
69+
70+
The example above will run tests if the `package.json` file changes, or if there is a change in `node_modules/express`. This is a good way to run tests if a package is installed.
71+
72+
Note that watchers are throttled to run no more than once per second.
73+
74+
Read more about [glob patterns](https://code.visualstudio.com/api/references/vscode-api#GlobPattern).
75+
76+
### `files` (string[])
77+
78+
A list of files to open in the users workspace to drive the users attention.
79+
80+
```yaml
81+
setup:
82+
files:
83+
- 'README.md'
84+
```
85+
86+
The above example will open the "README.md" file in the users workspace. Note that file paths are relative to the workspace root.
87+
88+
### `filter` (string)
89+
90+
A regex passed into the test runner to limit the tests returned
91+
92+
```yaml
93+
setup:
94+
filter: 'level_1_tests'
95+
```
96+
97+
Will restrict tests to only run a subset of tests that match the filter. Filter depends on your test runner, and can be configured in the test runner.
98+
99+
```yaml
100+
config:
101+
testRunner:
102+
command: ./node_modules/.bin/mocha
103+
args:
104+
filter": --grep
105+
```
106+
107+
Essentially, the above example will run `./node_modules/.bin/mocha --grep level_1_tests` as the test command.
108+
109+
### `subtasks` (boolean)
110+
111+
A task made up of multiple other tests where all must pass to continue

‎src/services/hooks/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ import { onError as telemetryOnError } from '../telemetry'
99
import{runTest}from'../../actions/onTest'
1010
importloggerfrom'../logger'
1111

12+
// run at the end of when a tutorial is configured
1213
exportconstonInit=async(actions:TT.StepActions):Promise<void>=>{
1314
awaitloadCommits(actions?.commits)
1415
awaitrunCommands(actions?.commands)
1516
awaitrunVSCodeCommands(actions?.vscodeCommands)
1617
}
1718

19+
// run when a level starts
1820
exportconstonLevelEnter=async(actions:TT.StepActions):Promise<void>=>{
1921
awaitloadCommits(actions?.commits)
2022
awaitrunCommands(actions?.commands)
2123
}
2224

25+
// run when a step starts
2326
exportconstonSetupEnter=async(actions:TT.StepActions):Promise<void>=>{
2427
awaitloadCommits(actions?.commits)
2528
awaitopenFiles(actions?.files)
@@ -28,6 +31,7 @@ export const onSetupEnter = async (actions: TT.StepActions): Promise<void> => {
2831
awaitrunVSCodeCommands(actions?.vscodeCommands)
2932
}
3033

34+
// run when a step solution starts
3135
exportconstonSolutionEnter=async(actions:TT.StepActions):Promise<void>=>{
3236
awaitgit.clear()
3337
awaitloadCommits(actions?.commits)
@@ -37,25 +41,30 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise<void> =>
3741
awaitrunTest()
3842
}
3943

44+
// run when "reset" is triggered
4045
exportconstonReset=async(actions:TT.StepActions):Promise<void>=>{
4146
awaitresetWatchers()
4247
awaitrunCommands(actions?.commands)
4348
awaitrunVSCodeCommands(actions?.vscodeCommands)
4449
}
4550

51+
// run when an uncaught exception is thrown
4652
exportconstonError=async(error:Error):Promise<void>=>{
4753
telemetryOnError(error)
4854
}
4955

56+
// run when a step task passes
5057
exportconstonStepComplete=async({ levelId, stepId}:{levelId:string;stepId:string}):Promise<void>=>{
5158
git.saveCommit(`Save progress:${stepId}`)
5259
logger(`ON STEP COMPLETE:${JSON.stringify({ levelId, stepId})}`)
5360
}
5461

62+
// run when a level is complete (all tasks pass or no tasks)
5563
exportconstonLevelComplete=async({ levelId}:{levelId:string}):Promise<void>=>{
5664
logger(`ON LEVEL COMPLETE:${JSON.stringify(levelId)}`)
5765
}
5866

67+
// run when all levels are complete
5968
exportconstonTutorialComplete=async({ tutorialId}:{tutorialId:string}):Promise<void>=>{
6069
logger(`ON TUTORIAL COMPLETE:${JSON.stringify(tutorialId)}`)
6170
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp