Skip to content

Commit 1f83014

Browse files
committed
Merge pull request #1070 from NativeScript/fatme/merge-release
Merge release
2 parents 859bacc + 1d55d75 commit 1f83014

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build android
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings]`
6+
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings] [--copy-to <File Path>]`
77

88
Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
99

@@ -15,8 +15,9 @@ Builds the project for Android and produces an APK that you can manually deploy
1515
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1616
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1717
* `--static-bindings` - **This is an experimental feature**. If set, generates static bindings from your JavaScript code to corresponding native Android APIs during build. This static bindings speed up app loading.[\*\*](#note)
18+
* `--copy-to` - Specifies the file path where the built `.apk` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
1819

19-
<% if(isHtml) { %><a id="note"></a><% } %>
20+
<% if(isHtml) { %><a id="note"></a><% } %>
2021
\*\* By default, NativeScript runtime for Android uses runtime binding generator. When you extend a Java class and overwrite a lot of methods, this could be a potentially slow operation.
2122

2223
### Attributes

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ build ios
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build ios [--for-device] [--release]`
6+
General | `$ tns build ios [--for-device] [--release] [--copy-to <File Path>]`
77

88
Builds the project for iOS and produces an `APP` or `IPA` that you can manually deploy in the iOS Simulator or on device, respectively.
99

10-
<% if(isConsole && (isWindows || isLinux)) { %>WARNING: You can run this command only on OS X systems. To view the complete help for this command, run `$ tns help build ios`<% } %>
11-
<% if((isConsole && isMacOS) || isHtml) { %>
12-
<% if(isHtml) { %>> <% } %>IMPORTANT: Before building for iOS device, verify that you have configured a valid pair of certificate and provisioning profile on your OS X system. <% if(isHtml) { %>For more information, see [Obtaining Signing Identities and Downloading Provisioning Profiles](https://developer.apple.com/library/mac/recipes/xcode_help-accounts_preferences/articles/obtain_certificates_and_provisioning_profiles.html).<% } %>
10+
<% if(isConsole && (isWindows || isLinux)) { %>WARNING: You can run this command only on OS X systems. To view the complete help for this command, run `$ tns help build ios`<% } %>
11+
<% if((isConsole && isMacOS) || isHtml) { %>
12+
<% if(isHtml) { %>> <% } %>IMPORTANT: Before building for iOS device, verify that you have configured a valid pair of certificate and provisioning profile on your OS X system. <% if(isHtml) { %>For more information, see [Obtaining Signing Identities and Downloading Provisioning Profiles](https://developer.apple.com/library/mac/recipes/xcode_help-accounts_preferences/articles/obtain_certificates_and_provisioning_profiles.html).<% } %>
1313

1414
### Options
1515
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
1616
* `--for-device` - If set, produces an application package that you can deploy on device. Otherwise, produces a build that you can run only in the native iOS Simulator.
17+
* `--copy-to` - Specifies the file path where the built `.ipa` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
1718
<% } %>
18-
<% if(isHtml) { %>
19+
<% if(isHtml) { %>
1920
### Command Limitations
2021

2122
* You can run `$ tns build ios` only on OS X systems.

lib/commands/build.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
"use strict";
33

44
export class BuildCommandBase {
5-
constructor(private $platformService: IPlatformService) { }
5+
constructor(protected $options: IOptions,
6+
private $platformService: IPlatformService) { }
67

78
executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
8-
return this.$platformService.buildPlatform(args[0], buildConfig);
9+
return (() => {
10+
let platform = args[0].toLowerCase();
11+
this.$platformService.buildPlatform(platform, buildConfig).wait();
12+
if(this.$options.copyTo) {
13+
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice}).wait();
14+
}
15+
}).future<void>()();
916
}
1017
}
1118

1219
export class BuildIosCommand extends BuildCommandBase implements ICommand {
13-
constructor($platformService: IPlatformService,
14-
private $platformsData: IPlatformsData) {
15-
super($platformService);
20+
constructor(protected $options: IOptions,
21+
private $platformsData: IPlatformsData,
22+
$platformService: IPlatformService) {
23+
super($options, $platformService);
1624
}
1725

1826
public allowedParameters: ICommandParameter[] = [];
@@ -24,11 +32,11 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
2432
$injector.registerCommand("build|ios", BuildIosCommand);
2533

2634
export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
27-
constructor($platformService: IPlatformService,
35+
constructor(protected $options: IOptions,
2836
private $platformsData: IPlatformsData,
29-
private $options: IOptions,
30-
private $errors: IErrors) {
31-
super($platformService);
37+
private $errors: IErrors,
38+
$platformService: IPlatformService) {
39+
super($options, $platformService);
3240
}
3341

3442
public execute(args: string[]): IFuture<void> {

lib/declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface IOptions extends ICommonOptions {
8282
tnsModulesVersion: string;
8383
staticBindings: boolean;
8484
compileSdk: number;
85+
copyTo: string;
8586
}
8687

8788
interface IProjectFilesManager {

lib/definitions/platform.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface IPlatformService {
1616

1717
getLatestApplicationPackageForDevice(platformData: IPlatformData): IFuture<IApplicationPackage>;
1818
getLatestApplicationPackageForEmulator(platformData: IPlatformData): IFuture<IApplicationPackage>;
19+
copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture<void>;
1920
}
2021

2122
interface IPlatformData {

lib/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3030
ignoreScripts: {type: OptionType.Boolean },
3131
tnsModulesVersion: { type: OptionType.String },
3232
staticBindings: {type: OptionType.Boolean},
33-
compileSdk: {type: OptionType.Number }
33+
compileSdk: {type: OptionType.Number },
34+
copyTo: { type: OptionType.String }
3435
},
3536
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
3637
$errors, $staticConfig);

lib/services/android-project-service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
3939
public get platformData(): IPlatformData {
4040
if (!this._platformData) {
4141
let projectRoot = path.join(this.$projectData.platformsDir, "android");
42-
42+
let packageName = this.getProjectNameFromId();
4343
this._platformData = {
4444
frameworkPackageName: "tns-android",
4545
normalizedPlatformName: "Android",
@@ -49,6 +49,8 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
4949
projectRoot: projectRoot,
5050
deviceBuildOutputPath: path.join(projectRoot, "build", "outputs", "apk"),
5151
validPackageNamesForDevice: [
52+
`${packageName}-debug.apk`,
53+
`${packageName}-release.apk`,
5254
`${this.$projectData.projectName}-debug.apk`,
5355
`${this.$projectData.projectName}-release.apk`
5456
],
@@ -143,11 +145,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
143145
shell.sed('-i', /__TITLE_ACTIVITY__/, this.$projectData.projectName, stringsFilePath);
144146

145147
let gradleSettingsFilePath = path.join(this.platformData.projectRoot, "settings.gradle");
146-
shell.sed('-i', /__PROJECT_NAME__/, this.$projectData.projectId.split(".")[2], gradleSettingsFilePath);
148+
shell.sed('-i', /__PROJECT_NAME__/, this.getProjectNameFromId(), gradleSettingsFilePath);
147149
shell.sed('-i', /__APILEVEL__/, this.$options.sdk || this.$androidToolsInfo.getToolsInfo().wait().compileSdkVersion.toString(), manifestPath);
148150
}).future<void>()();
149151
}
150152

153+
private getProjectNameFromId(): string {
154+
let id: string;
155+
if(this.$projectData && this.$projectData.projectId) {
156+
id = this.$projectData.projectId.split(".")[2];
157+
}
158+
159+
return id;
160+
}
161+
151162
public afterCreateProject(projectRoot: string): IFuture<void> {
152163
return Future.fromResult();
153164
}

lib/services/platform-service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,33 @@ export class PlatformService implements IPlatformService {
215215
}).future<void>()();
216216
}
217217

218+
public copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture<void> {
219+
return (() => {
220+
let packageFile: string;
221+
platform = platform.toLowerCase();
222+
targetPath = path.resolve(targetPath);
223+
let platformData = this.$platformsData.getPlatformData(platform);
224+
if (settings.isForDevice) {
225+
packageFile = this.getLatestApplicationPackageForDevice(platformData).wait().packageName;
226+
} else {
227+
packageFile = this.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
228+
}
229+
if(!packageFile || !this.$fs.exists(packageFile).wait()) {
230+
this.$errors.failWithoutHelp("Unable to find built application. Try 'tns build %s'.", platform);
231+
}
232+
233+
this.$fs.ensureDirectoryExists(path.dirname(targetPath)).wait();
234+
235+
if(this.$fs.exists(targetPath).wait() && this.$fs.getFsStats(targetPath).wait().isDirectory()) {
236+
let sourceFileName = path.basename(packageFile);
237+
this.$logger.trace(`Specified target path: '${targetPath}' is directory. Same filename will be used: '${sourceFileName}'.`);
238+
targetPath = path.join(targetPath, sourceFileName);
239+
}
240+
this.$fs.copyFile(packageFile, targetPath).wait();
241+
this.$logger.info(`Copied file '${packageFile}' to '${targetPath}'.`);
242+
}).future<void>()();
243+
}
244+
218245
public runPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
219246
return (() => {
220247
platform = platform.toLowerCase();

0 commit comments

Comments
 (0)