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

Commit37ed10b

Browse files
committed
add tutorial missing and unmet dependency checks
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent176d24a commit37ed10b

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

‎errors/MissingTutorialDependency.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
###Missing Tutorial Dependency
2+
3+
The tutorial cannot run because it a dependency is not yet installed. Install the dependency and click "Check Again".

‎errors/UnmetTutorialDependency.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
###Unmet Tutorial Dependency
2+
3+
###Unmet Tutorial Dependency
4+
5+
Tutorial cannot reun because a dependency version doesn't match. Install the correct dependency and click "Check Again".

‎src/channel/index.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import tutorialConfig from '../actions/tutorialConfig'
99
import{COMMANDS}from'../editor/commands'
1010
importloggerfrom'../services/logger'
1111
importContextfrom'./context'
12-
import{version}from'../services/dependencies'
12+
import{version,compareVersions}from'../services/dependencies'
1313
import{openWorkspace,checkWorkspaceEmpty}from'../services/workspace'
1414
import{readFile}from'fs'
1515
import{join}from'path'
1616
import{promisify}from'util'
17+
import{compare}from'semver'
1718

1819
constreadFileAsync=promisify(readFile)
1920

@@ -95,6 +96,53 @@ class Channel implements Channel {
9596
awaitthis.context.setTutorial(this.workspaceState,data)
9697

9798
// validate dependencies
99+
if(data.config.dependencies){
100+
for(constdepofdata.config.dependencies){
101+
// check dependency is installed
102+
constcurrentVersion:string|null=awaitversion(name)
103+
if(!currentVersion){
104+
// use a custom error message
105+
consterror={
106+
type:'MissingTutorialDependency',
107+
message:dep.message||`Process${name} is required but not found. It may need to be installed`,
108+
actions:[
109+
{
110+
label:'Check Again',
111+
transition:'TRY_AGAIN',
112+
},
113+
],
114+
}
115+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
116+
return
117+
}
118+
119+
// check dependency version
120+
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version).catch((error:Error)=>({
121+
type:'UnmetTutorialDependency',
122+
message:error.message,
123+
actions:[
124+
{
125+
label:'Check Again',
126+
transition:'TRY_AGAIN',
127+
},
128+
],
129+
}))
130+
if(satisfiedDependency!==true){
131+
consterror=satisfiedDependency||{
132+
type:'UnknownError',
133+
message:`Something went wrong comparing dependency for${name}`,
134+
actions:[
135+
{
136+
label:'Try Again',
137+
transition:'TRY_AGAIN',
138+
},
139+
],
140+
}
141+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
142+
return
143+
}
144+
}
145+
}
98146

99147
consterror:E.ErrorMessage|void=awaittutorialConfig({config:data.config}).catch((error:Error)=>({
100148
type:'UnknownError',

‎src/services/dependencies/index.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ export const version = async (name: string): Promise<string | null> => {
1515
returnnull
1616
}
1717

18-
exportconstcompareVersions=async({
19-
name,
20-
version:expectedVersion,
21-
message,
22-
}:TT.TutorialDependency):Promise<boolean>=>{
23-
constcurrentVersion=awaitversion(name)
24-
if(!currentVersion){
25-
// use a custom error message
26-
if(message){
27-
thrownewError(message)
28-
}
29-
thrownewError(`Process${name} is required but not found. It may need to be installed`)
30-
}
18+
exportconstcompareVersions=async(currentVersion:string,expectedVersion:string):Promise<never|boolean>=>{
3119
// see node-semver docs: https://github.com/npm/node-semver
3220
constsatisfied:boolean=satisfies(currentVersion,expectedVersion)
3321
if(!satisfied){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp