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

Commit21a0ff0

Browse files
committed
compare versions fn
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent5513a1d commit21a0ff0

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

‎package-lock.json

Lines changed: 29 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/jest":"^25.2.1",
4040
"@types/jsdom":"^16.2.0",
4141
"@types/node":"^13.11.0",
42+
"@types/semver":"^7.1.0",
4243
"@typescript-eslint/eslint-plugin":"^2.26.0",
4344
"@typescript-eslint/parser":"^2.26.0",
4445
"chokidar":"^3.3.0",
@@ -49,6 +50,7 @@
4950
"jest":"^25.2.7",
5051
"jsdom":"^16.2.2",
5152
"prettier":"^2.0.2",
53+
"semver":"^7.2.2",
5254
"ts-jest":"^25.3.1",
5355
"typescript":"^3.8.3"
5456
},

‎src/services/dependencies/index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import*asTTfrom'typings/tutorial'
2+
import{satisfies}from'semver'
13
importnodefrom'../node'
24

35
constsemverRegex=/(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/gi
46

5-
exportconstgetVersion=async(name:string):Promise<string|null>=>{
7+
exportconstversion=async(name:string):Promise<string|null>=>{
68
const{ stdout, stderr}=awaitnode.exec(`${name} --version`)
79
if(!stderr){
810
constmatch=stdout.match(semverRegex)
@@ -12,3 +14,24 @@ export const getVersion = async (name: string): Promise<string | null> => {
1214
}
1315
returnnull
1416
}
17+
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+
}
31+
// see node-semver docs: https://github.com/npm/node-semver
32+
constsatisfied:boolean=satisfies(currentVersion,expectedVersion)
33+
if(!satisfied){
34+
thrownewError(`Expected${name} to have version${expectedVersion}, but found version${currentVersion}`)
35+
}
36+
returntrue
37+
}

‎typings/tutorial.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ export interface TutorialRepo {
6262
exportinterfaceTutorialDependency{
6363
name:string
6464
version:string
65+
message?:string
6566
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp