diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index d3e22a8386..16088ce9df 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -7,7 +7,6 @@ import * as projectServiceBaseLib from "./platform-project-service-base"; import {DeviceAndroidDebugBridge} from "../common/mobile/android/device-android-debug-bridge"; import {AndroidDeviceHashService} from "../common/mobile/android/android-device-hash-service"; import {EOL} from "os"; -import { createGUID } from "../common/helpers"; export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService { private static VALUES_DIRNAME = "values"; @@ -307,31 +306,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject } public prepareProject(): IFuture { - return (() => { - let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait(); - let androidManifestPath = path.join(resDestinationDir, this.platformData.configurationFileName); - - // In case the file is not correct, looks like we are still using the default AndroidManifest.xml from runtime and the current file (in res dir) - // should be merged with it. - if (this.isAndroidManifestFileCorrect(androidManifestPath).wait()) { - // Delete the AndroidManifest.xml file from res directory as the runtime will consider it as addition to the one in src/main and will try to merge them. - // However now they are the same file. - this.$fs.deleteFile(androidManifestPath).wait(); - } - }).future()(); + return Future.fromResult(); } public ensureConfigurationFileInAppResources(): IFuture { return (() => { - let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName), - hasAndroidManifestInAppResources = this.$fs.exists(originalAndroidManifestFilePath).wait(), - shouldExtractDefaultManifest = !hasAndroidManifestInAppResources || !this.isAndroidManifestFileCorrect(originalAndroidManifestFilePath).wait(); - - // In case we should extract the manifest from default template, but for some reason we cannot, break the execution, - // so the original file from Android runtime will be used. - if (shouldExtractDefaultManifest && !this.extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath).wait()) { - return; - } + let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName); // Overwrite the AndroidManifest from runtime. this.$fs.copyFile(originalAndroidManifestFilePath, this.platformData.configurationFilePath).wait(); @@ -526,101 +506,5 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject }).future()(); } - - private isAndroidManifestFileCorrect(pathToAndroidManifest: string): IFuture { - return ((): boolean => { - try { - // Check if the AndroidManifest in app/App_Resouces is the correct one - // Use a real magic to detect if this is the correct file, by checking some mandatory strings. - let fileContent = this.$fs.readText(pathToAndroidManifest).wait(), - isFileCorrect = !!(~fileContent.indexOf("android:minSdkVersion") && ~fileContent.indexOf("android:targetSdkVersion") - && ~fileContent.indexOf("uses-permission") && ~fileContent.indexOf("") - && ~fileContent.indexOf("android.intent.action.MAIN") - && ~fileContent.indexOf("android:versionCode") - && !this.$xmlValidator.getXmlFileErrors(pathToAndroidManifest).wait()); - - this.$logger.trace(`Existing ${this.platformData.configurationFileName} is ${isFileCorrect ? "" : "NOT "}correct.`); - return isFileCorrect; - } catch (err) { - this.$logger.trace(`Error while checking ${pathToAndroidManifest}: `, err); - return false; - } - }).future()(); - } - - private _configurationFileBackupName: string; - - private getConfigurationFileBackupName(originalAndroidManifestFilePath: string): IFuture { - return (() => { - if (!this._configurationFileBackupName) { - let defaultBackupName = this.platformData.configurationFileName + ".backup"; - if (this.$fs.exists(path.join(path.dirname(originalAndroidManifestFilePath), defaultBackupName)).wait()) { - defaultBackupName += `_${createGUID(false)}`; - } - this._configurationFileBackupName = defaultBackupName; - } - - return this._configurationFileBackupName; - }).future()(); - } - - private backupOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture { - return (() => { - let newPathForOriginalManifest = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait()); - shell.mv(originalAndroidManifestFilePath, newPathForOriginalManifest); - }).future()(); - } - - private revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture { - return (() => { - let pathToBackupFile = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait()); - if (this.$fs.exists(pathToBackupFile).wait()) { - this.$logger.trace(`Could not extract ${this.platformData.configurationFileName} from default template. Reverting the change of your app/App_Resources/${this.platformData.configurationFileName}.`); - shell.mv(pathToBackupFile, originalAndroidManifestFilePath); - } - }).future()(); - } - - private extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath: string): IFuture { - return ((): boolean => { - let defaultTemplatePath = this.$projectTemplatesService.defaultTemplatePath.wait(); - let templateAndroidManifest = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName); - let alreadyHasAndroidManifest = this.$fs.exists(originalAndroidManifestFilePath).wait(); - if (this.$fs.exists(templateAndroidManifest).wait()) { - this.$logger.trace(`${originalAndroidManifestFilePath} is missing. Upgrading the source of the project with one from the new project template. Copy ${templateAndroidManifest} to ${originalAndroidManifestFilePath}`); - try { - if (alreadyHasAndroidManifest) { - this.backupOriginalAndroidManifest(originalAndroidManifestFilePath).wait(); - } - - let content = this.$fs.readText(templateAndroidManifest).wait(); - - // We do not want to force launch screens on old projects. - let themeMeta = ``; - content = content - .replace(`\n\t\t\tandroid:theme="@style/LaunchScreenTheme">\n`, `>\n\t\t\t\n`) - .replace(themeMeta, ""); - - this.$fs.writeFile(originalAndroidManifestFilePath, content).wait(); - } catch (e) { - this.$logger.trace(`Copying template's ${this.platformData.configurationFileName} failed. `, e); - this.revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath).wait(); - return false; - } - } else { - this.$logger.trace(`${originalAndroidManifestFilePath} is missing but the template ${templateAndroidManifest} is missing too, can not upgrade ${this.platformData.configurationFileName}.`); - return false; - } - - if (alreadyHasAndroidManifest) { - this.$logger.warn(`Your ${this.platformData.configurationFileName} in app/App_Resources/Android will be replaced by the default one from hello-world template.`); - this.$logger.printMarkdown(`The original file will be moved to \`${this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait()}\`. Merge it **manually** with the new \`${this.platformData.configurationFileName}\` in your app/App_Resources/Android.`); - } - - this.interpolateConfigurationFile().wait(); - return true; - }).future()(); - } } $injector.register("androidProjectService", AndroidProjectService); diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 698ff28076..1ad061442d 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -624,26 +624,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f ); } public ensureConfigurationFileInAppResources(): IFuture { - return (() => { - let infoPlistPath = this.getInfoPlistPath(); - if (!this.$fs.exists(infoPlistPath).wait()) { - // The project is missing Info.plist, try to populate it from the project template. - let projectTemplateService: IProjectTemplatesService = this.$injector.resolve("projectTemplatesService"); - let defaultTemplatePath = projectTemplateService.defaultTemplatePath.wait(); - let templateInfoPlist = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.iOS, this.platformData.configurationFileName); - if (this.$fs.exists(templateInfoPlist).wait()) { - this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing. Upgrading the source of the project with one from the new project template. Copy " + templateInfoPlist + " to " + infoPlistPath); - try { - this.$fs.copyFile(templateInfoPlist, infoPlistPath).wait(); - } catch (e) { - this.$logger.trace("Copying template's Info.plist failed. " + e); - } - } else { - this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing but the template " + templateInfoPlist + " is missing too, can not upgrade Info.plist."); - } - } - - }).future()(); + return Future.fromResult(); } private mergeInfoPlists(): IFuture { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 7300fc9efb..511a09f3af 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -259,12 +259,6 @@ export class PlatformService implements IPlatformService { sourceFiles = sourceFiles.filter(source => source.indexOf(testsFolderPath) === -1); } - let hasTnsModulesInAppFolder = this.$fs.exists(path.join(appSourceDirectoryPath, constants.TNS_MODULES_FOLDER_NAME)).wait(); - if (hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) { - this.$logger.warn("You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it."); - sourceFiles = sourceFiles.filter(source => !minimatch(source, `**/${constants.TNS_MODULES_FOLDER_NAME}/**`, { nocase: true })); - } - // verify .xml files are well-formed this.$xmlValidator.validateXmlFiles(sourceFiles).wait(); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index fc91f67fc6..14750d2298 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -124,17 +124,13 @@ export class PluginsService implements IPluginsService { } if (exists) { - this.$fs.ensureDirectoryExists(pluginDestinationPath).wait(); - shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath); - + //prepare platform speciffic files, .map and .ts files this.$projectFilesManager.processPlatformSpecificFiles(pluginDestinationPath, platform).wait(); + //deal with platforms/android folder in ns plugin pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform); platformData.platformProjectService.preparePluginNativeCode(pluginData).wait(); - shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, "platforms")); - // Remove node_modules of the plugin. The destination path should have flattened node_modules. - shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, constants.NODE_MODULES_FOLDER_NAME)); // Show message this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);