Skip to content

Commit 8f06ff2

Browse files
committed
fix version check
1 parent a7d5a67 commit 8f06ff2

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

lib/reducers/checks/check-setup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function hasDirectory() {
77
resolve(true);
88
}
99
else {
10-
resolve(true);
10+
resolve(false);
1111
}
1212
});
1313
}
@@ -18,7 +18,7 @@ function hasPackageJson() {
1818
if (!hasPackageJson) {
1919
resolve(true);
2020
}
21-
resolve(true);
21+
resolve(false);
2222
});
2323
}
2424
exports.hasPackageJson = hasPackageJson;
@@ -30,7 +30,7 @@ function hasTutorialDep() {
3030
if (!hasTutorialDep) {
3131
resolve(true);
3232
}
33-
resolve(true);
33+
resolve(false);
3434
});
3535
}
3636
exports.hasTutorialDep = hasTutorialDep;

lib/reducers/checks/check-system.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
"use strict";
22
var command_line_1 = require('../../services/command-line');
3+
function matchVersions(v) {
4+
return v.match(/([0-9]+)\.([0-9]+)/);
5+
}
36
function minVersion(command, minVersion) {
47
return new Promise(function (resolve, reject) {
58
var minOrLater = command_line_1.default(command, '-v')
69
.then(function (res) {
710
if (parseInt(res, 10).toString() === 'NaN') {
811
return false;
912
}
10-
var hasSecondDigit = res.match(/([0-9]+)\.([0-9]+)/);
11-
if (!!hasSecondDigit) {
12-
var versions = minVersion.match(/([0-9]+)\.([0-9]+)/);
13-
var firstDigit = parseInt(hasSecondDigit[1], 10);
14-
var firstVersion = parseInt(versions[1], 10);
13+
var mins = matchVersions(minVersion);
14+
if (!!mins) {
15+
var resMins = matchVersions(res);
16+
var firstDigit = parseInt(resMins[1], 10);
17+
var firstVersion = parseInt(mins[1], 10);
1518
return firstDigit > firstVersion ||
16-
firstDigit === firstVersion && parseInt(hasSecondDigit[2], 10) >= parseInt(firstVersion[2], 10);
19+
firstDigit === firstVersion && parseInt(resMins[2], 10) >= parseInt(firstVersion[2], 10);
1720
}
1821
else {
1922
return parseInt(res, 10) >= parseInt(minVersion, 10);

lib/reducers/checks/verify.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
var check_system_1 = require('./check-system');
33
var check_setup_1 = require('./check-setup');
44
var result = function (x) { return x; };
5-
var allTrue = function (obj) {
5+
function allTrue(obj) {
66
return Object.values(obj).every(function (x) { return x === true; });
7-
};
7+
}
88
function verifySetup() {
99
var checks = {
1010
system: {
@@ -20,7 +20,6 @@ function verifySetup() {
2020
checks.system.passed = allTrue(checks.system);
2121
checks.setup.passed = allTrue(checks.setup);
2222
checks.passed = checks.system.passed && checks.setup.passed;
23-
console.log('checks', checks);
2423
return checks;
2524
}
2625
Object.defineProperty(exports, "__esModule", { value: true });

src/reducers/checks/check-setup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function hasDirectory(): Promise<boolean> {
99
if (!hasDirectory) {
1010
resolve(true);
1111
} else {
12-
resolve(true);
12+
resolve(false);
1313
}
1414
});
1515
}
@@ -20,7 +20,7 @@ export function hasPackageJson(): Promise<boolean> {
2020
if (!hasPackageJson) {
2121
resolve(true);
2222
}
23-
resolve(true);
23+
resolve(false);
2424
});
2525
}
2626

@@ -32,7 +32,7 @@ export function hasTutorialDep(): Promise<boolean> {
3232
if (!hasTutorialDep) {
3333
resolve(true);
3434
}
35-
resolve(true);
35+
resolve(false);
3636
});
3737
}
3838

src/reducers/checks/check-system.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import commandLine from '../../services/command-line';
22

3+
function matchVersions(v: string): string[] {
4+
return v.match(/([0-9]+)\.([0-9]+)/);
5+
}
6+
37
function minVersion(command: string, minVersion: string): Promise<boolean> {
48
return new Promise((resolve, reject) => {
59
let minOrLater: Promise<boolean> = commandLine(command, '-v')
@@ -9,13 +13,13 @@ function minVersion(command: string, minVersion: string): Promise<boolean> {
913
return false;
1014
}
1115
// two digits, ex: 0.10
12-
let hasSecondDigit = res.match(/([0-9]+)\.([0-9]+)/);
13-
if (!!hasSecondDigit) {
14-
let versions = minVersion.match(/([0-9]+)\.([0-9]+)/);
15-
let firstDigit = parseInt(hasSecondDigit[1], 10);
16-
let firstVersion = parseInt(versions[1], 10);
16+
let mins = matchVersions(minVersion);
17+
if (!!mins) {
18+
let resMins = matchVersions(res);
19+
let firstDigit = parseInt(resMins[1], 10);
20+
let firstVersion = parseInt(mins[1], 10);
1721
return firstDigit > firstVersion ||
18-
firstDigit === firstVersion && parseInt(hasSecondDigit[2], 10) >= parseInt(firstVersion[2], 10);
22+
firstDigit === firstVersion && parseInt(resMins[2], 10) >= parseInt(firstVersion[2], 10);
1923
} else {
2024
// single digit, ex: 3.0
2125
return parseInt(res, 10) >= parseInt(minVersion, 10);

src/reducers/checks/verify.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function verifySetup() {
2020
checks.system.passed = allTrue(checks.system);
2121
checks.setup.passed = allTrue(checks.setup);
2222
checks.passed = checks.system.passed && checks.setup.passed;
23-
console.log('checks', checks);
2423
return checks;
2524
}
2625
Object.defineProperty(exports, "__esModule", { value: true });

src/reducers/checks/verify.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ export default function verifySetup(): CR.Checks {
2626
checks.system.passed = allTrue(checks.system);
2727
checks.setup.passed = allTrue(checks.setup);
2828
checks.passed = checks.system.passed && checks.setup.passed;
29-
console.log('checks', checks);
3029
return checks;
3130
}

0 commit comments

Comments
 (0)