Skip to content

fix: respect App_Resources directly from project #4657

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
May 31, 2019
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
20 changes: 18 additions & 2 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,24 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}
}

public prepareAppResources(appResourcesDirectoryPath: string, projectData: IProjectData): void {
this.cleanUpPreparedResources(appResourcesDirectoryPath, projectData);
public prepareAppResources(projectData: IProjectData): void {
const platformData = this.getPlatformData(projectData);
const projectAppResourcesPath = projectData.getAppResourcesDirectoryPath(projectData.projectDir);
const platformsAppResourcesPath = this.getAppResourcesDestinationDirectoryPath(projectData);

this.cleanUpPreparedResources(projectAppResourcesPath, projectData);

this.$fs.ensureDirectoryExists(platformsAppResourcesPath);

this.$fs.copyFile(path.join(projectAppResourcesPath, platformData.normalizedPlatformName, "*"), platformsAppResourcesPath);
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(projectAppResourcesPath);
if (appResourcesDirStructureHasMigrated) {
this.$fs.copyFile(path.join(projectAppResourcesPath, platformData.normalizedPlatformName, "src", "*"), platformsAppResourcesPath);
} else {
// https://github.com/NativeScript/android-runtime/issues/899
// App_Resources/Android/libs is reserved to user's aars and jars, but they should not be copied as resources
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, "libs"));
}
}

public async preparePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> {
Expand Down
25 changes: 14 additions & 11 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,23 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}
}

public prepareAppResources(appResourcesDirectoryPath: string, projectData: IProjectData): void {
const platformFolder = path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName);
const filterFile = (filename: string) => this.$fs.deleteFile(path.join(platformFolder, filename));
public prepareAppResources(projectData: IProjectData): void {
const platformData = this.getPlatformData(projectData);
const projectAppResourcesPath = projectData.getAppResourcesDirectoryPath(projectData.projectDir);
const platformsAppResourcesPath = this.getAppResourcesDestinationDirectoryPath(projectData);

this.$fs.deleteDirectory(platformsAppResourcesPath);
this.$fs.ensureDirectoryExists(platformsAppResourcesPath);

filterFile(this.getPlatformData(projectData).configurationFileName);
filterFile(constants.PODFILE_NAME);
this.$fs.copyFile(path.join(projectAppResourcesPath, platformData.normalizedPlatformName, "*"), platformsAppResourcesPath);

// src folder should not be copied as the pbxproject will have references to its files
this.$fs.deleteDirectory(path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, constants.NATIVE_SOURCE_FOLDER));
this.$fs.deleteDirectory(path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, constants.NATIVE_EXTENSION_FOLDER));
this.$fs.deleteDirectory(path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, "watchapp"));
this.$fs.deleteDirectory(path.join(appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, "watchextension"));
this.$fs.deleteFile(path.join(platformsAppResourcesPath, platformData.configurationFileName));
this.$fs.deleteFile(path.join(platformsAppResourcesPath, constants.PODFILE_NAME));

this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath(projectData));
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, constants.NATIVE_SOURCE_FOLDER));
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, constants.NATIVE_EXTENSION_FOLDER));
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, "watchapp"));
this.$fs.deleteDirectory(path.join(platformsAppResourcesPath, "watchextension"));
}

public async processConfigurationFilesFromAppResources(projectData: IProjectData, opts: IRelease): Promise<void> {
Expand Down
47 changes: 2 additions & 45 deletions lib/services/platform/prepare-native-platform-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@

import { hook } from "../../common/helpers";
import { performanceLog } from "../../common/decorators";
import * as path from "path";
import { NativePlatformStatus, APP_FOLDER_NAME, APP_RESOURCES_FOLDER_NAME } from "../../constants";
import { NativePlatformStatus } from "../../constants";

export class PrepareNativePlatformService implements IPrepareNativePlatformService {

constructor(
private $androidResourcesMigrationService: IAndroidResourcesMigrationService,
private $fs: IFileSystem,
public $hooksService: IHooksService,
private $nodeModulesBuilder: INodeModulesBuilder,
private $projectChangesService: IProjectChangesService,
Expand All @@ -34,10 +31,7 @@ export class PrepareNativePlatformService implements IPrepareNativePlatformServi
await this.cleanProject(platformData, projectData, { release });
}

// Move the native application resources from platforms/.../app/App_Resources
// to the right places in the native project,
// because webpack copies them on every build (not every change).
this.prepareAppResources(platformData, projectData);
platformData.platformProjectService.prepareAppResources(projectData);

if (hasChangesRequirePrepare) {
await platformData.platformProjectService.prepareProject(projectData, prepareData);
Expand All @@ -58,43 +52,6 @@ export class PrepareNativePlatformService implements IPrepareNativePlatformServi
return hasChanges;
}

private prepareAppResources(platformData: IPlatformData, projectData: IProjectData): void {
const appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
const appResourcesDestinationDirectoryPath = path.join(appDestinationDirectoryPath, APP_RESOURCES_FOLDER_NAME);

if (this.$fs.exists(appResourcesDestinationDirectoryPath)) {
platformData.platformProjectService.prepareAppResources(appResourcesDestinationDirectoryPath, projectData);
const appResourcesDestination = platformData.platformProjectService.getAppResourcesDestinationDirectoryPath(projectData);
this.$fs.ensureDirectoryExists(appResourcesDestination);

if (platformData.normalizedPlatformName.toLowerCase() === "android") {
const appResourcesDirectoryPath = projectData.getAppResourcesDirectoryPath();
const appResourcesDirStructureHasMigrated = this.$androidResourcesMigrationService.hasMigrated(appResourcesDirectoryPath);
const appResourcesAndroid = path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName);

if (appResourcesDirStructureHasMigrated) {
this.$fs.copyFile(path.join(appResourcesAndroid, "src", "*"), appResourcesDestination);

this.$fs.deleteDirectory(appResourcesDestinationDirectoryPath);
return;
}

// https://github.com/NativeScript/android-runtime/issues/899
// App_Resources/Android/libs is reserved to user's aars and jars, but they should not be copied as resources
this.$fs.copyFile(path.join(appResourcesDestinationDirectoryPath, platformData.normalizedPlatformName, "*"), appResourcesDestination);
this.$fs.deleteDirectory(path.join(appResourcesDestination, "libs"));

this.$fs.deleteDirectory(appResourcesDestinationDirectoryPath);

return;
}

this.$fs.copyFile(path.join(appResourcesDestinationDirectoryPath, platformData.normalizedPlatformName, "*"), appResourcesDestination);

this.$fs.deleteDirectory(appResourcesDestinationDirectoryPath);
}
}

private async cleanProject(platformData: IPlatformData, projectData: IProjectData, options: { release: boolean }): Promise<void> {
// android build artifacts need to be cleaned up
// when switching between debug, release and webpack builds
Expand Down
2 changes: 1 addition & 1 deletion lib/services/webpack/webpack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ declare global {
* @param {IProjectData} projectData DTO with information about the project.
* @returns {void}
*/
prepareAppResources(appResourcesDirectoryPath: string, projectData: IProjectData): void;
prepareAppResources(projectData: IProjectData): void;

/**
* Defines if current platform is prepared (i.e. if <project dir>/platforms/<platform> dir exists).
Expand Down
2 changes: 1 addition & 1 deletion test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): Promise<boolean> {
return Promise.resolve(true);
}
prepareAppResources(appResourcesDirectoryPath: string): void { }
prepareAppResources(projectData: IProjectData): void { }

async preparePluginNativeCode(pluginData: IPluginData): Promise<void> {
return Promise.resolve();
Expand Down