Skip to content

Commit b16dffb

Browse files
committed
create minVersion checker, check for node version
1 parent bd95826 commit b16dffb

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

lib/reducers/checks/check-system.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
"use strict";
22
var command_line_1 = require('../../services/command-line');
3-
var minVersion = 3;
4-
function npmVersionThreeOrLater() {
3+
function minVersion(command, minVersion) {
54
return new Promise(function (resolve, reject) {
6-
var threeOrLater = command_line_1.default('npm', '-v').then(function (res) { return parseInt(res, 10) >= minVersion; });
7-
if (!threeOrLater) {
5+
var minOrLater = command_line_1.default(command, '-v')
6+
.then(function (res) {
7+
console.log(res);
8+
if (parseInt(res, 10).toString() === 'NaN') {
9+
return false;
10+
}
11+
var hasSecondDigit = res.match(/([0-9]+)\.([0-9]+)/);
12+
if (!!hasSecondDigit) {
13+
var versions = minVersion.match(/([0-9]+)\.([0-9]+)/);
14+
var firstDigit = parseInt(hasSecondDigit[1], 10);
15+
var firstVersion = parseInt(versions[1], 10);
16+
return firstDigit > firstVersion ||
17+
firstDigit === firstVersion && parseInt(hasSecondDigit[2], 10) >= parseInt(firstVersion[2], 10);
18+
}
19+
else {
20+
return parseInt(res, 10) >= parseInt(minVersion, 10);
21+
}
22+
});
23+
if (!minOrLater) {
824
resolve(false);
925
}
1026
else {
1127
resolve(true);
1228
}
1329
});
1430
}
15-
exports.npmVersionThreeOrLater = npmVersionThreeOrLater;
31+
function npmMinVersion() {
32+
return minVersion('npm', '3');
33+
}
34+
exports.npmMinVersion = npmMinVersion;
35+
function nodeMinVersion() {
36+
return minVersion('node', '0.10');
37+
}
38+
exports.nodeMinVersion = nodeMinVersion;

lib/reducers/checks/verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ function result(x) {
1010
function verifySetup() {
1111
var checks = {
1212
system: {
13-
node: false,
14-
npm: !!check_system_1.npmVersionThreeOrLater()
13+
node: !!check_system_1.nodeMinVersion(),
14+
npm: !!check_system_1.npmMinVersion()
1515
},
1616
setup: {
1717
dir: !!check_setup_1.hasDirectory(),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"classnames": "2.2.3",
4242
"highlights": "1.3.1",
43-
"lodash": "4.10.0",
43+
"lodash": "4.11.0",
4444
"marked": "0.3.5",
4545
"material-ui": "0.15.0-alpha.2",
4646
"react": "15.0.1",

src/reducers/checks/check-system.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
import commandLine from '../../services/command-line';
22

3-
const minVersion = 3;
4-
export function npmVersionThreeOrLater(): Promise<boolean> {
3+
function minVersion(command: string, minVersion: string): Promise<boolean> {
54
return new Promise((resolve, reject) => {
6-
let threeOrLater: Promise<boolean> = commandLine('npm', '-v').then((res: string) => parseInt(res, 10) >= minVersion);
7-
if (!threeOrLater) {
5+
let minOrLater: Promise<boolean> = commandLine(command, '-v')
6+
.then((res: string) => {
7+
// not installed
8+
if (parseInt(res, 10).toString() === 'NaN') {
9+
return false;
10+
}
11+
// 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);
17+
return firstDigit > firstVersion ||
18+
firstDigit === firstVersion && parseInt(hasSecondDigit[2], 10) >= parseInt(firstVersion[2], 10);
19+
} else {
20+
// single digit, ex: 3.0
21+
return parseInt(res, 10) >= parseInt(minVersion, 10);
22+
}
23+
});
24+
if (!minOrLater) {
825
resolve(false);
926
} else {
1027
resolve(true);
1128
}
1229
});
1330
}
31+
32+
export function npmMinVersion(): Promise<boolean> {
33+
return minVersion('npm', '3');
34+
}
35+
36+
export function nodeMinVersion(): Promise<boolean> {
37+
return minVersion('node', '0.10');
38+
}

src/reducers/checks/verify.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {fileExists} from '../../services/exists';
2-
import {npmVersionThreeOrLater} from './check-system';
2+
import {npmMinVersion, nodeMinVersion} from './check-system';
33
import {hasDirectory, hasPackageJson, hasTutorialDep} from './check-setup';
44
import {packageJsonExists, loadRootPackageJson, searchForTutorials} from '../tutorials/check-tutorials';
5-
import {createPackageJson, openDirectory, installTutorial} from './setup-actions';
5+
import {createPackageJson, openDirectory, installTutorial} from './action-setup';
66
import * as path from 'path';
77

88
function allTrue(obj: Object): boolean {
@@ -16,8 +16,8 @@ function result(x) {
1616
export default function verifySetup(): CR.Checks {
1717
let checks: CR.Checks = {
1818
system: {
19-
node: false,
20-
npm: !!npmVersionThreeOrLater()
19+
node: !!nodeMinVersion(),
20+
npm: !!npmMinVersion()
2121
},
2222
setup: {
2323
dir: !!hasDirectory(),

0 commit comments

Comments
 (0)