-
Notifications
You must be signed in to change notification settings - Fork 41
/
pluginstall.js
53 lines (45 loc) · 1.68 KB
/
pluginstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// copyright (c) 2012 Andrew Lunny, Adobe Systems
var fs = require('fs'),
path = require('path'),
et = require('elementtree'),
platforms = require('./platforms'),
platformModules = {
'android': require('./platforms/android'),
'ios': require('./platforms/ios'),
'www': require('./platforms/www')
}
// check arguments and resolve file paths
exports.init = function (platform, projectPath, pluginPath) {
var projectPath = fs.realpathSync(projectPath),
pluginPath = fs.realpathSync(pluginPath);
if (platforms.indexOf(platform) < 0)
throw { name: "Platform Error", message: platform + " not supported" }
return {
platform: platform,
projectPath: projectPath,
pluginPath: pluginPath
}
}
exports.parseXml = function (config) {
var xmlPath = path.join(config.pluginPath, 'plugin.xml'),
xmlText = fs.readFileSync(xmlPath, 'utf-8'),
xmlDoc = new et.ElementTree(et.XML(xmlText)),
rootAttr = xmlDoc._root.attrib,
supportedPlatforms;
supportedPlatforms = xmlDoc.findall('platform').map(function (platform) {
return platform.attrib['name'];
});
return {
xmlDoc: xmlDoc,
_id: rootAttr['id'],
version: rootAttr['version'],
platforms: supportedPlatforms
};
}
// should move all asset and source files into the right places
// and then edit all appropriate files (manifests and the like)
exports.installPlugin = function (config, plugin, callback) {
// get the platform-specific fn
var platformInstall = platformModules[config.platform].installPlugin;
return platformInstall(config, plugin, callback)
}