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

Commitae3ee13

Browse files
committed
refactor onTutorialConfig
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent7f12a0f commitae3ee13

File tree

4 files changed

+129
-115
lines changed

4 files changed

+129
-115
lines changed

‎src/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export{defaultasonStartup}from'./onStartup'
2+
export{defaultasonTutorialConfig}from'./onTutorialConfig'
23
export{defaultasonErrorPage}from'./onErrorPage'
34
export{defaultasonTestPass}from'./onTestPass'

‎src/actions/onTutorialConfig.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import*asvscodefrom'vscode'
2+
import*asTfrom'typings'
3+
import*asTTfrom'typings/tutorial'
4+
import*asEfrom'typings/error'
5+
import{satisfies}from'semver'
6+
import{onEvent}from'../services/telemetry'
7+
import{version,compareVersions}from'../services/dependencies'
8+
importContextfrom'../services/context/context'
9+
importtutorialConfigfrom'./utils/tutorialConfig'
10+
11+
constonTutorialConfig=async(action:T.Action,context:Context,workspaceState:vscode.Memento,send:any)=>{
12+
try{
13+
constdata:TT.Tutorial=action.payload.tutorial
14+
15+
onEvent('tutorial_start',{
16+
tutorial_id:data.id,
17+
tutorial_version:data.version,
18+
tutorial_title:data.summary.title,
19+
})
20+
21+
// validate extension version
22+
constexpectedAppVersion=data.config?.appVersions?.vscode
23+
if(expectedAppVersion){
24+
constextension=vscode.extensions.getExtension('coderoad.coderoad')
25+
if(extension){
26+
constcurrentAppVersion=extension.packageJSON.version
27+
constsatisfied=satisfies(currentAppVersion,expectedAppVersion)
28+
if(!satisfied){
29+
consterror:E.ErrorMessage={
30+
type:'UnmetExtensionVersion',
31+
message:`Expected CodeRoad v${expectedAppVersion}, but found v${currentAppVersion}`,
32+
}
33+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
34+
return
35+
}
36+
}
37+
}
38+
39+
// setup tutorial config (save watcher, test runner, etc)
40+
awaitcontext.setTutorial(workspaceState,data)
41+
42+
// validate dependencies
43+
constdependencies=data.config.dependencies
44+
if(dependencies&&dependencies.length){
45+
for(constdepofdependencies){
46+
// check dependency is installed
47+
constcurrentVersion:string|null=awaitversion(dep.name)
48+
if(!currentVersion){
49+
// use a custom error message
50+
consterror:E.ErrorMessage={
51+
type:'MissingTutorialDependency',
52+
message:dep.message||`Process "${dep.name}" is required but not found. It may need to be installed`,
53+
actions:[
54+
{
55+
label:'Check Again',
56+
transition:'TRY_AGAIN',
57+
},
58+
],
59+
}
60+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
61+
return
62+
}
63+
64+
// check dependency version
65+
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version)
66+
67+
if(!satisfiedDependency){
68+
consterror:E.ErrorMessage={
69+
type:'UnmetTutorialDependency',
70+
message:`Expected${dep.name} to have version${dep.version}, but found version${currentVersion}`,
71+
actions:[
72+
{
73+
label:'Check Again',
74+
transition:'TRY_AGAIN',
75+
},
76+
],
77+
}
78+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
79+
return
80+
}
81+
82+
if(satisfiedDependency!==true){
83+
consterror:E.ErrorMessage=satisfiedDependency||{
84+
type:'UnknownError',
85+
message:`Something went wrong comparing dependency for${name}`,
86+
actions:[
87+
{
88+
label:'Try Again',
89+
transition:'TRY_AGAIN',
90+
},
91+
],
92+
}
93+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
94+
return
95+
}
96+
}
97+
}
98+
99+
consterror:E.ErrorMessage|void=awaittutorialConfig({ data}).catch((error:Error)=>({
100+
type:'UnknownError',
101+
message:`Location: tutorial config.\n\n${error.message}`,
102+
}))
103+
104+
// has error
105+
if(error&&error.type){
106+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
107+
return
108+
}
109+
110+
// report back to the webview that setup is complete
111+
send({type:'TUTORIAL_CONFIGURED'})
112+
}catch(e){
113+
consterror={
114+
type:'UnknownError',
115+
message:`Location: EditorTutorialConfig.\n\n${e.message}`,
116+
}
117+
send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
118+
}
119+
}
120+
121+
exportdefaultonTutorialConfig

‎src/actions/tutorialConfig.tsrenamed to‎src/actions/utils/tutorialConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import*asEfrom'typings/error'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
4-
import{COMMANDS}from'../commands'
5-
import*asgitfrom'../services/git'
6-
import{DISABLE_RUN_ON_SAVE}from'../environment'
4+
import{COMMANDS}from'../../commands'
5+
import*asgitfrom'../../services/git'
6+
import{DISABLE_RUN_ON_SAVE}from'../../environment'
77

88
interfaceTutorialConfigParams{
99
data:TT.Tutorial

‎src/channel.ts

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import * as T from 'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asEfrom'typings/error'
44
import*asvscodefrom'vscode'
5-
import{satisfies}from'semver'
65
import{setupActions,solutionActions}from'./actions/setupActions'
7-
importtutorialConfigfrom'./actions/tutorialConfig'
6+
importtutorialConfigfrom'./actions/utils/tutorialConfig'
87
import{COMMANDS}from'./commands'
98
importContextfrom'./services/context/context'
109
importloggerfrom'./services/logger'
11-
import{version,compareVersions}from'./services/dependencies'
10+
import{version}from'./services/dependencies'
1211
import{openWorkspace,checkWorkspaceEmpty}from'./services/workspace'
1312
import{showOutput}from'./services/testRunner/output'
1413
import{exec}from'./services/node'
1514
importresetfrom'./services/reset'
1615
importgetLastCommitHashfrom'./services/reset/lastHash'
17-
import{onEvent}from'./services/telemetry'
16+
1817
import*asactionsfrom'./actions'
1918

2019
interfaceChannel{
@@ -58,114 +57,7 @@ class Channel implements Channel {
5857
return
5958
// configure test runner, language, git
6059
case'EDITOR_TUTORIAL_CONFIG':
61-
try{
62-
constdata:TT.Tutorial=action.payload.tutorial
63-
64-
onEvent('tutorial_start',{
65-
tutorial_id:data.id,
66-
tutorial_version:data.version,
67-
tutorial_title:data.summary.title,
68-
})
69-
70-
// validate extension version
71-
constexpectedAppVersion=data.config?.appVersions?.vscode
72-
if(expectedAppVersion){
73-
constextension=vscode.extensions.getExtension('coderoad.coderoad')
74-
if(extension){
75-
constcurrentAppVersion=extension.packageJSON.version
76-
constsatisfied=satisfies(currentAppVersion,expectedAppVersion)
77-
if(!satisfied){
78-
consterror:E.ErrorMessage={
79-
type:'UnmetExtensionVersion',
80-
message:`Expected CodeRoad v${expectedAppVersion}, but found v${currentAppVersion}`,
81-
}
82-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
83-
return
84-
}
85-
}
86-
}
87-
88-
// setup tutorial config (save watcher, test runner, etc)
89-
awaitthis.context.setTutorial(this.workspaceState,data)
90-
91-
// validate dependencies
92-
constdependencies=data.config.dependencies
93-
if(dependencies&&dependencies.length){
94-
for(constdepofdependencies){
95-
// check dependency is installed
96-
constcurrentVersion:string|null=awaitversion(dep.name)
97-
if(!currentVersion){
98-
// use a custom error message
99-
consterror:E.ErrorMessage={
100-
type:'MissingTutorialDependency',
101-
message:
102-
dep.message||`Process "${dep.name}" is required but not found. It may need to be installed`,
103-
actions:[
104-
{
105-
label:'Check Again',
106-
transition:'TRY_AGAIN',
107-
},
108-
],
109-
}
110-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
111-
return
112-
}
113-
114-
// check dependency version
115-
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version)
116-
117-
if(!satisfiedDependency){
118-
consterror:E.ErrorMessage={
119-
type:'UnmetTutorialDependency',
120-
message:`Expected${dep.name} to have version${dep.version}, but found version${currentVersion}`,
121-
actions:[
122-
{
123-
label:'Check Again',
124-
transition:'TRY_AGAIN',
125-
},
126-
],
127-
}
128-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
129-
return
130-
}
131-
132-
if(satisfiedDependency!==true){
133-
consterror:E.ErrorMessage=satisfiedDependency||{
134-
type:'UnknownError',
135-
message:`Something went wrong comparing dependency for${name}`,
136-
actions:[
137-
{
138-
label:'Try Again',
139-
transition:'TRY_AGAIN',
140-
},
141-
],
142-
}
143-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
144-
return
145-
}
146-
}
147-
}
148-
149-
consterror:E.ErrorMessage|void=awaittutorialConfig({ data}).catch((error:Error)=>({
150-
type:'UnknownError',
151-
message:`Location: tutorial config.\n\n${error.message}`,
152-
}))
153-
154-
// has error
155-
if(error&&error.type){
156-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
157-
return
158-
}
159-
160-
// report back to the webview that setup is complete
161-
this.send({type:'TUTORIAL_CONFIGURED'})
162-
}catch(e){
163-
consterror={
164-
type:'UnknownError',
165-
message:`Location: EditorTutorialConfig.\n\n${e.message}`,
166-
}
167-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
168-
}
60+
actions.onTutorialConfig(action,this.context,this.workspaceState,this.send)
16961
return
17062
case'EDITOR_TUTORIAL_CONTINUE_CONFIG':
17163
try{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp