Skip to content

Commit d0ab68d

Browse files
Mitko-Kerezovrosen-vladimirov
authored andcommitted
Clean app directory when bundle flag is switched (#3265)
When switching the value of `--bundle` (i.e. passing it or not passing it) between two builds the latter build should clear the app directory inside platforms prior to building.
1 parent da9e146 commit d0ab68d

8 files changed

+32
-28
lines changed

lib/commands/clean-app.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ export class CleanAppCommandBase implements ICommand {
1515

1616
public async execute(args: string[]): Promise<void> {
1717
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
18-
return this.$platformService.cleanDestinationApp(this.platform.toLowerCase(), appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
18+
const platformInfo: IPreparePlatformInfo = {
19+
appFilesUpdaterOptions,
20+
platform: this.platform.toLowerCase(),
21+
config: this.$options,
22+
platformTemplate: this.$options.platformTemplate,
23+
projectData: this.$projectData,
24+
env: this.$options.env
25+
};
26+
27+
return this.$platformService.cleanDestinationApp(platformInfo);
1928
}
2029

2130
public async canExecute(args: string[]): Promise<boolean> {

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
115115
*/
116116
startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string): Promise<void>;
117117

118-
cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void>;
118+
cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void>;
119119
validatePlatformInstalled(platform: string, projectData: IProjectData): void;
120120

121121
/**

lib/definitions/project-changes.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IProjectChangesInfo extends IAddedNativePlatform {
1515
configChanged: boolean;
1616
packageChanged: boolean;
1717
nativeChanged: boolean;
18+
bundleChanged: boolean;
1819
signingChanged: boolean;
1920

2021
readonly hasChanges: boolean;

lib/services/app-files-updater.ts

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ export class AppFilesUpdater {
2121
}
2222

2323
public cleanDestinationApp(): void {
24-
if (this.options.bundle) {
25-
//Assuming an the bundle has updated the dest folder already.
26-
//Skip cleaning up completely.
27-
return;
28-
}
29-
3024
// Delete the destination app in order to prevent EEXIST errors when symlinks are used.
3125
let destinationAppContents = this.readDestinationDir();
3226
destinationAppContents = destinationAppContents.filter(

lib/services/platform-service.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
194194
const requiresNativePrepare = (!platformInfo.nativePrepare || !platformInfo.nativePrepare.skipNativePrepare) && changesInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPrepare;
195195

196196
if (changesInfo.hasChanges || platformInfo.appFilesUpdaterOptions.bundle || requiresNativePrepare) {
197+
if (changesInfo.bundleChanged) {
198+
await this.cleanDestinationApp(platformInfo);
199+
}
200+
197201
await this.preparePlatformCore(
198202
platformInfo.platform,
199203
platformInfo.appFilesUpdaterOptions,
@@ -553,13 +557,13 @@ export class PlatformService extends EventEmitter implements IPlatformService {
553557
return null;
554558
}
555559

556-
public async cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void> {
557-
await this.ensurePlatformInstalled(platform, platformTemplate, projectData, config);
560+
public async cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void> {
561+
await this.ensurePlatformInstalled(platformInfo.platform, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config);
558562

559-
const appSourceDirectoryPath = path.join(projectData.projectDir, constants.APP_FOLDER_NAME);
560-
const platformData = this.$platformsData.getPlatformData(platform, projectData);
563+
const appSourceDirectoryPath = path.join(platformInfo.projectData.projectDir, constants.APP_FOLDER_NAME);
564+
const platformData = this.$platformsData.getPlatformData(platformInfo.platform, platformInfo.projectData);
561565
const appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
562-
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, appFilesUpdaterOptions, this.$fs);
566+
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, platformInfo.appFilesUpdaterOptions, this.$fs);
563567
appUpdater.cleanDestinationApp();
564568
}
565569

lib/services/project-changes-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ProjectChangesInfo implements IProjectChangesInfo {
1212
public configChanged: boolean;
1313
public packageChanged: boolean;
1414
public nativeChanged: boolean;
15+
public bundleChanged: boolean;
1516
public signingChanged: boolean;
1617
public nativePlatformStatus: NativePlatformStatus;
1718

@@ -93,6 +94,7 @@ export class ProjectChangesService implements IProjectChangesService {
9394
this._changesInfo.appFilesChanged = true;
9495
this._changesInfo.appResourcesChanged = true;
9596
this._changesInfo.modulesChanged = true;
97+
this._changesInfo.bundleChanged = true;
9698
this._changesInfo.configChanged = true;
9799
this._prepareInfo.release = projectChangesOptions.release;
98100
this._prepareInfo.bundle = projectChangesOptions.bundle;

test/app-files-updates.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@ describe("App files cleanup", () => {
2727
}
2828
}
2929

30-
it("cleans up entire app when not bundling", () => {
31-
const updater = new CleanUpAppFilesUpdater([
32-
"file1", "dir1/file2", "App_Resources/Android/blah.png"
33-
], { bundle: false });
34-
updater.clean();
35-
assert.deepEqual(["file1", "dir1/file2", "App_Resources/Android/blah.png"], updater.deletedDestinationItems);
36-
});
37-
38-
it("does not clean up destination when bundling", () => {
39-
const updater = new CleanUpAppFilesUpdater([
40-
"file1", "dir1/file2", "App_Resources/Android/blah.png"
41-
], { bundle: true });
42-
updater.clean();
43-
assert.deepEqual([], updater.deletedDestinationItems);
30+
_.each([true, false], bundle => {
31+
it(`cleans up entire app when bundle is ${bundle}`, () => {
32+
const updater = new CleanUpAppFilesUpdater([
33+
"file1", "dir1/file2", "App_Resources/Android/blah.png"
34+
], { bundle });
35+
updater.clean();
36+
assert.deepEqual(["file1", "dir1/file2", "App_Resources/Android/blah.png"], updater.deletedDestinationItems);
37+
});
4438
});
4539
});
4640

test/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
678678
return Promise.resolve();
679679
}
680680

681-
public cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string): Promise<void> {
681+
public cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void> {
682682
return Promise.resolve();
683683
}
684684

0 commit comments

Comments
 (0)