Example #1
0
 }).then(function(){
     //remove plugin from config.xml
     if(saveToConfigXmlOn(config_json, opts)){
         events.emit('log', 'Removing plugin ' + target + ' from config.xml file...');
         var configPath = cordova_util.projectConfig(projectRoot);
         if(fs.existsSync(configPath)){//should not happen with real life but needed for tests
             var configXml = new ConfigParser(configPath);
             configXml.removePlugin(target);
             configXml.write();
         }
         var pkgJson;
         var pkgJsonPath = path.join(projectRoot,'package.json');
         // If statement to see if pkgJsonPath exists in the filesystem
         if(fs.existsSync(pkgJsonPath)) {
             //delete any previous caches of require(package.json)
             pkgJson = cordova_util.requireNoCache(pkgJsonPath);
         } else {
             // Create package.json in cordova@7
         }
         // If package.json exists and contains a specified plugin in cordova['plugins'], it will be removed    
         if(pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.plugins !== undefined) {
             events.emit('log', 'Removing '  + target +  ' from package.json');
             // Remove plugin from package.json
             delete pkgJson.cordova.plugins[target];
             //Write out new package.json with plugin removed correctly.
             fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2), 'utf8');
         }
     }
     
 }).then(function(){
Example #2
0
module.exports.removePlugin = function (appPath, plugin) {
    appPath = getConfigPath(appPath);
    var parser = new ConfigParser(appPath);

    parser.removePlugin(plugin);
    parser.write();
};
                        .then(function(pluginInfo){
                            // save to config.xml
                            if(saveToConfigXmlOn(config_json, opts)){
                                var src = parseSource(target, opts);
                                var attributes = {
                                    name: pluginInfo.id
                                };

                                if (src) {
                                    attributes.spec = src;
                                } else {
                                    var ver = '~' + pluginInfo.version;
                                    // Scoped packages need to have the package-spec along with the version
                                    var parsedSpec = pluginSpec.parse(target);
                                    if (parsedSpec.scope) {
                                        attributes.spec = parsedSpec.package + '@' + ver;
                                    } else {
                                        attributes.spec = ver;
                                    }
                                }

                                xml = cordova_util.projectConfig(projectRoot);
                                cfg = new ConfigParser(xml);
                                cfg.removePlugin(pluginInfo.id);
                                cfg.addPlugin(attributes, opts.cli_variables);
                                cfg.write();

                                events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
                            }
                        });
Example #4
0
                }).then(function (pluginInfo) {
                    var pkgJson;
                    var pkgJsonPath = path.join(projectRoot, 'package.json');

                    // save to config.xml
                    // TODO: no need to have saveToConfigXMLOn anymore. Should just check opts.save instead
                    if (plugin_util.saveToConfigXmlOn(config_json, opts)) {
                        // If statement to see if pkgJsonPath exists in the filesystem
                        if (fs.existsSync(pkgJsonPath)) {
                            // Delete any previous caches of require(package.json)
                            pkgJson = cordova_util.requireNoCache(pkgJsonPath);
                        }
                        // If package.json exists, the plugin object and plugin name
                        // will be added to package.json if not already there.
                        if (pkgJson) {
                            pkgJson.cordova = pkgJson.cordova || {};
                            pkgJson.cordova.plugins = pkgJson.cordova.plugins || {};
                            // Plugin and variables are added.
                            pkgJson.cordova.plugins[pluginInfo.id] = opts.cli_variables;
                            events.emit('log', 'Adding ' + pluginInfo.id + ' to package.json');

                            // Write to package.json
                            var file = fs.readFileSync(pkgJsonPath, 'utf8');
                            var indent = detectIndent(file).indent || '  ';
                            fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, indent), 'utf8');
                        }

                        var src = module.exports.parseSource(target, opts);
                        var attributes = {
                            name: pluginInfo.id
                        };

                        if (src) {
                            attributes.spec = src;
                        } else {
                            var ver = '~' + pluginInfo.version;
                            // Scoped packages need to have the package-spec along with the version
                            var parsedSpec = pluginSpec.parse(target);
                            if (pkgJson && pkgJson.dependencies && pkgJson.dependencies[pluginInfo.id]) {
                                attributes.spec = pkgJson.dependencies[pluginInfo.id];
                            } else {
                                if (parsedSpec.scope) {
                                    attributes.spec = parsedSpec.package + '@' + ver;
                                } else {
                                    attributes.spec = ver;
                                }
                            }
                        }
                        xml = cordova_util.projectConfig(projectRoot);
                        cfg = new ConfigParser(xml);
                        cfg.removePlugin(pluginInfo.id);
                        cfg.addPlugin(attributes, opts.cli_variables);
                        cfg.write();

                        events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
                    }
                });
 }).then(function(){
     //remove plugin from config.xml
     if(saveToConfigXmlOn(config_json, opts)){
         events.emit('log', 'Removing plugin ' + target + ' from config.xml file...');
         var configPath = cordova_util.projectConfig(projectRoot);
         if(fs.existsSync(configPath)){//should not happen with real life but needed for tests
             var configXml = new ConfigParser(configPath);
             configXml.removePlugin(target);
             configXml.write();
         }
     }
 })
 }).then(function(){
     //remove plugin from config.xml
     if(saveToConfigXmlOn(config_json, opts)){
         var configPath = cordova_util.projectConfig(projectRoot);
         if(fs.existsSync(configPath)){//should not happen with real life but needed for tests
             var configXml = new ConfigParser(configPath);
             configXml.removePlugin(target);
             configXml.write();
             events.emit('results', 'config.xml entry for ' +target+ ' is removed');
         }
     }
 })
Example #7
0
module.exports.setPluginSpec = function (appPath, plugin, spec) {
    appPath = getConfigPath(appPath);
    var parser = new ConfigParser(appPath),
        p = parser.getPlugin(plugin),
        variables = [];

    if (p) {
        parser.removePlugin(p.name);
        if (p.variables.length && p.variables.length > 0) {
            variables = p.variables;
        }
    }

    parser.addPlugin({ 'name': plugin, 'spec': spec }, variables);
    parser.write();
};
                    .then(function(pluginInfo){
                        // save to config.xml
                        if(saveToConfigXmlOn(config_json, opts)){
                            var src = parseSource(target, opts);
                            var attributes = {
                                name: pluginInfo.id,
                                spec: src ? src : '~' + pluginInfo.version
                            };

                            cfg.removePlugin(pluginInfo.id);
                            cfg.addPlugin(attributes, opts.cli_variables);
                            cfg.write();

                            events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
                        }
                    });