Skip to content

Implement command line option to run static bindings generator #843

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

Merged
merged 1 commit into from
Sep 1, 2015
Merged
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
4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

3 changes: 2 additions & 1 deletion docs/man_pages/project/testing/build-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build android

Usage | Synopsis
---|---
General | `$ tns build android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release]`
General | `$ tns build android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings]`

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

Expand All @@ -13,6 +13,7 @@ Builds the project for Android and produces an APK that you can manually deploy
* `--key-store-password` - Provides the password 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.
* `--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.
* `--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.
* `--static-bindings` - If set, generates static bindings from your JavaScript code to corresponding native Android APIs during build. This static bindings speed up app loading.

<% if(isHtml) { %>
### Related Commands
Expand Down
14 changes: 8 additions & 6 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
export class BuildCommandBase {
constructor(private $platformService: IPlatformService) { }

executeCore(args: string[]): IFuture<void> {
return this.$platformService.buildPlatform(args[0]);
executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
return this.$platformService.buildPlatform(args[0], buildConfig);
}
}

Expand All @@ -25,14 +25,16 @@ $injector.registerCommand("build|ios", BuildIosCommand);

export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
constructor($platformService: IPlatformService,
private $platformsData: IPlatformsData) {
private $platformsData: IPlatformsData,
private $options: IOptions) {
super($platformService);
}

public allowedParameters: ICommandParameter[] = [];

public execute(args: string[]): IFuture<void> {
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let config: IBuildConfig = {runSbGenerator: this.$options.staticBindings};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to move around empty objects unless really needed.

return this.executeCore([this.$platformsData.availablePlatforms.Android], config);
}

public allowedParameters: ICommandParameter[] = [];
}
$injector.registerCommand("build|android", BuildAndroidCommand);
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface IOptions extends ICommonOptions {
sdk: string;
ignoreScripts: boolean;
tnsModulesVersion: string;
staticBindings: boolean;
}

interface IProjectFilesManager {
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IPlatformService {
updatePlatforms(platforms: string[]): IFuture<void>;
runPlatform(platform: string): IFuture<void>;
preparePlatform(platform: string): IFuture<void>;
buildPlatform(platform: string): IFuture<void>;
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
deployOnDevice(platform: string): IFuture<void>;
deployOnEmulator(platform: string): IFuture<void>;
validatePlatformInstalled(platform: string): void;
Expand Down
6 changes: 5 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ interface IPlatformProjectServiceBase {
getPluginPlatformsFolderPath(pluginData: IPluginData, platform: string): string;
}

interface IBuildConfig {
runSbGenerator?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why runSbGenerator is not mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is still experimental option. Once we prove it is stable, we will switch it to be on by default - possibly for {N} 1.4.

}

interface IPlatformProjectService {
platformData: IPlatformData;
validate(): IFuture<void>;
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
interpolateData(projectRoot: string): IFuture<void>;
afterCreateProject(projectRoot: string): IFuture<void>;
buildProject(projectRoot: string): IFuture<void>;
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
prepareProject(): IFuture<void>;
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
Expand Down
3 changes: 2 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
keyStoreAliasPassword: { type: OptionType.String },
sdk: { type: OptionType.String },
ignoreScripts: {type: OptionType.Boolean },
tnsModulesVersion: { type: OptionType.String }
tnsModulesVersion: { type: OptionType.String },
staticBindings: {type: OptionType.Boolean}
},
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
$errors, $staticConfig);
Expand Down
6 changes: 5 additions & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
return Future.fromResult();
}

public buildProject(projectRoot: string): IFuture<void> {
public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
return (() => {
if(this.canUseGradle().wait()) {
let buildOptions = ["buildapk", `-PcompileSdk=${this.getAndroidTarget().wait()}`];
Expand All @@ -187,6 +187,10 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`);
}

if (buildConfig && buildConfig.runSbGenerator) {
buildOptions.push("-PrunSBGenerator");
}

this.spawn("gradle", buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
} else {
this.checkAnt().wait();
Expand Down
4 changes: 2 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ export class PlatformService implements IPlatformService {
}).future<void>()();
}

public buildPlatform(platform: string): IFuture<void> {
public buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
return (() => {
platform = platform.toLowerCase();
this.preparePlatform(platform).wait();

let platformData = this.$platformsData.getPlatformData(platform);
platformData.platformProjectService.buildProject(platformData.projectRoot).wait();
platformData.platformProjectService.buildProject(platformData.projectRoot, buildConfig).wait();
this.$logger.out("Project successfully built");
}).future<void>()();
}
Expand Down