Skip to content

Transpile to ES6 #2285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ results
scratch/
.idea/
.settings/
.vscode/
.vscode/**
!.vscode/launch.json
test-reports.xml

npm-debug.log
node_modules
docs/html
docs/html

!test-scripts/*.js
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ lib/**/*.ts
lib/**/*.js.map

test/
test-scripts/
.vscode
lib/common/test/
coverage/
scratch/
*.suo
.travis.yml
docs/html/
dev/
dev/
70 changes: 70 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program (Node 6+)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
// define the arguments that you would like to pass to CLI, for example
// "args": [ "build", "android", "--justlaunch" ]
"args": [

]
},

{
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
"type": "node",
"request": "launch",
"name": "Launch Tests (Node 6+)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},

{
"type": "node",
"runtimeArgs": [
"--harmony"
],
"request": "launch",
"name": "Launch Program (Node 4, Node 5)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
// define the arguments that you would like to pass to CLI, for example
// "args": [ "build", "android", "--justlaunch" ]
"args": [

]
},

{
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
"type": "node",
"runtimeArgs": [
"--harmony"
],
"request": "launch",
"name": "Launch Tests (Node 4, Node 5)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},

{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858,
"sourceMaps": true
}

]
}
22 changes: 12 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ module.exports = function(grunt) {

pkg: grunt.file.readJSON("package.json"),
ts: {
options: {
target: 'es5',
module: 'commonjs',
sourceMap: true,
declaration: false,
removeComments: false,
noImplicitAny: true,
experimentalDecorators: true
},
options: grunt.file.readJSON("tsconfig.json").compilerOptions,

devlib: {
src: ["lib/**/*.ts", "!lib/common/node_modules/**/*.ts"],
Expand Down Expand Up @@ -131,7 +123,17 @@ module.exports = function(grunt) {
},

clean: {
src: ["test/**/*.js*", "lib/**/*.js*", "!lib/common/vendor/*.js", "!lib/common/**/*.json", "!lib/common/Gruntfile.js", "!lib/common/node_modules/**/*", "!lib/common/hooks/**/*.js", "!lib/common/bin/*.js", "*.tgz"]
src: ["test/**/*.js*",
"lib/**/*.js*",
"!test-scripts/**/*",
"!lib/common/vendor/*.js",
"!lib/common/**/*.json",
"!lib/common/Gruntfile.js",
"!lib/common/node_modules/**/*",
"!lib/common/hooks/**/*.js",
"!lib/common/bin/*.js",
"!lib/common/test-scripts/**/*",
"*.tgz"]
}
});

Expand Down
17 changes: 16 additions & 1 deletion bin/nativescript
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/sh

AB_DIR="`dirname \"$0\"`"
node "$AB_DIR/nativescript.js" "$@"
NODE_VERSION=`node --version`
NODE4_VERSION_PREFIX="v4."
NODE5_VERSION_PREFIX="v5."

# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
# so we have to pass --harmony flag for them in order to enable spread opearator usage
# Use POSIX substring parameter expansion, so the code will work on all shells.

if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
then
# Node is 4.x.x or 5.x.x
node --harmony "$AB_DIR/nativescript.js" "$@"
else
# Node is NOT 4.x.x or 5.x.x
node "$AB_DIR/nativescript.js" "$@"
fi
19 changes: 18 additions & 1 deletion bin/nativescript.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
@node %~dp0\nativescript.js %*
@for /F "delims=" %%i IN ('@node --version') DO @set node_ver=%%i

@echo %node_ver% | @findstr /b /c:"v4."
@set is_node_4=%errorlevel%

@echo %node_ver% | @findstr /b /c:"v5."
@set is_node_5=%errorlevel%

@set use_harmony_flag=0

@if %is_node_4% == 0 @set use_harmony_flag=1
@if %is_node_5% == 0 @set use_harmony_flag=1

@if %use_harmony_flag% == 1 (
return @node --harmony %~dp0\nativescript.js %*
) else (
@node %~dp0\nativescript.js %*
)
17 changes: 16 additions & 1 deletion bin/tns
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/sh

AB_DIR="`dirname \"$0\"`"
node "$AB_DIR/nativescript.js" "$@"
NODE_VERSION=`node --version`
NODE4_VERSION_PREFIX="v4."
NODE5_VERSION_PREFIX="v5."

# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
# so we have to pass --harmony flag for them in order to enable spread opearator usage
# Use POSIX substring parameter expansion, so the code will work on all shells.

if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
then
# Node is 4.x.x or 5.x.x
node --harmony "$AB_DIR/nativescript.js" "$@"
else
# Node is NOT 4.x.x or 5.x.x
node "$AB_DIR/nativescript.js" "$@"
fi
19 changes: 18 additions & 1 deletion bin/tns.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
@node %~dp0\nativescript.js %*
@for /F "delims=" %%i IN ('@node --version') DO @set node_ver=%%i

@echo %node_ver% | @findstr /b /c:"v4."
@set is_node_4=%errorlevel%

@echo %node_ver% | @findstr /b /c:"v5."
@set is_node_5=%errorlevel%

@set use_harmony_flag=0

@if %is_node_4% == 0 @set use_harmony_flag=1
@if %is_node_5% == 0 @set use_harmony_flag=1

@if %use_harmony_flag% == 1 (
return @node --harmony %~dp0\nativescript.js %*
) else (
@node %~dp0\nativescript.js %*
)
7 changes: 5 additions & 2 deletions lib/device-sockets/ios/socket-request-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
return (() => {
let npc = new iOSProxyServices.NotificationProxyClient(device, this.$injector);

let [alreadyConnected, readyForAttach, attachAvailable] = [this.$iOSNotification.alreadyConnected, this.$iOSNotification.readyForAttach, this.$iOSNotification.attachAvailable]
.map((notification) => this.$iOSNotificationService.awaitNotification(npc, notification, timeout));
let data = [this.$iOSNotification.alreadyConnected, this.$iOSNotification.readyForAttach, this.$iOSNotification.attachAvailable]
.map((notification) => this.$iOSNotificationService.awaitNotification(npc, notification, timeout)),
alreadyConnected = data[0],
readyForAttach = data[1],
attachAvailable = data[2];

npc.postNotificationAndAttachForData(this.$iOSNotification.attachAvailabilityQuery);

Expand Down
9 changes: 7 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export class PlatformService implements IPlatformService {

private addPlatform(platformParam: string): IFuture<void> {
return (() => {
let [platform, version] = platformParam.split("@");
let data = platformParam.split("@"),
platform = data[0],
version = data[1];

this.validatePlatform(platform);

Expand Down Expand Up @@ -427,7 +429,10 @@ export class PlatformService implements IPlatformService {
public updatePlatforms(platforms: string[]): IFuture<void> {
return (() => {
_.each(platforms, platformParam => {
let [platform, version] = platformParam.split("@");
let data = platformParam.split("@"),
platform = data[0],
version = data[1];

if (this.isPlatformInstalled(platform).wait()) {
this.updatePlatform(platform, version).wait();
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class PluginsService implements IPluginsService {
.filter(dependencyName => _.startsWith(dependencyName, "@"))
.each(scopedDependencyDir => {
let contents = this.$fs.readDirectory(path.join(this.nodeModulesPath, scopedDependencyDir)).wait();
installedDependencies = installedDependencies.concat(...contents.map(dependencyName => `${scopedDependencyDir}/${dependencyName}`));
installedDependencies = installedDependencies.concat(contents.map(dependencyName => `${scopedDependencyDir}/${dependencyName}`));
});

let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
Expand Down
5 changes: 4 additions & 1 deletion lib/services/project-templates-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
let templateName = originalTemplateName.toLowerCase();

// support <reserved_name>@<version> syntax
let [name, version] = templateName.split("@");
let data = templateName.split("@"),
name = data[0],
version = data[1];

if(constants.RESERVED_TEMPLATE_NAMES[name]) {
realTemplatePath = this.prepareNativeScriptTemplate(constants.RESERVED_TEMPLATE_NAMES[name], version, projectDir).wait();
} else {
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"main": "./lib/nativescript-cli.js",
"scripts": {
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha",
"test": "node test-scripts/istanbul.js",
"postinstall": "node postinstall.js",
"preuninstall": "node preuninstall.js",
"mocha": "mocha",
"mocha": "node test-scripts/mocha.js",
"tsc": "tsc",
"test-watch": "node ./dev/tsc-to-mocha-watch.js"
},
Expand All @@ -27,7 +27,6 @@
"mobile"
],
"dependencies": {
"bluebird": "2.9.34",
"bplist-parser": "0.1.0",
"bufferpack": "0.0.6",
"bufferutil": "https://github.com/telerik/bufferutil/tarball/v1.0.1.4",
Expand Down Expand Up @@ -90,7 +89,7 @@
"grunt-ts": "6.0.0-beta.3",
"grunt-tslint": "3.3.0",
"istanbul": "0.4.5",
"mocha": "2.5.3",
"mocha": "3.1.2",
"mocha-fibers": "https://github.com/NativeScript/mocha-fibers.git",
"mocha-typescript": "^1.0.4",
"should": "7.0.2",
Expand Down
18 changes: 18 additions & 0 deletions test-scripts/istanbul.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

const childProcess = require("child_process");
const path = require("path");
const pathToIstanbul = path.join(__dirname, "..", "node_modules", "istanbul", "lib", "cli.js");
const pathToMocha = path.join(__dirname, "..", "node_modules", "mocha", "bin", "_mocha");

const istanbulArgs = [ pathToIstanbul, "cover", pathToMocha ];

const nodeArgs = require("../lib/common/test-scripts/node-args").getNodeArgs();

const args = nodeArgs.concat(istanbulArgs);

const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit"});
nodeProcess.on("close", (code) => {
// We need this handler so if any test fails, we'll exit with same exit code as istanbul.
process.exit(code);
});
15 changes: 15 additions & 0 deletions test-scripts/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";

const childProcess = require("child_process");
const path = require("path");
const pathToMocha = path.join(__dirname, "..", "node_modules", "mocha", "bin", "_mocha");

const nodeArgs = require("../lib/common/test-scripts/node-args").getNodeArgs();

const args = nodeArgs.concat(pathToMocha);

const nodeProcess = childProcess.spawn("node", args, { stdio: "inherit"});
nodeProcess.on("close", (code) => {
// We need this handler so if any test fails, we'll exit with same exit code as mocha.
process.exit(code);
});
Loading