Skip to content

Commit 7211fc7

Browse files
Merge pull request #1067 from NativeScript/vladimirov/add-copyTo-option
Add --copy-to option to build command
2 parents fa6b00b + 14ef368 commit 7211fc7

File tree

7 files changed

+57
-17
lines changed

7 files changed

+57
-17
lines changed

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

+3-2
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

+6-5
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

+17-9
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

+1
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

+1
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

+2-1
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/platform-service.ts

+27
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)