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

Commitd3cd169

Browse files
committed
breaking - init setup actions moved in config
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent50b2719 commitd3cd169

File tree

13 files changed

+93
-101
lines changed

13 files changed

+93
-101
lines changed

‎src/actions/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ export { default as onValidateSetup } from './onValidateSetup'
55
export{defaultasonRunReset}from'./onRunReset'
66
export{defaultasonErrorPage}from'./onErrorPage'
77
export{onRunTest,onTestPass}from'./onTest'
8-
export{onSetupActions,onSolutionActions}from'./onActions'
98
export{onOpenLogs}from'./onOpenLogs'

‎src/actions/onActions.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎src/channel.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Context from './services/context/context'
55
importloggerfrom'./services/logger'
66
import{openWorkspace}from'./services/workspace'
77
import*asactionsfrom'./actions'
8+
import*ashooksfrom'./services/hooks'
89

910
interfaceChannel{
1011
receive(action:T.Action):Promise<void>
@@ -56,14 +57,12 @@ class Channel implements Channel {
5657
// load step actions (git commits, commands, open files)
5758
case'SETUP_ACTIONS':
5859
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
59-
actions.onSetupActions({actions:action.payload.actions,send:this.send})
60+
hooks.onSetupEnter(action.payload.actions)
6061
return
6162
// load solution step actions (git commits, commands, open files)
6263
case'SOLUTION_ACTIONS':
6364
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
64-
awaitactions.onSolutionActions({actions:action.payload.actions,send:this.send})
65-
// run test following solution to update position
66-
actions.onRunTest()
65+
hooks.onSolutionEnter(action.payload.actions)
6766
return
6867
case'EDITOR_SYNC_POSITION':
6968
// update progress when a level is deemed complete in the client

‎src/commands.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as T from 'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
44
importcreateTestRunnerfrom'./services/testRunner'
5-
import{onSetupActions}from'./actions/onActions'
65
importcreateWebViewfrom'./services/webview'
76
importloggerfrom'./services/logger'
7+
import*ashooksfrom'./services/hooks'
88

99
exportconstCOMMANDS={
1010
START:'coderoad.start',
@@ -19,6 +19,14 @@ interface CreateCommandProps {
1919
workspaceState:vscode.Memento
2020
}
2121

22+
letsendToClient=(action:T.Action):void=>{
23+
/* */
24+
}
25+
26+
exportconstsend=(action:T.Action):void=>{
27+
sendToClient(action)
28+
}
29+
2230
exportconstcreateCommands=({ extensionPath, workspaceState}:CreateCommandProps):{[key:string]:any}=>{
2331
// React panel webview
2432
letwebview:any
@@ -30,6 +38,10 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
3038
[COMMANDS.START]:async()=>{
3139
if(webview&&webview.state.loaded){
3240
webview.createOrShow()
41+
// make send to client function exportable
42+
// as "send". This makes it easier to pass the send
43+
// function throughout the codebase
44+
sendToClient=webview.send
3345
}else{
3446
// activate machine
3547
webview=createWebView({
@@ -39,38 +51,31 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
3951
}
4052
},
4153
[COMMANDS.CONFIG_TEST_RUNNER]:async(data:TT.Tutorial)=>{
42-
consttestRunnerConfig=data.config.testRunner
43-
constsetup=testRunnerConfig.setup||testRunnerConfig.actions// TODO: deprecate and remove config.actions
44-
if(setup){
45-
// setup tutorial test runner commits
46-
// assumes git already exists
47-
awaitonSetupActions({
48-
actions:setup,
49-
send:webview.send,
50-
dir:testRunnerConfig.directory||testRunnerConfig.path,
51-
})// TODO: deprecate and remove config.path
54+
constsetupActions=data.config.setup
55+
if(setupActions){
56+
hooks.onInit(setupActions)
5257
}
5358
testRunner=createTestRunner(data,{
5459
onSuccess:(position:T.Position)=>{
5560
logger('test pass position',position)
5661
// send test pass message back to client
57-
webview.send({type:'TEST_PASS',payload:{position:{ ...position,complete:true}}})
62+
send({type:'TEST_PASS',payload:{position:{ ...position,complete:true}}})
5863
},
5964
onFail:(position:T.Position,failSummary:T.TestFail):void=>{
6065
// send test fail message back to client with failure message
61-
webview.send({type:'TEST_FAIL',payload:{ position,fail:failSummary}})
66+
send({type:'TEST_FAIL',payload:{ position,fail:failSummary}})
6267
},
6368
onError:(position:T.Position)=>{
6469
// TODO: send test error message back to client
6570
constmessage='Error with test runner'
66-
webview.send({type:'TEST_ERROR',payload:{ position, message}})
71+
send({type:'TEST_ERROR',payload:{ position, message}})
6772
},
6873
onRun:(position:T.Position)=>{
6974
// send test run message back to client
70-
webview.send({type:'TEST_RUNNING',payload:{ position}})
75+
send({type:'TEST_RUNNING',payload:{ position}})
7176
},
7277
onLoadSubtasks:({ summary})=>{
73-
webview.send({type:'LOAD_SUBTASK_RESULTS',payload:{ summary}})
78+
send({type:'LOAD_SUBTASK_RESULTS',payload:{ summary}})
7479
},
7580
})
7681
},
@@ -85,7 +90,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
8590
testRunner({position:currentPosition,onSuccess:callbacks?.onSuccess, subtasks})
8691
},
8792
[COMMANDS.ENTER]:()=>{
88-
webview.send({type:'KEY_PRESS_ENTER'})
93+
send({type:'KEY_PRESS_ENTER'})
8994
},
9095
}
9196
}

‎src/services/hooks/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import*asTTfrom'typings/tutorial'
2+
import*asgitfrom'../git'
3+
importloadCommitsfrom'./utils/loadCommits'
4+
importloadWatchersfrom'./utils/loadWatchers'
5+
importopenFilesfrom'./utils/openFiles'
6+
importrunCommandsfrom'./utils/runCommands'
7+
import{onErrorastelemetryOnError}from'../telemetry'
8+
import{onRunTest}from'../../actions/onTest'
9+
10+
exportconstonInit=async(actions:TT.StepActions):Promise<void>=>{
11+
awaitloadCommits(actions.commits)
12+
awaitrunCommands(actions.commands)
13+
}
14+
15+
exportconstonLevelEnter=async(actions:TT.StepActions):Promise<void>=>{
16+
awaitloadCommits(actions.commits)
17+
awaitrunCommands(actions.commands)
18+
}
19+
20+
exportconstonSetupEnter=async(actions:TT.StepActions):Promise<void>=>{
21+
// TODO: set position
22+
awaitloadCommits(actions.commits)
23+
awaitopenFiles(actions.files)
24+
awaitloadWatchers(actions.watchers)
25+
awaitrunCommands(actions.commands)
26+
}
27+
28+
exportconstonSolutionEnter=async(actions:TT.StepActions):Promise<void>=>{
29+
// TODO: set position
30+
awaitgit.clear()
31+
awaitloadCommits(actions.commits)
32+
awaitopenFiles(actions.files)
33+
awaitrunCommands(actions.commands)
34+
awaitonRunTest()
35+
}
36+
37+
exportconstonError=async(error:Error):Promise<void>=>{
38+
telemetryOnError(error)
39+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import*asgitfrom'../../git'
2+
3+
constloadCommits=async(commits:string[]):Promise<void>=>{
4+
if(commits){
5+
// load the current list of commits for validation
6+
constcurrentCommits:string[]=awaitgit.loadCommitHistory()
7+
for(constcommitofcommits){
8+
awaitgit.loadCommit(commit)
9+
}
10+
}
11+
}
12+
13+
exportdefaultloadCommits

‎src/actions/utils/loadWatchers.tsrenamed to‎src/services/hooks/utils/loadWatchers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*aschokidarfrom'chokidar'
22
import*asvscodefrom'vscode'
3-
import{COMMANDS}from'../../commands'
4-
import{WORKSPACE_ROOT}from'../../environment'
3+
import{COMMANDS}from'../../../commands'
4+
import{WORKSPACE_ROOT}from'../../../environment'
55

66
// NOTE: vscode createFileWatcher doesn't seem to detect changes outside of vscode
77
// such as `npm install` of a package. Went with chokidar instead
@@ -14,7 +14,7 @@ const disposeWatcher = (watcher: string) => {
1414
deletewatcherObject[watcher]
1515
}
1616

17-
constloadWatchers=(watchers:string[]):void=>{
17+
constloadWatchers=(watchers:string[]=[]):void=>{
1818
if(!watchers.length){
1919
// remove all watchers
2020
for(constwatcherofObject.keys(watcherObject)){

‎src/actions/utils/openFiles.tsrenamed to‎src/services/hooks/utils/openFiles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import{join}from'path'
22
import*asvscodefrom'vscode'
3-
import{COMMANDS}from'../../commands'
3+
import{COMMANDS}from'../../../commands'
44

5-
constopenFiles=async(files:string[]):Promise<void>=>{
5+
constopenFiles=async(files:string[]=[]):Promise<void>=>{
66
if(!files.length){
77
return
88
}

‎src/actions/utils/runCommands.tsrenamed to‎src/services/hooks/utils/runCommands.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import*asTfrom'typings'
2-
import{exec}from'../../services/node'
2+
import{exec}from'../../node'
3+
import{send}from'../../../commands'
34

4-
interfaceRunCommands{
5-
commands:string[]
6-
send:(action:T.Action)=>void
7-
dir?:string
8-
}
9-
10-
construnCommands=async({ commands, send, dir}:RunCommands):Promise<void>=>{
5+
construnCommands=async(commands:string[]=[]):Promise<void>=>{
116
if(!commands.length){
127
return
138
}
@@ -19,10 +14,10 @@ const runCommands = async ({ commands, send, dir }: RunCommands): Promise<void>
1914
send({type:'COMMAND_START',payload:{process:{ ...process,status:'RUNNING'}}})
2015
letresult:{stdout:string;stderr:string}
2116
try{
22-
result=awaitexec({ command, dir})
17+
result=awaitexec({ command})
2318
console.log(result)
2419
}catch(error){
25-
console.log(`Test failed:${error.message}`)
20+
console.error(`Test failed:${error.message}`)
2621
send({type:'COMMAND_FAIL',payload:{process:{ ...process,status:'FAIL'}}})
2722
return
2823
}

‎src/services/reset/lastHash.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ describe('lastHash', () => {
6565
consttutorial:TT.Tutorial={
6666
config:{
6767
//@ts-ignore
68-
testRunner:{
69-
setup:{
70-
commits:['abcdef2','abcdef3'],
71-
},
68+
testRunner:{},
69+
setup:{
70+
commits:['abcdef2','abcdef3'],
7271
},
7372
},
7473
levels:[

‎src/services/reset/lastHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const getLastCommitHash = (position: T.Position, tutorial: TT.Tutorial | null):
2828
level=levels[levelIndex-1]
2929
}else{
3030
// use init commit
31-
constconfigCommits=tutorial.config.testRunner.setup?.commits
31+
constconfigCommits=tutorial.config.setup?.commits
3232
if(!configCommits){
3333
thrownewError('No commits found to reset back to')
3434
}

‎src/services/testRunner/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks): ((params: an
7474
}
7575
}
7676
logger('COMMAND',command)
77-
result=awaitexec({ command,dir:testRunnerConfig.directory||testRunnerConfig.path})// TODO: remove config.path later
77+
result=awaitexec({ command,dir:testRunnerConfig.directory})
7878
}catch(err){
7979
result={stdout:err.stdout,stderr:err.stack}
8080
}

‎typings/tutorial.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type TutorialConfig = {
1111
testRunner:TestRunnerConfig
1212
repo:TutorialRepo
1313
dependencies?:TutorialDependency[]
14+
setup?:StepActions
1415
reset?:ConfigReset
1516
}
1617

@@ -70,10 +71,7 @@ export interface TestRunnerArgs {
7071
exportinterfaceTestRunnerConfig{
7172
command:string
7273
args:TestRunnerArgs
73-
path?:string// deprecated
7474
directory?:string
75-
actions?:StepActions// deprecated
76-
setup?:StepActions
7775
}
7876

7977
exportinterfaceTutorialRepo{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp