Skip to content

Commit 47fb440

Browse files
committed
Merge xmls
1 parent 101cc49 commit 47fb440

File tree

7 files changed

+50
-11
lines changed

7 files changed

+50
-11
lines changed

lib/definitions/platform.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ interface IPlatformData {
3434
frameworkDirectoriesExtensions?: string[];
3535
frameworkDirectoriesNames?: string[];
3636
targetedOS?: string[];
37+
configurationFileName?: string;
38+
configurationFilePath?: string;
3739
}
3840

3941
interface IPlatformsData {

lib/services/android-project-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class AndroidProjectService implements IPlatformProjectService {
4646
util.format("%s-%s.%s", this.$projectData.projectName, "debug", "apk"),
4747
util.format("%s-%s.%s", this.$projectData.projectName, "release", "apk")
4848
],
49-
frameworkFilesExtensions: [".jar", ".dat", ".so"]
49+
frameworkFilesExtensions: [".jar", ".dat", ".so"],
50+
configurationFileName: "AndroidManifest.xml",
51+
configurationFilePath: path.join(this.$projectData.platformsDir, "android", "AndroidManifest.xml")
5052
};
5153
}
5254

lib/services/ios-project-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class IOSProjectService implements IPlatformProjectService {
4545
frameworkFilesExtensions: [".a", ".framework", ".bin"],
4646
frameworkDirectoriesExtensions: [".framework"],
4747
frameworkDirectoriesNames: ["Metadata"],
48-
targetedOS: ['darwin']
48+
targetedOS: ['darwin'],
49+
configurationFileName: this.$projectData.projectName+"-Info.plist",
50+
configurationFilePath: path.join(projectRoot, this.$projectData.projectName, this.$projectData.projectName+"-Info.plist")
4951
};
5052
}
5153

lib/services/plugins-service.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import path = require("path");
44
import shelljs = require("shelljs");
55
import semver = require("semver");
6+
import Future = require("fibers/future");
67
import constants = require("./../constants");
8+
let xmlmerge = require("xmlmerge-js");
79

810
export class PluginsService implements IPluginsService {
911
private static INSTALL_COMMAND_NAME = "install";
@@ -38,7 +40,7 @@ export class PluginsService implements IPluginsService {
3840
return (() => {
3941
this.executeNpmCommand(PluginsService.UNINSTALL_COMMAND_NAME, pluginName).wait();
4042
let showMessage = true;
41-
let action = (modulesDestinationPath: string, platform: string) => {
43+
let action = (modulesDestinationPath: string, platform: string, platformData: IPlatformData) => {
4244
shelljs.rm("-rf", path.join(modulesDestinationPath, pluginName));
4345
this.$logger.out(`Successfully removed plugin ${pluginName} for ${platform} platform`);
4446
showMessage = false;
@@ -53,7 +55,7 @@ export class PluginsService implements IPluginsService {
5355

5456
public prepare(pluginData: IPluginData): IFuture<void> {
5557
return (() => {
56-
let action = (pluginDestinationPath: string, platform: string) => {
58+
let action = (pluginDestinationPath: string, platform: string, platformData: IPlatformData) => {
5759
let skipExecution = false;
5860
// Process .js files
5961
let installedFrameworkVersion = this.getInstalledFrameworkVersion(platform).wait();
@@ -66,13 +68,20 @@ export class PluginsService implements IPluginsService {
6668
if(!skipExecution) {
6769
this.$fs.ensureDirectoryExists(pluginDestinationPath).wait();
6870
shelljs.cp("-R", pluginData.fullPath, pluginDestinationPath);
69-
70-
// TODO: Merge xmls - check if android.manifest or info.plist files exist and merge them
71+
7172
let pluginPlatformsFolderPath = path.join(pluginDestinationPath, pluginData.name, "platforms");
72-
if(this.$fs.exists(pluginPlatformsFolderPath).wait()) {
73-
shelljs.rm("-rf", pluginPlatformsFolderPath);
73+
let pluginConfigurationFilePath = path.join(pluginPlatformsFolderPath, platformData.configurationFileName);
74+
if(this.$fs.exists(pluginConfigurationFilePath).wait()) {
75+
let pluginConfigurationFileContent = this.$fs.readFile(pluginConfigurationFilePath).wait().toString();
76+
let configurationFileContent = this.$fs.readFile(platformData.configurationFilePath).wait().toString();
77+
let resultXml = this.mergeXml(pluginConfigurationFileContent, configurationFileContent).wait();
78+
this.$fs.writeFile(platformData.configurationFilePath, resultXml).wait();
7479
}
7580

81+
if(this.$fs.exists(pluginPlatformsFolderPath).wait()) {
82+
shelljs.rm("-rf", pluginPlatformsFolderPath);
83+
}
84+
7685
// TODO: Add libraries
7786

7887
// Show message
@@ -120,14 +129,14 @@ export class PluginsService implements IPluginsService {
120129
return npmCommandResult.split("@")[0]; // returns plugin name
121130
}
122131

123-
private executeForAllInstalledPlatforms(action: (pluginDestinationPath: string, platform: string) => void): void {
132+
private executeForAllInstalledPlatforms(action: (pluginDestinationPath: string, platform: string, platformData: IPlatformData) => void): void {
124133
let availablePlatforms = _.keys(this.$platformsData.availablePlatforms);
125134
_.each(availablePlatforms, platform => {
126135
let isPlatformInstalled = this.$fs.exists(path.join(this.$projectData.platformsDir, platform.toLowerCase())).wait();
127136
if(isPlatformInstalled) {
128137
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
129138
let pluginDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, "tns_modules");
130-
action(pluginDestinationPath, platform.toLowerCase());
139+
action(pluginDestinationPath, platform.toLowerCase(), platformData);
131140
}
132141
});
133142
}
@@ -168,5 +177,14 @@ export class PluginsService implements IPluginsService {
168177
return frameworkData.version;
169178
}).future<string>()();
170179
}
180+
181+
private mergeXml(xml1: string, xml2: string): IFuture<string> {
182+
let future = new Future<string>();
183+
xmlmerge.merge(xml1, xml2, (mergedXml: string) => { // TODO: process errors
184+
future.return(mergedXml);
185+
});
186+
187+
return future;
188+
}
171189
}
172190
$injector.register("pluginsService", PluginsService);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"ws": "0.7.1",
6969
"xcode": "https://github.com/NativeScript/node-xcode/archive/NativeScript-0.9.tar.gz",
7070
"xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master",
71+
"xmlmerge-js": "0.2.4",
7172
"yargs": "1.2.2"
7273
},
7374
"analyze": true,

test/platform-commands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ function createTestInjector() {
108108
testInjector.register("broccoliBuilder", {
109109
prepareNodeModulesFolder: () => {}
110110
});
111+
testInjector.register("pluginsService", {
112+
getAllInstalledPlugins: () => {
113+
return (() => {
114+
return <any>[];
115+
}).future<IPluginData[]>()();
116+
}
117+
});
111118

112119
return testInjector;
113120
}

test/platform-service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ function createTestInjector() {
5050
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
5151
testInjector.register("broccoliBuilder", {
5252
prepareNodeModulesFolder: () => {}
53-
})
53+
});
54+
testInjector.register("pluginsService", {
55+
getAllInstalledPlugins: () => {
56+
return (() => {
57+
return <any>[];
58+
}).future<IPluginData[]>()();
59+
}
60+
});
5461

5562
return testInjector;
5663
}

0 commit comments

Comments
 (0)