Skip to content

Commit e0738f9

Browse files
authored
Merge pull request #2099 from NativeScript/plamen5kov/cli_refactor
removing unnecessary functionality
2 parents 628f949 + 72f1dd8 commit e0738f9

File tree

4 files changed

+5
-150
lines changed

4 files changed

+5
-150
lines changed

lib/services/android-project-service.ts

+2-118
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as projectServiceBaseLib from "./platform-project-service-base";
77
import {DeviceAndroidDebugBridge} from "../common/mobile/android/device-android-debug-bridge";
88
import {AndroidDeviceHashService} from "../common/mobile/android/android-device-hash-service";
99
import {EOL} from "os";
10-
import { createGUID } from "../common/helpers";
1110

1211
export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1312
private static VALUES_DIRNAME = "values";
@@ -307,31 +306,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
307306
}
308307

309308
public prepareProject(): IFuture<void> {
310-
return (() => {
311-
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
312-
let androidManifestPath = path.join(resDestinationDir, this.platformData.configurationFileName);
313-
314-
// 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)
315-
// should be merged with it.
316-
if (this.isAndroidManifestFileCorrect(androidManifestPath).wait()) {
317-
// 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.
318-
// However now they are the same file.
319-
this.$fs.deleteFile(androidManifestPath).wait();
320-
}
321-
}).future<void>()();
309+
return Future.fromResult();
322310
}
323311

324312
public ensureConfigurationFileInAppResources(): IFuture<void> {
325313
return (() => {
326-
let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName),
327-
hasAndroidManifestInAppResources = this.$fs.exists(originalAndroidManifestFilePath).wait(),
328-
shouldExtractDefaultManifest = !hasAndroidManifestInAppResources || !this.isAndroidManifestFileCorrect(originalAndroidManifestFilePath).wait();
329-
330-
// In case we should extract the manifest from default template, but for some reason we cannot, break the execution,
331-
// so the original file from Android runtime will be used.
332-
if (shouldExtractDefaultManifest && !this.extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath).wait()) {
333-
return;
334-
}
314+
let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName);
335315

336316
// Overwrite the AndroidManifest from runtime.
337317
this.$fs.copyFile(originalAndroidManifestFilePath, this.platformData.configurationFilePath).wait();
@@ -526,101 +506,5 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
526506

527507
}).future<void>()();
528508
}
529-
530-
private isAndroidManifestFileCorrect(pathToAndroidManifest: string): IFuture<boolean> {
531-
return ((): boolean => {
532-
try {
533-
// Check if the AndroidManifest in app/App_Resouces is the correct one
534-
// Use a real magic to detect if this is the correct file, by checking some mandatory strings.
535-
let fileContent = this.$fs.readText(pathToAndroidManifest).wait(),
536-
isFileCorrect = !!(~fileContent.indexOf("android:minSdkVersion") && ~fileContent.indexOf("android:targetSdkVersion")
537-
&& ~fileContent.indexOf("uses-permission") && ~fileContent.indexOf("<application")
538-
&& ~fileContent.indexOf("<activity") && ~fileContent.indexOf("<intent-filter>")
539-
&& ~fileContent.indexOf("android.intent.action.MAIN")
540-
&& ~fileContent.indexOf("android:versionCode")
541-
&& !this.$xmlValidator.getXmlFileErrors(pathToAndroidManifest).wait());
542-
543-
this.$logger.trace(`Existing ${this.platformData.configurationFileName} is ${isFileCorrect ? "" : "NOT "}correct.`);
544-
return isFileCorrect;
545-
} catch (err) {
546-
this.$logger.trace(`Error while checking ${pathToAndroidManifest}: `, err);
547-
return false;
548-
}
549-
}).future<boolean>()();
550-
}
551-
552-
private _configurationFileBackupName: string;
553-
554-
private getConfigurationFileBackupName(originalAndroidManifestFilePath: string): IFuture<string> {
555-
return (() => {
556-
if (!this._configurationFileBackupName) {
557-
let defaultBackupName = this.platformData.configurationFileName + ".backup";
558-
if (this.$fs.exists(path.join(path.dirname(originalAndroidManifestFilePath), defaultBackupName)).wait()) {
559-
defaultBackupName += `_${createGUID(false)}`;
560-
}
561-
this._configurationFileBackupName = defaultBackupName;
562-
}
563-
564-
return this._configurationFileBackupName;
565-
}).future<string>()();
566-
}
567-
568-
private backupOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture<void> {
569-
return (() => {
570-
let newPathForOriginalManifest = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait());
571-
shell.mv(originalAndroidManifestFilePath, newPathForOriginalManifest);
572-
}).future<void>()();
573-
}
574-
575-
private revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture<void> {
576-
return (() => {
577-
let pathToBackupFile = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait());
578-
if (this.$fs.exists(pathToBackupFile).wait()) {
579-
this.$logger.trace(`Could not extract ${this.platformData.configurationFileName} from default template. Reverting the change of your app/App_Resources/${this.platformData.configurationFileName}.`);
580-
shell.mv(pathToBackupFile, originalAndroidManifestFilePath);
581-
}
582-
}).future<void>()();
583-
}
584-
585-
private extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath: string): IFuture<boolean> {
586-
return ((): boolean => {
587-
let defaultTemplatePath = this.$projectTemplatesService.defaultTemplatePath.wait();
588-
let templateAndroidManifest = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName);
589-
let alreadyHasAndroidManifest = this.$fs.exists(originalAndroidManifestFilePath).wait();
590-
if (this.$fs.exists(templateAndroidManifest).wait()) {
591-
this.$logger.trace(`${originalAndroidManifestFilePath} is missing. Upgrading the source of the project with one from the new project template. Copy ${templateAndroidManifest} to ${originalAndroidManifestFilePath}`);
592-
try {
593-
if (alreadyHasAndroidManifest) {
594-
this.backupOriginalAndroidManifest(originalAndroidManifestFilePath).wait();
595-
}
596-
597-
let content = this.$fs.readText(templateAndroidManifest).wait();
598-
599-
// We do not want to force launch screens on old projects.
600-
let themeMeta = `<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />`;
601-
content = content
602-
.replace(`\n\t\t\tandroid:theme="@style/LaunchScreenTheme">\n`, `>\n\t\t\t<!-- android:theme="@style/LaunchScreenTheme" -->\n`)
603-
.replace(themeMeta, "<!-- " + themeMeta + " -->");
604-
605-
this.$fs.writeFile(originalAndroidManifestFilePath, content).wait();
606-
} catch (e) {
607-
this.$logger.trace(`Copying template's ${this.platformData.configurationFileName} failed. `, e);
608-
this.revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath).wait();
609-
return false;
610-
}
611-
} else {
612-
this.$logger.trace(`${originalAndroidManifestFilePath} is missing but the template ${templateAndroidManifest} is missing too, can not upgrade ${this.platformData.configurationFileName}.`);
613-
return false;
614-
}
615-
616-
if (alreadyHasAndroidManifest) {
617-
this.$logger.warn(`Your ${this.platformData.configurationFileName} in app/App_Resources/Android will be replaced by the default one from hello-world template.`);
618-
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.`);
619-
}
620-
621-
this.interpolateConfigurationFile().wait();
622-
return true;
623-
}).future<boolean>()();
624-
}
625509
}
626510
$injector.register("androidProjectService", AndroidProjectService);

lib/services/ios-project-service.ts

+1-20
Original file line numberDiff line numberDiff line change
@@ -624,26 +624,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
624624
);
625625
}
626626
public ensureConfigurationFileInAppResources(): IFuture<void> {
627-
return (() => {
628-
let infoPlistPath = this.getInfoPlistPath();
629-
if (!this.$fs.exists(infoPlistPath).wait()) {
630-
// The project is missing Info.plist, try to populate it from the project template.
631-
let projectTemplateService: IProjectTemplatesService = this.$injector.resolve("projectTemplatesService");
632-
let defaultTemplatePath = projectTemplateService.defaultTemplatePath.wait();
633-
let templateInfoPlist = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.iOS, this.platformData.configurationFileName);
634-
if (this.$fs.exists(templateInfoPlist).wait()) {
635-
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);
636-
try {
637-
this.$fs.copyFile(templateInfoPlist, infoPlistPath).wait();
638-
} catch (e) {
639-
this.$logger.trace("Copying template's Info.plist failed. " + e);
640-
}
641-
} else {
642-
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.");
643-
}
644-
}
645-
646-
}).future<void>()();
627+
return Future.fromResult();
647628
}
648629

649630
private mergeInfoPlists(): IFuture<void> {

lib/services/platform-service.ts

-6
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,6 @@ export class PlatformService implements IPlatformService {
259259
sourceFiles = sourceFiles.filter(source => source.indexOf(testsFolderPath) === -1);
260260
}
261261

262-
let hasTnsModulesInAppFolder = this.$fs.exists(path.join(appSourceDirectoryPath, constants.TNS_MODULES_FOLDER_NAME)).wait();
263-
if (hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) {
264-
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.");
265-
sourceFiles = sourceFiles.filter(source => !minimatch(source, `**/${constants.TNS_MODULES_FOLDER_NAME}/**`, { nocase: true }));
266-
}
267-
268262
// verify .xml files are well-formed
269263
this.$xmlValidator.validateXmlFiles(sourceFiles).wait();
270264

lib/services/plugins-service.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,13 @@ export class PluginsService implements IPluginsService {
121121
}
122122

123123
if (exists) {
124-
this.$fs.ensureDirectoryExists(pluginDestinationPath).wait();
125-
shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath);
126-
124+
//prepare platform speciffic files, .map and .ts files
127125
this.$projectFilesManager.processPlatformSpecificFiles(pluginDestinationPath, platform).wait();
128126

127+
//deal with platforms/android folder in ns plugin
129128
pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform);
130129
platformData.platformProjectService.preparePluginNativeCode(pluginData).wait();
131-
132130
shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, "platforms"));
133-
// Remove node_modules of the plugin. The destination path should have flattened node_modules.
134-
shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, constants.NODE_MODULES_FOLDER_NAME));
135131

136132
// Show message
137133
this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);

0 commit comments

Comments
 (0)