add: function()

in src/plugman/platform.js [29:55]


    add: function (platformName) {
        // Check to make sure we are in the plugin first
        if (!fs.existsSync('plugin.xml')) {
            return Promise.reject(new Error("can't find a plugin.xml.  Are you in the plugin?"));
        }

        // Get the current plugin.xml file
        const pluginxml = et.parse(fs.readFileSync('plugin.xml', 'utf-8'));

        // Check if this platform exists
        if (pluginxml.find("./platform/[@name='" + platformName + "']")) {
            return Promise.reject(new Error('platform: ' + platformName + ' already added'));
        }

        // Get the platform specific elements
        const platform = doPlatform(platformName, pluginxml.find('./name').text, pluginxml.getroot().get('id'));

        // Make sure we support it
        if (!platform) {
            return Promise.reject(new Error('platform: ' + platformName + ' not yet supported'));
        }

        pluginxml.getroot().append(platform.getroot());

        fs.writeFileSync('plugin.xml', pluginxml.write('plugin.xml', { indent: 4 }), 'utf-8');
        return Promise.resolve();
    },