summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-customurlscheme/src/windows/hooks/prepare-manifest.js
blob: 06e237f758ef125d7ed83ab4a398036c9f209fed (plain)
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
module.exports = function(context) {
    var fs = context.requireCordovaModule('fs'),
        et = context.requireCordovaModule('elementtree'),
        path = context.requireCordovaModule('path'),
        xml= context.requireCordovaModule('cordova-common').xmlHelpers,
        projectRoot = path.join(context.opts.projectRoot, "platforms", "windows");

    var MANIFEST_WINDOWS    = 'package.windows.appxmanifest',
        MANIFEST_PHONE      = 'package.phone.appxmanifest',
        MANIFEST_WINDOWS10  = 'package.windows10.appxmanifest',
        MANIFEST_WINDOWS80  = 'package.windows80.appxmanifest';

    function updateManifestFile(manifestPath) {
        var doc = xml.parseElementtreeSync(manifestPath);
        var root = doc.getroot();
        var app = root.find('./Applications/Application');
        if (!app) {
            throw new Error(manifestPath + ' has incorrect XML structure.');
        }
        if (!app.find('./Extensions')) {
            app.append(new et.Element('Extensions'));
        }
        fs.writeFileSync(manifestPath, doc.write({indent: 4}), 'utf-8');
    }

    [MANIFEST_PHONE, MANIFEST_WINDOWS80, MANIFEST_WINDOWS, MANIFEST_WINDOWS10]
    .forEach(function(manifestFile) {
        updateManifestFile(path.join(projectRoot, manifestFile));
    });
}