Skip to content

Commit 85d7c78

Browse files
Merge pull request #2334 from NativeScript/vladimirov/fix-node-4
Fix CLI usage with Node.js 4
2 parents 6b81845 + 6ddc1f7 commit 85d7c78

File tree

6 files changed

+40
-83
lines changed

6 files changed

+40
-83
lines changed

bin/nativescript

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
#!/bin/sh
1+
#!/usr/bin/env node
22

3-
AB_DIR="`dirname \"$0\"`"
4-
NODE_VERSION=`node --version`
5-
NODE4_VERSION_PREFIX="v4."
6-
NODE5_VERSION_PREFIX="v5."
7-
8-
# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
9-
# so we have to pass --harmony flag for them in order to enable spread opearator usage
10-
# Use POSIX substring parameter expansion, so the code will work on all shells.
11-
12-
if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
13-
then
14-
# Node is 4.x.x or 5.x.x
15-
node --harmony "$AB_DIR/nativescript.js" "$@"
16-
else
17-
# Node is NOT 4.x.x or 5.x.x
18-
node "$AB_DIR/nativescript.js" "$@"
19-
fi
3+
require("./tns");

bin/nativescript.cmd

-18
This file was deleted.

bin/nativescript.js

-8
This file was deleted.

bin/tns

+36-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
#!/bin/sh
2-
3-
AB_DIR="`dirname \"$0\"`"
4-
NODE_VERSION=`node --version`
5-
NODE4_VERSION_PREFIX="v4."
6-
NODE5_VERSION_PREFIX="v5."
7-
8-
# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
9-
# so we have to pass --harmony flag for them in order to enable spread opearator usage
10-
# Use POSIX substring parameter expansion, so the code will work on all shells.
11-
12-
if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
13-
then
14-
# Node is 4.x.x or 5.x.x
15-
node --harmony "$AB_DIR/nativescript.js" "$@"
16-
else
17-
# Node is NOT 4.x.x or 5.x.x
18-
node "$AB_DIR/nativescript.js" "$@"
19-
fi
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
var path = require("path"),
5+
node = require("../package.json").engines.node,
6+
pathToLib = path.join(__dirname, "..", "lib"),
7+
pathToCommon = path.join(pathToLib, "common");
8+
9+
require(path.join(pathToCommon, "verify-node-version")).verifyNodeVersion(node, "NativeScript");
10+
11+
var pathToCliExecutable = path.join(pathToLib, "nativescript-cli.js");
12+
13+
var nodeArgs = require(path.join(pathToCommon, "scripts", "node-args")).getNodeArgs();
14+
15+
if (nodeArgs.length) {
16+
// We need custom args for Node process, so pass them here.
17+
var childProcess = require("child_process");
18+
var args = process.argv;
19+
20+
// Remove `node` and `nativescript` from the arguments.
21+
args.shift();
22+
args.shift();
23+
24+
args.unshift(pathToCliExecutable);
25+
26+
args = nodeArgs.concat(args);
27+
28+
var nodeProcess = childProcess.spawn(process.execPath, args, { stdio: "inherit" });
29+
30+
nodeProcess.on("close", function(code) {
31+
// We need this handler so if command fails, we'll exit with same exit code as CLI.
32+
process.exit(code);
33+
});
34+
} else {
35+
require(pathToCliExecutable);
36+
}

bin/tns.cmd

-18
This file was deleted.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"author": "Telerik <[email protected]>",
66
"description": "Command-line interface for building NativeScript projects",
77
"bin": {
8-
"tns": "./bin/nativescript.js",
9-
"nativescript": "./bin/nativescript.js"
8+
"tns": "./bin/tns",
9+
"nativescript": "./bin/tns"
1010
},
1111
"main": "./lib/nativescript-cli.js",
1212
"scripts": {

0 commit comments

Comments
 (0)