diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 56604202c9..bfecc6f763 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -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 { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index dd4d1ff697..149fec0188 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -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 { diff --git a/lib/services/platform/prepare-native-platform-service.ts b/lib/services/platform/prepare-native-platform-service.ts index b017932d70..2e5ed21b88 100644 --- a/lib/services/platform/prepare-native-platform-service.ts +++ b/lib/services/platform/prepare-native-platform-service.ts @@ -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, @@ -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); @@ -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 { // android build artifacts need to be cleaned up // when switching between debug, release and webpack builds diff --git a/lib/services/webpack/webpack.d.ts b/lib/services/webpack/webpack.d.ts index d58c7978ac..86617fee0f 100644 --- a/lib/services/webpack/webpack.d.ts +++ b/lib/services/webpack/webpack.d.ts @@ -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 /platforms/ dir exists). diff --git a/test/stubs.ts b/test/stubs.ts index a1ba362197..74fe81c052 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -425,7 +425,7 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): Promise { return Promise.resolve(true); } - prepareAppResources(appResourcesDirectoryPath: string): void { } + prepareAppResources(projectData: IProjectData): void { } async preparePluginNativeCode(pluginData: IPluginData): Promise { return Promise.resolve();