Skip to content
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
30 changes: 21 additions & 9 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$logger.trace("Changes info in prepare platform:", changesInfo);

if (changesInfo.hasChanges) {
// android build artifacts need to be cleaned up when switching from release to debug builds
if (platform.toLowerCase() === "android") {
let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
// clean up prepared plugins when not building for release
if (previousPrepareInfo && previousPrepareInfo.release !== appFilesUpdaterOptions.release) {
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
}
}

await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData);
await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync);

this.$projectChangesService.savePrepareInfo(platform, projectData);
} else {
this.$logger.out("Skipping prepare.");
Expand All @@ -275,6 +268,25 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}
}

private async cleanProject(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformData: IPlatformData, projectData: IProjectData): Promise<void> {
// android build artifacts need to be cleaned up
// when switching between debug, release and webpack builds
if (platform.toLowerCase() !== "android") {
return;
}

const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
if (!previousPrepareInfo) {
return;
}

const { release: previousWasRelease, bundle: previousWasBundle } = previousPrepareInfo;
const { release: currentIsRelease, bundle: currentIsBundle } = appFilesUpdaterOptions;
if ((previousWasRelease !== currentIsRelease) || (previousWasBundle !== currentIsBundle)) {
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
}
}

/* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/
@helpers.hook('prepare')
private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions test/npm-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ async function setupProject(dependencies?: any): Promise<any> {
ensureConfigurationFileInAppResources: (): any => null,
interpolateConfigurationFile: (): void => undefined,
isPlatformPrepared: (projectRoot: string) => false,
validatePlugins: (projectData: IProjectData) => Promise.resolve()
validatePlugins: (projectData: IProjectData) => Promise.resolve(),
cleanProject: () => Promise.resolve(),
}
};
};
Expand Down Expand Up @@ -316,7 +317,7 @@ describe("Flatten npm modules tests", () => {
let gulpJshint = path.join(tnsModulesFolderPath, "gulp-jshint");
assert.isFalse(fs.exists(gulpJshint));

// Get all gulp dependencies
// Get all gulp dependencies
let gulpJsonContent = fs.readJson(path.join(projectFolder, nodeModulesFolderName, "gulp", packageJsonName));
_.each(_.keys(gulpJsonContent.dependencies), dependency => {
assert.isFalse(fs.exists(path.join(tnsModulesFolderPath, dependency)));
Expand Down