Skip to content

Commit 3de21f9

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #756 from NativeScript/fatme/merge-release-1.2.2
Merge release 1.2.2
2 parents 595cb73 + b0abf92 commit 3de21f9

22 files changed

+246
-99
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
NativeScript CLI Changelog
22
================
33

4-
1.2.0 (2015, July 22)
4+
1.2.1 (2015, July 27)
5+
==
6+
7+
### Fixed
8+
9+
* [Fixed #690](https://github.com/NativeScript/nativescript-cli/issues/690): The `$ tns debug ios --debug-brk` command does not work.
10+
11+
1.2.0 (2015, July 24)
512
==
613

714
### New

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Apache License
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright (c) 2015 Telerik AD
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

docs/man_pages/project/testing/debug-android.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Debugs your project on a connected device, in a native emulator or in Genymotion
2323
* `--stop` - Detaches the debug tools.
2424
* `--get-port` - Retrieves the port on which you are debugging your application.
2525
* `--debug-port` - Sets a new port on which to attach the debug tools.
26+
* `--timeout` - Sets the number of seconds that NativeScript CLI will wait for the debugger to boot. If not set, the default timeout is 90 seconds.
2627

2728
### Attributes
2829
* `<Device ID>` is the index or name of the target device as listed by `$ tns device`

docs/man_pages/project/testing/debug-ios.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Debugs your project on a connected device or in the iOS Simulator. <% if(isHtml)
2020
* `--start` - Attaches the debug tools to a deployed and running app and launches the developer tools of your Safari browser.
2121
* `--emulator` - Indicates that you want to debug your app in the iOS simulator.
2222
* `--no-client` - If set, the NativeScript CLI attaches the debug tools but does not launch the developer tools in Safari.
23+
* `--timeout` - Sets the number of seconds that NativeScript CLI will wait for the debugger to boot. If not set, the default timeout is 90 seconds.
2324

2425
### Attributes
2526
* `<Device ID>` is the index or name of the target device as listed by `$ tns device`

docs/man_pages/project/testing/livesync-ios.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ livesync ios
33

44
Usage | Synopsis
55
------|-------
6-
General | `$ tns livesync ios [--device <Device ID>] [--watch]`
6+
General | `$ tns livesync ios [--device <Device ID>] [--watch] [--emulator]`
77

8-
Synchronizes the latest changes in your project to iOS devices.
8+
Synchronizes the latest changes in your project to iOS devices or iOS simulator.
99

1010
### Options
1111
* `--watch` - If set, when you save changes to the project, changes are automatically synchronized to the connected device.
1212
* `--device` - Specifies the serial number or the index of the connected device to which you want to synchronize changes. To list all connected devices, grouped by platform, run `$ tns device`
13+
* `--emulator` - If set, changes are synchronized to iOS simulator.
1314

1415
### Attributes
1516
* `<Device ID>` is the device index or identifier as listed by `$ tns device`

lib/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase imple
2828
public CLIENT_NAME_ALIAS = "NativeScript";
2929
public ANALYTICS_API_KEY = "5752dabccfc54c4ab82aea9626b7338e";
3030
public TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage";
31+
public ERROR_REPORT_SETTING_NAME = "TrackExceptions";
3132
public ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID";
3233
public START_PACKAGE_ACTIVITY_NAME = "com.tns.NativeScriptActivity";
3334

lib/declarations.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface INpmInstallationManager {
1515
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
1616
getLatestVersion(packageName: string): IFuture<string>;
1717
getCachedPackagePath(packageName: string, version: string): string;
18+
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
1819
}
1920

2021
interface INpmInstallOptions {
@@ -56,6 +57,7 @@ interface IUsbLiveSyncService {
5657

5758
interface IPlatformSpecificUsbLiveSyncService {
5859
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
60+
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
5961
}
6062

6163
interface IOptions extends ICommonOptions {

lib/definitions/shelljs.d.ts

-8
This file was deleted.

lib/npm-installation-manager.ts

+50-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import semver = require("semver");
66
import npm = require("npm");
77
import constants = require("./constants");
88

9-
export class NpmInstallationManager {
9+
export class NpmInstallationManager implements INpmInstallationManager {
1010
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later.";
1111
private versionsCache: IDictionary<string[]>;
1212

@@ -27,13 +27,18 @@ export class NpmInstallationManager {
2727
public getCachedPackagePath(packageName: string, version: string): string {
2828
return path.join(this.getCacheRootPath(), packageName, version, "package");
2929
}
30-
30+
3131
public addToCache(packageName: string, version: string): IFuture<void> {
3232
return (() => {
33-
this.$npm.cache(packageName, version).wait();
34-
let packagePath = path.join(this.getCacheRootPath(), packageName, version, "package");
35-
if(!this.isPackageUnpacked(packagePath).wait()) {
36-
this.cacheUnpack(packageName, version).wait();
33+
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
34+
if(!this.$fs.exists(cachedPackagePath).wait()) {
35+
this.addToCacheCore(packageName, version).wait();
36+
}
37+
38+
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
39+
// In some cases the package is not fully downloaded and the framework directory is missing
40+
// Try removing the old package and add the real one to cache again
41+
this.addCleanCopyToCache(packageName, version).wait();
3742
}
3843
}).future<void>()();
3944
}
@@ -73,6 +78,43 @@ export class NpmInstallationManager {
7378
}).future<string>()();
7479
}
7580

81+
public addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
82+
return (() => {
83+
let packagePath = path.join(this.getCacheRootPath(), packageName, version);
84+
this.$logger.trace(`Deleting: ${packagePath}.`);
85+
this.$fs.deleteDirectory(packagePath).wait();
86+
this.addToCacheCore(packageName, version).wait();
87+
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
88+
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${version} to npm cache. Try cleaning your cache and execute the command again.`)
89+
}
90+
}).future<void>()();
91+
}
92+
93+
private addToCacheCore(packageName: string, version: string): IFuture<void> {
94+
return (() => {
95+
this.$npm.cache(packageName, version).wait();
96+
let packagePath = path.join(this.getCacheRootPath(), packageName, version, "package");
97+
if(!this.isPackageUnpacked(packagePath).wait()) {
98+
this.cacheUnpack(packageName, version).wait();
99+
}
100+
}).future<void>()();
101+
}
102+
103+
private isShasumOfPackageCorrect(packageName: string, version: string): IFuture<boolean> {
104+
return ((): boolean => {
105+
let shasumProperty = "dist.shasum";
106+
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
107+
let realShasum = this.$npm.view(`${packageName}@${version}`, shasumProperty).wait()[version][shasumProperty];
108+
let packageTgz = cachedPackagePath + ".tgz";
109+
let currentShasum = "";
110+
if(this.$fs.exists(packageTgz).wait()) {
111+
currentShasum = this.$fs.getFileShasum(packageTgz).wait();
112+
}
113+
this.$logger.trace(`Checking shasum of package: ${packageName}@${version}: expected ${realShasum}, actual ${currentShasum}.`);
114+
return realShasum === currentShasum;
115+
}).future<boolean>()();
116+
}
117+
76118
private installCore(packageName: string, pathToSave: string, version: string): IFuture<string> {
77119
return (() => {
78120
if (this.$options.frameworkPath) {
@@ -116,7 +158,8 @@ export class NpmInstallationManager {
116158
private isPackageUnpacked(packagePath: string): IFuture<boolean> {
117159
return (() => {
118160
return this.$fs.getFsStats(packagePath).wait().isDirectory() &&
119-
this.$fs.enumerateFilesInDirectorySync(packagePath).length > 1;
161+
this.$fs.exists(path.join(packagePath, "framework")).wait() &&
162+
this.$fs.enumerateFilesInDirectorySync(path.join(packagePath, "framework")).length > 1;
120163
}).future<boolean>()();
121164
}
122165
}

lib/options.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class Options extends commonOptionsLibPath.OptionsBase {
1818
copyFrom: { type: OptionType.String },
1919
linkTo: { type: OptionType.String },
2020
release: { type: OptionType.Boolean },
21-
emulator: { type: OptionType.Boolean },
2221
symlink: { type: OptionType.Boolean },
2322
forDevice: { type: OptionType.Boolean },
2423
client: { type: OptionType.Boolean, default: true},

lib/providers/device-app-data-provider.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase
2626
}
2727

2828
public get deviceProjectRootPath(): string {
29-
return `/data/local/tmp/12590FAA-5EDD-4B12-856D-F52A0A1599F2/${this.appIdentifier}`;
29+
let options: IOptions = $injector.resolve("options");
30+
let syncFolderName = options.watch ? "sync" : "fullsync";
31+
return `/data/local/tmp/${this.appIdentifier}/${syncFolderName}`;
3032
}
3133

3234
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {

lib/services/android-debug-service.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class AndroidDebugService implements IDebugService {
2424
private $hostInfo: IHostInfo,
2525
private $errors: IErrors,
2626
private $opener: IOpener,
27-
private $staticConfig: IStaticConfig) { }
27+
private $staticConfig: IStaticConfig,
28+
private $utils: IUtils,
29+
private $config: IConfiguration) { }
2830

2931
private get platform() { return "android"; }
3032

@@ -53,9 +55,12 @@ class AndroidDebugService implements IDebugService {
5355
return (() => {
5456
let packageFile = "";
5557

56-
if (this.$options.debugBrk) {
57-
this.$platformService.preparePlatform(this.platform).wait();
58+
if(!this.$options.debugBrk && !this.$options.start && !this.$options.getPort && !this.$options.stop) {
59+
this.$logger.warn("Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk.");
60+
this.$options.debugBrk = true;
61+
}
5862

63+
if (this.$options.debugBrk && !this.$options.emulator) {
5964
let cachedDeviceOption = this.$options.forDevice;
6065
this.$options.forDevice = true;
6166
this.$platformService.buildPlatform(this.platform).wait();
@@ -85,8 +90,6 @@ class AndroidDebugService implements IDebugService {
8590
this.detachDebugger(packageName).wait();
8691
} else if (this.$options.debugBrk) {
8792
this.startAppWithDebugger(packageFile, packageName).wait();
88-
} else {
89-
this.$logger.info("Should specify at least one option: debug-brk, start, stop, get-port.");
9093
}
9194
}).future<void>()();
9295
}
@@ -129,8 +132,10 @@ class AndroidDebugService implements IDebugService {
129132

130133
private startAppWithDebugger(packageFile: string, packageName: string): IFuture<void> {
131134
return (() => {
132-
this.device.applicationManager.uninstallApplication(packageName).wait();
133-
this.device.applicationManager.installApplication(packageFile).wait();
135+
if(!this.$options.emulator) {
136+
this.device.applicationManager.uninstallApplication(packageName).wait();
137+
this.device.applicationManager.installApplication(packageFile).wait();
138+
}
134139

135140
let port = this.$options.debugPort;
136141

@@ -168,7 +173,7 @@ class AndroidDebugService implements IDebugService {
168173
}
169174

170175
private openDebuggerClient(url: string): void {
171-
let chrome = this.$hostInfo.isDarwin ? "Google\ Chrome" : "chrome";
176+
let chrome = this.$hostInfo.isDarwin ? this.$config.ANDROID_DEBUG_UI_MAC : "chrome";
172177
let child = this.$opener.open(url, chrome);
173178
if(!child) {
174179
this.$errors.fail(`Unable to open ${chrome}.`);
@@ -195,8 +200,8 @@ class AndroidDebugService implements IDebugService {
195200
private startAndGetPort(packageName: string): IFuture<number> {
196201
return (() => {
197202
let port = -1;
198-
let timeout = 60;
199-
203+
let timeout = this.$utils.getParsedTimeout(90);
204+
200205
let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
201206
let envDebugInFullpath = packageDir + AndroidDebugService.ENV_DEBUG_IN_FILENAME;
202207
this.device.adb.executeShellCommand(`rm "${envDebugInFullpath}"`).wait();

lib/services/android-project-service.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import constants = require("../constants");
88
import helpers = require("../common/helpers");
99
import fs = require("fs");
1010
import os = require("os");
11+
import semver = require("semver");
1112

1213
import androidProjectPropertiesManagerLib = require("./android-project-properties-manager");
1314
import projectServiceBaseLib = require("./platform-project-service-base");
@@ -21,7 +22,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
2122
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
2223
private static ANDROID_PLATFORM_NAME = "android";
2324
private static LIBS_FOLDER_NAME = "libs";
24-
25+
private static MIN_JAVA_VERSION = "1.7.0";
2526

2627
private targetApi: string;
2728
private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;
@@ -35,6 +36,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
3536
private $options: IOptions,
3637
private $projectData: IProjectData,
3738
private $propertiesParser: IPropertiesParser,
39+
private $sysInfo: ISysInfo,
3840
$fs: IFileSystem) {
3941
super($fs);
4042
this._androidProjectPropertiesManagers = Object.create(null);
@@ -73,7 +75,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
7375
this.validatePackageName(this.$projectData.projectId);
7476
this.validateProjectName(this.$projectData.projectName);
7577

76-
this.checkAnt().wait() && this.checkAndroid().wait();
78+
this.checkJava().wait() && this.checkAnt().wait() && this.checkAndroid().wait();
7779
}).future<void>()();
7880
}
7981

@@ -478,6 +480,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
478480
return this.targetApi;
479481
}).future<string>()();
480482
}
483+
484+
private checkJava(): IFuture<void> {
485+
return (() => {
486+
try {
487+
let javaVersion = this.$sysInfo.getSysInfo().javaVer;
488+
if(semver.lt(javaVersion, AndroidProjectService.MIN_JAVA_VERSION)) {
489+
this.$errors.failWithoutHelp(`Your current java version is ${javaVersion}. NativeScript CLI needs at least ${AndroidProjectService.MIN_JAVA_VERSION} version to work correctly. Ensure that you have at least ${AndroidProjectService.MIN_JAVA_VERSION} java version installed and try again.`);
490+
}
491+
} catch(error) {
492+
this.$errors.failWithoutHelp("Error executing command 'java'. Make sure you have java installed and added to your PATH.");
493+
}
494+
}).future<void>()();
495+
}
481496

482497
private checkAnt(): IFuture<void> {
483498
return (() => {

0 commit comments

Comments
 (0)