From bc9d2427a5cff81b0f236211803b89d05f15afac Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 21 Feb 2018 15:53:11 +0200 Subject: [PATCH] feat(sidekick): Support for clean option in Sidekick when executing local builds * Expose cleanNativeApp method for Sidekick * Fix run, deploy and build commands when clean option is specified * Fix help of build and deploy commands --- docs/man_pages/project/testing/build-android.md | 1 + docs/man_pages/project/testing/deploy.md | 1 + lib/commands/build.ts | 1 - lib/common | 2 +- lib/definitions/project.d.ts | 8 ++++++++ lib/services/local-build-service.ts | 10 +++++++++- lib/services/platform-service.ts | 4 ++++ 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/man_pages/project/testing/build-android.md b/docs/man_pages/project/testing/build-android.md index f86ee1cb3a..785e3b683f 100644 --- a/docs/man_pages/project/testing/build-android.md +++ b/docs/man_pages/project/testing/build-android.md @@ -13,6 +13,7 @@ Builds the project for Android and produces an APK that you can manually deploy ### Options * `--compileSdk` - Sets the Android SDK that will be used to build the project. +* `--clean` - If set, forces rebuilding the native application. * `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options. * `--key-store-path` - Specifies the file path to the keystore file (P12) which you want to use to code sign your APK. 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-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. diff --git a/docs/man_pages/project/testing/deploy.md b/docs/man_pages/project/testing/deploy.md index 9904acda68..4474cf5ebf 100644 --- a/docs/man_pages/project/testing/deploy.md +++ b/docs/man_pages/project/testing/deploy.md @@ -21,6 +21,7 @@ Prepares, builds and deploys the project to a connected physical or virtual devi ### Options<% if(isMacOS) { %> for Android<% } %> * `--device` - Deploys the project on the specified connected physical or virtual device. +* `--clean` - If set, forces rebuilding the native application. * `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options. * `--key-store-path` - Specifies the file path to the keystore file (P12) which you want to use to code sign your APK. 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-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. diff --git a/lib/commands/build.ts b/lib/commands/build.ts index ae5208cbf9..34ea2c9251 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -26,7 +26,6 @@ export class BuildCommandBase extends BundleBase { }; await this.$platformService.preparePlatform(platformInfo); - this.$options.clean = true; const buildConfig: IBuildConfig = { buildForDevice: this.$options.forDevice, projectDir: this.$options.path, diff --git a/lib/common b/lib/common index c3d02f3f5f..262dbdf2f0 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit c3d02f3f5f3858b7647a751eb501010eabd609f9 +Subproject commit 262dbdf2f035f067c8321b743fb1f91704c18495 diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index c4d3607321..671e8e59d6 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -167,8 +167,16 @@ interface ILocalBuildService { * @return {Promise} Path to the build output. */ build(platform: string, platformBuildOptions: IPlatformBuildData, platformTemplate?: string): Promise; + /** + * Removes build artifacts specific to the platform + * @param {ICleanNativeAppData} data Data describing the clean app process + * @returns {void} + */ + cleanNativeApp(data: ICleanNativeAppData): Promise; } +interface ICleanNativeAppData extends IProjectDir, IPlatform { } + interface IPlatformProjectService extends NodeJS.EventEmitter { getPlatformData(projectData: IProjectData): IPlatformData; validate(projectData: IProjectData): Promise; diff --git a/lib/services/local-build-service.ts b/lib/services/local-build-service.ts index 7b8fe95465..b33f49051d 100644 --- a/lib/services/local-build-service.ts +++ b/lib/services/local-build-service.ts @@ -6,7 +6,9 @@ export class LocalBuildService extends EventEmitter implements ILocalBuildServic constructor(private $projectData: IProjectData, private $mobileHelper: Mobile.IMobileHelper, private $errors: IErrors, - private $platformService: IPlatformService) { + private $platformsData: IPlatformsData, + private $platformService: IPlatformService, + private $projectDataService: IProjectDataService) { super(); } @@ -41,6 +43,12 @@ export class LocalBuildService extends EventEmitter implements ILocalBuildServic await attachAwaitDetach(BUILD_OUTPUT_EVENT_NAME, this.$platformService, handler, this.$platformService.buildPlatform(platform, platformBuildOptions, this.$projectData)); return this.$platformService.lastOutputPath(platform, platformBuildOptions, this.$projectData); } + + public async cleanNativeApp(data: ICleanNativeAppData): Promise { + const projectData = this.$projectDataService.getProjectData(data.projectDir); + const platformData = this.$platformsData.getPlatformData(data.platform, projectData); + await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData); + } } $injector.register("localBuildService", LocalBuildService); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index ad0d3797f7..ce224ff3b6 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -388,6 +388,10 @@ export class PlatformService extends EventEmitter implements IPlatformService { }); const platformData = this.$platformsData.getPlatformData(platform, projectData); + if (buildConfig.clean) { + await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData); + } + const handler = (data: any) => { this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data); this.$logger.printInfoMessageOnSameLine(data.data.toString());