Skip to content

Commit cd08382

Browse files
author
IceBuildUser
committed
Merge remote-tracking branch 'origin/release' into HEAD
2 parents f134094 + 50b6685 commit cd08382

File tree

13 files changed

+136
-41
lines changed

13 files changed

+136
-41
lines changed

docs/man_pages/project/configuration/platform-add.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ platform add
33

44
Usage | Synopsis
55
------|-------
6-
Android latest runtime | `$ tns platform add android [--frameworkPath <File Path>] [--symlink] [--sdk <API Level>]`
7-
Android selected runtime | `$ tns platform add android[@<Version>] [--frameworkPath <File Path>] [--symlink] [--sdk <API Level>]`
8-
<% if (isMacOS) { %>iOS latest runtime | `$ tns platform add ios [--frameworkPath <File Path>] [--symlink]`
9-
iOS selected runtime | `$ tns platform add ios[@<Version>] [--frameworkPath <File Path>] [--symlink]`<% } %>
6+
Android latest runtime | `$ tns platform add android [--framework-path <File Path>] [--symlink] [--sdk <API Level>] [--platform-template <Platform Template>]`
7+
Android selected runtime | `$ tns platform add android[@<Version>] [--framework-path <File Path>] [--symlink] [--sdk <API Level>] [--platform-template <Platform Template>]`
8+
<% if (isMacOS) { %>iOS latest runtime | `$ tns platform add ios [--framework-path <File Path>] [--symlink]`
9+
iOS selected runtime | `$ tns platform add ios[@<Version>] [--framework-path <File Path>] [--symlink] [--platform-template <Platform Template>]`<% } %>
1010

11-
Configures the current project to target the selected platform. <% if(isHtml) { %>When you add a target platform, the NativeScript CLI adds a corresponding platform-specific subdirectory under the platforms directory. This platform-specific directory contains the necessary files to let you build your project for the target platform.<% } %>
11+
Configures the current project to target the selected platform. <% if(isHtml) { %>When you add a target platform, the NativeScript CLI creates a corresponding platform-specific subdirectory under the platforms directory. This platform-specific directory contains the necessary files to let you build your project for the target platform.<% } %>
1212

1313
### Options
14-
* `--frameworkPath` - Sets the path to a NativeScript runtime for the specified platform that you want to use instead of the default runtime. If `--symlink` is specified, `<File Path>` must point to directory in which the runtime is already extracted. If `--symlink` is not specified, `<File Path>` must point to a valid npm package.
14+
* `--framework-path` - Sets the path to a NativeScript runtime for the specified platform that you want to use instead of the default runtime. If `--symlink` is specified, `<File Path>` must point to directory in which the runtime is already extracted. If `--symlink` is not specified, `<File Path>` must point to a valid npm package.
1515
* `--symlink` - Creates a symlink to a NativeScript runtime for the specified platform that you want to use instead of the default runtime. If `--frameworkPath` is specified, creates a symlink to the specified directory. If `--frameworkPath` is not specified, creates a symlink to platform runtime installed with your current version of NativeScript.
1616
* `--sdk` - Sets the target Android SDK for the project.
17+
* `--platform-template` - Sets the platform template that will be used for the native application.
1718

1819
### Attributes
1920
* `<API Level>` is a valid Android API level. For example: 17, 19, MNC.<% if(isHtml) { %> For a complete list of the Android API levels and their corresponding Android versions, click [here](http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#platform).<% } %>
2021
* `<File Path>` is the complete path to a valid npm package or a directory that contains a NativeScript runtime for the selected platform.
21-
* `<Version>` is any available version of the respective platform runtime published in npm. <% if(isHtml) { %>If `@<Version>` is not specified, the NativeScript CLI installs the latest stable runtime for the selected platform.
22-
To list all available versions for Android, run `$ npm view tns-android versions`
23-
To list only experimental versions for Android, run `$ npm view tns-android dist-tags`
24-
To list all available versions for iOS, run `$ npm view tns-ios versions`
25-
To list only experimental versions for iOS, run `$ npm view tns-ios dist-tags`
22+
* `<Platform Template>` is a valid npm package, path to directory, .tgz or GitHub URL that contains a native Android or iOS template.
23+
* `<Version>` is any available version of the respective platform runtime published in npm. <% if(isHtml) { %>If `@<Version>` is not specified, the NativeScript CLI installs the latest stable runtime for the selected platform.
24+
To list all available versions for Android, run `$ npm view tns-android versions`
25+
To list only experimental versions for Android, run `$ npm view tns-android dist-tags`
26+
To list all available versions for iOS, run `$ npm view tns-ios versions`
27+
To list only experimental versions for iOS, run `$ npm view tns-ios dist-tags`
2628

2729
### Command Limitations
2830

lib/android-tools-info.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
99
private static ANDROID_TARGET_PREFIX = "android";
1010
private static SUPPORTED_TARGETS = ["android-17", "android-18", "android-19", "android-21", "android-22", "android-23"];
1111
private static MIN_REQUIRED_COMPILE_TARGET = 22;
12-
private static REQUIRED_BUILD_TOOLS_RANGE_PREFIX = ">=22";
12+
private static REQUIRED_BUILD_TOOLS_RANGE_PREFIX = ">=23";
1313
private static VERSION_REGEX = /((\d+\.){2}\d+)/;
1414
private static MIN_JAVA_VERSION = "1.7.0";
1515

@@ -156,30 +156,65 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
156156
}).future<boolean>()();
157157
}
158158

159-
public validateJavacVersion(installedJavaVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean> {
159+
public validateJava(javacVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean> {
160160
return ((): boolean => {
161-
let hasProblemWithJavaVersion = false;
162161
if(options) {
163162
this.showWarningsAsErrors = options.showWarningsAsErrors;
164163
}
165-
let additionalMessage = "You will not be able to build your projects for Android." + EOL
164+
165+
let helpfulMessage = "You will not be able to build your projects for Android." + EOL
166166
+ "To be able to build for Android, verify that you have installed The Java Development Kit (JDK) and configured it according to system requirements as" + EOL +
167167
" described in https://github.com/NativeScript/nativescript-cli#system-requirements.";
168-
let matchingVersion = (installedJavaVersion || "").match(AndroidToolsInfo.VERSION_REGEX);
169-
if(matchingVersion && matchingVersion[1]) {
170-
if(semver.lt(matchingVersion[1], AndroidToolsInfo.MIN_JAVA_VERSION)) {
171-
hasProblemWithJavaVersion = true;
172-
this.printMessage(`Javac version ${installedJavaVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, additionalMessage);
168+
169+
let hasProblemWithJavaHome = this.validateJavaHome(helpfulMessage).wait();
170+
let hasProblemWithJavaVersion: boolean;
171+
if(!hasProblemWithJavaHome) {
172+
hasProblemWithJavaVersion = this.validateJavacVersion(javacVersion, helpfulMessage);
173+
}
174+
175+
return hasProblemWithJavaHome || hasProblemWithJavaVersion;
176+
}).future<boolean>()();
177+
}
178+
179+
private validateJavaHome(helpfulMessage: string): IFuture<boolean> {
180+
return ((): boolean => {
181+
let hasProblemWithJavaHome = false;
182+
let javaHome = process.env.JAVA_HOME;
183+
184+
if(javaHome) {
185+
// validate jarsigner as it does not exist in JRE, but is mandatory for JDK and Android Runtime
186+
let jarSigner = path.join(javaHome, "bin", "jarsigner");
187+
let childProcessResult = this.$childProcess.spawnFromEvent(jarSigner, [], "close", {}, { throwError: false }).wait();
188+
this.$logger.trace(`Result of calling jarsigner from path: ${jarSigner}:`, childProcessResult);
189+
if(childProcessResult.stderr || childProcessResult.exitCode !== 0) {
190+
hasProblemWithJavaHome = true;
191+
this.printMessage("JAVA_HOME environment variable points to incorrect path. Make sure it points to the installation directory of JDK.", helpfulMessage);
173192
}
174193
} else {
175-
hasProblemWithJavaVersion = true;
176-
this.printMessage("Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.", additionalMessage);
194+
hasProblemWithJavaHome = true;
195+
this.printMessage("JAVA_HOME environment variable is not set.", helpfulMessage);
177196
}
178197

179-
return hasProblemWithJavaVersion;
198+
return hasProblemWithJavaHome;
180199
}).future<boolean>()();
181200
}
182201

202+
private validateJavacVersion(installedJavaVersion: string, helpfulMessage: string): boolean {
203+
let hasProblemWithJavaVersion = false;
204+
let matchingVersion = (installedJavaVersion || "").match(AndroidToolsInfo.VERSION_REGEX);
205+
if(matchingVersion && matchingVersion[1]) {
206+
if(semver.lt(matchingVersion[1], AndroidToolsInfo.MIN_JAVA_VERSION)) {
207+
hasProblemWithJavaVersion = true;
208+
this.printMessage(`Javac version ${installedJavaVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, helpfulMessage);
209+
}
210+
} else {
211+
hasProblemWithJavaVersion = true;
212+
this.printMessage("Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.", helpfulMessage);
213+
}
214+
215+
return hasProblemWithJavaVersion;
216+
}
217+
183218
public getPathToAdbFromAndroidHome(): IFuture<string> {
184219
return (() => {
185220
if(this.androidHome) {
@@ -278,7 +313,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
278313
selectedVersion = _.find(subDirs, dir => dir.indexOf(version) !== -1);
279314
}
280315
}
281-
316+
this.$logger.trace("Selected version is: ", selectedVersion);
282317
return selectedVersion;
283318
}).future<string>()();
284319
}

lib/common

lib/declarations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ interface IOptions extends ICommonOptions {
8383
port: Number;
8484
copyTo: string;
8585
baseConfig: string;
86+
platformTemplate: string;
8687
}
8788

8889
interface IInitService {
@@ -160,12 +161,12 @@ interface IAndroidToolsInfo {
160161
validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture<boolean>;
161162

162163
/**
163-
* Validates the information about required JAVA version.
164-
* @param {string} installedJavaVersion The JAVA version that will be checked.
164+
* Validates the information about required JAVA version and JAVA_HOME.
165+
* @param {string} javacVersion The JAVA version that will be checked.
165166
* @param {any} options Defines if the warning messages should treated as error.
166167
* @return {boolean} True if there are detected issues, false otherwise.
167168
*/
168-
validateJavacVersion(installedJavaVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean>;
169+
validateJava(javacVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean>;
169170

170171
/**
171172
* Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`.

lib/definitions/project.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ interface IiOSBuildConfig extends IBuildConfig {
6969
interface IPlatformProjectService {
7070
platformData: IPlatformData;
7171
validate(): IFuture<void>;
72-
createProject(frameworkDir: string, frameworkVersion: string): IFuture<void>;
72+
createProject(frameworkDir: string, frameworkVersion: string, pathToTemplate?: string): IFuture<void>;
7373
interpolateData(): IFuture<void>;
7474
interpolateConfigurationFile(configurationFilePath?: string): IFuture<void>;
7575
afterCreateProject(projectRoot: string): IFuture<void>;

lib/nativescript-cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as fiber from "fibers";
99
import Future = require("fibers/future");
1010
import * as shelljs from "shelljs";
1111
shelljs.config.silent = true;
12+
shelljs.config.fatal = true;
1213
import {installUncaughtExceptionListener} from "./common/errors";
1314
installUncaughtExceptionListener(process.exit);
1415

lib/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3434
compileSdk: {type: OptionType.Number },
3535
port: { type: OptionType.Number },
3636
copyTo: { type: OptionType.String },
37-
baseConfig: { type: OptionType.String }
37+
baseConfig: { type: OptionType.String },
38+
platformTemplate: { type: OptionType.String }
3839
},
3940
path.join($hostInfo.isWindows ? process.env.AppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
4041
$errors, $staticConfig);

lib/services/android-project-service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8888

8989
// this call will fail in case `android` is not set correctly.
9090
this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait();
91-
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
91+
this.$androidToolsInfo.validateJava(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
9292
}).future<void>()();
9393
}
9494

95-
public createProject(frameworkDir: string, frameworkVersion: string): IFuture<void> {
95+
public createProject(frameworkDir: string, frameworkVersion: string, pathToTemplate?: string): IFuture<void> {
9696
return (() => {
9797
if(semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
9898
this.$errors.failWithoutHelp(`The NativeScript CLI requires Android runtime ${AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE} or later to work properly.`);
@@ -111,7 +111,13 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
111111
}
112112

113113
// These files and directories should not be symlinked as CLI is modifying them and we'll change the original values as well.
114-
this.copy(this.platformData.projectRoot, frameworkDir, "src", "-R");
114+
if(pathToTemplate) {
115+
let mainPath = path.join(this.platformData.projectRoot, "src", "main");
116+
this.$fs.createDirectory(mainPath).wait();
117+
shell.cp("-R", path.join(path.resolve(pathToTemplate), "*"), mainPath);
118+
} else {
119+
this.copy(this.platformData.projectRoot, frameworkDir, "src", "-R");
120+
}
115121
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle gradle.properties", "-f");
116122

117123
if (this.useGradleWrapper(frameworkDir)) {

lib/services/doctor-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class DoctorService implements IDoctorService {
8787
}
8888

8989
let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait();
90-
let javaVersionIssue = this.$androidToolsInfo.validateJavacVersion(sysInfo.javacVersion).wait();
90+
let javaVersionIssue = this.$androidToolsInfo.validateJava(sysInfo.javacVersion).wait();
9191
return result || androidToolsIssues || javaVersionIssue;
9292
}
9393

lib/services/ios-project-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
104104
}).future<void>()();
105105
}
106106

107-
public createProject(frameworkDir: string, frameworkVersion: string): IFuture<void> {
107+
public createProject(frameworkDir: string, frameworkVersion: string, pathToTemplate?: string): IFuture<void> {
108108
return (() => {
109109
this.$fs.ensureDirectoryExists(path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)).wait();
110-
if(this.$options.symlink) {
110+
if(pathToTemplate) {
111+
// Copy everything except the template from the runtime
112+
this.$fs.readDirectory(frameworkDir).wait()
113+
.filter(dirName => dirName.indexOf(IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER) === -1)
114+
.forEach(dirName => shell.cp("-R", path.join(frameworkDir, dirName), this.platformData.projectRoot));
115+
shell.cp("-rf", path.join(pathToTemplate, "*"), this.platformData.projectRoot);
116+
} else if(this.$options.symlink) {
111117
let xcodeProjectName = util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER);
112118

113119
shell.cp("-R", path.join(frameworkDir, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER, "*"), path.join(this.platformData.projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER));
@@ -118,7 +124,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
118124
_.each(frameworkFiles, (file: string) => {
119125
this.$fs.symlink(path.join(frameworkDir, file), path.join(this.platformData.projectRoot, file)).wait();
120126
});
121-
122127
} else {
123128
shell.cp("-R", path.join(frameworkDir, "*"), this.platformData.projectRoot);
124129
}

0 commit comments

Comments
 (0)