Skip to content

Commit 719c486

Browse files
committed
Respect tns minVersion setting
1 parent f87b288 commit 719c486

File tree

6 files changed

+35
-225
lines changed

6 files changed

+35
-225
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ build/Release
2929
# Dependency directories
3030
node_modules
3131
jspm_packages
32+
package-lock.json
3233

3334
# Optional npm cache directory
3435
.npm

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ installNativeScript.ensureNode()
2525
* [fixMissingNPMPermissions](#fixmissingnpmpermissions)
2626

2727
### ensureNode
28-
The `ensureNode` method checks if node is installed on the machine. In case it cannot detect it, the method downloads a node installer and runs it. You can pass a specific node version to install. In case it is not provided, the method installs version 6.11.4.
28+
The `ensureNode` method checks if node is installed on the machine. In case it cannot detect it, the method downloads a node installer and runs it. You can pass a specific node version to install. In case it is not provided, the method installs version 8.11.3.
2929

3030
Note: This method changes process.env so that after it succeeds, you can install and detect globally installed npm modules.
3131

@@ -37,7 +37,10 @@ installNativeScript.ensureNode();
3737
```
3838

3939
### ensureCLI
40-
The `ensureCLI` method checks if you have NativeScript CLI installed globally on your machine. In case it cannot detect it, the method installs it globally using npm. You can pass a specific NativeScript CLI version to install. In case it is not provided, the method installs the latest official version.
40+
The `ensureCLI` method checks if you have NativeScript CLI installed globally on your machine.
41+
42+
- In case it cannot detect it, the method installs it globally using npm. You can pass a specific NativeScript CLI version to install. In case it is not provided, the method installs the latest official version.
43+
- In case it detects a version, the method will update it in case you pass a specific minVersion and the current version does not satisfy the requirement. Again, in case a specific version is not provided, the method installs the latest official version.
4144

4245
Usage:
4346
```JavaScript

lib/ensure-cli-service.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const _ = require("lodash");
2+
const semver = require("semver");
3+
14
module.exports = (helpers, config, sysInfo) => {
25
const { logMessage, execSync, stringFormat } = helpers;
36
const { getCLICommand, installCLICommand, removeGlobalPackageCommand } = config;
@@ -26,12 +29,6 @@ module.exports = (helpers, config, sysInfo) => {
2629
};
2730

2831
const installCLI = (cliVersion) => {
29-
const cliPath = getDependencyPath();
30-
31-
if (cliPath) {
32-
return;
33-
}
34-
3532
const version = cliVersion ? `@${cliVersion}` : "";
3633
const command = stringFormat(installCLICommand, version);
3734

@@ -84,10 +81,29 @@ module.exports = (helpers, config, sysInfo) => {
8481
});
8582
};
8683

87-
const ensureCLI = (cliVersion) => {
84+
const ensureCLI = ({ version = "latest", minVersion } = {}) => {
8885
return findCLI()
86+
.then((cliVersion) => {
87+
const hasMinRequirement = !_.isNil(minVersion) && !_.isNull(semver.valid(minVersion));
88+
89+
if (!hasMinRequirement || semver.gte(cliVersion, minVersion)) {
90+
return cliVersion;
91+
}
92+
93+
logMessage(`Found version ${cliVersion} does not satisfy required minVersion ${minVersion}.`);
94+
95+
installCLI(version);
96+
97+
return findCLI();
98+
})
8999
.catch(() => {
90-
installCLI(cliVersion);
100+
const cliPath = getDependencyPath();
101+
102+
if (cliPath) {
103+
return;
104+
}
105+
106+
installCLI(version);
91107

92108
return findCLI();
93109
});

lib/ensure-node-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ module.exports = (helpers, config, sysInfo) => {
7777
});
7878
};
7979

80-
const ensureNode = (nodeVersion = "6.11.4") => {
80+
const ensureNode = ({ version = "8.11.3" } = {}) => {
8181
return findNode()
8282
.catch(() => {
83-
return installNode(nodeVersion)
83+
return installNode(version)
8484
.then(findNode);
8585
});
8686
};

package-lock.json

Lines changed: 0 additions & 211 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "install-nativescript",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Package that helps you install Node.js, npm and nativescript-cli. Works only on Windows and Mac.",
55
"main": "index.js",
66
"scripts": {
@@ -23,7 +23,8 @@
2323
"dependencies": {
2424
"get-shell-vars": "^3.0.0",
2525
"lodash": "^4.17.4",
26-
"nativescript-doctor": "^0.8.0",
26+
"nativescript-doctor": "1.2.1",
27+
"semver": "5.3.0",
2728
"sudo-prompt": "^7.0.0",
2829
"temp": "^0.8.3"
2930
}

0 commit comments

Comments
 (0)