Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const rewire = require('rewire');
const path = require('path');
const ConfigParser = require('cordova-common').ConfigParser;
const FIXTURES = path.join(__dirname, '..', '..', '..', '..', 'fixtures');
// Create a real config object before mocking out everything.
const cfg1 = new ConfigParser(path.join(FIXTURES, 'test-config-1.xml'));
const cfg2 = new ConfigParser(path.join(FIXTURES, 'test-config-2.xml'));
const cfgEmpty = new ConfigParser(path.join(FIXTURES, 'test-config-empty.xml'));
describe('Testing ManifestJsonParser.js:', () => {
let ManifestJsonParser;
let locations;
beforeEach(() => {
ManifestJsonParser = rewire('../../../../../../bin/templates/cordova/lib/ManifestJsonParser');
locations = {
buildRes: path.join('mock', 'build-res'),
www: path.join('mock', 'www'),
configXml: path.join('mock', 'config.xml')
};
});
function updateConfigFilesFrom(sourceConfig, configMunger, locations) {
events.emit('verbose', 'Generating platform-specific config.xml from defaults for android at ' + locations.configXml);
// First cleanup current config and merge project's one into own
// Overwrite platform config.xml with defaults.xml.
shell.cp('-f', locations.defaultConfigXml, locations.configXml);
// Then apply config changes from global munge to all config files
// in project (including project's config)
configMunger.reapply_global_munge().save_all();
events.emit('verbose', 'Merging project\'s config.xml into platform-specific android config.xml');
// Merge changes from app's config.xml into platform's one
var config = new ConfigParser(locations.configXml);
xmlHelpers.mergeXml(sourceConfig.doc.getroot(),
config.doc.getroot(), 'android', /*clobber=*/true);
config.write();
return config;
}
function updateConfigFile(sourceConfig, configMunger, locations) {
events.emit('verbose', 'Generating platform-specific config.xml from defaults for iOS at ' + locations.configXml);
// First cleanup current config and merge project's one into own
// Overwrite platform config.xml with defaults.xml.
shell.cp('-f', locations.defaultConfigXml, locations.configXml);
// Then apply config changes from global munge to all config files
// in project (including project's config)
configMunger.reapply_global_munge().save_all();
events.emit('verbose', 'Merging project\'s config.xml into platform-specific iOS config.xml');
// Merge changes from app's config.xml into platform's one
var config = new ConfigParser(locations.configXml);
xmlHelpers.mergeXml(sourceConfig.doc.getroot(),
config.doc.getroot(), 'ios', /*clobber=*/true);
config.write();
return config;
}
targets.forEach(function (target) {
var platformName = target.split('@')[0];
var xml = cordova_util.projectConfig(projectRoot);
var cfg = new ConfigParser(xml);
if (cfg.getEngines && cfg.getEngines().some(function (e) { return e.name === platformName; })) {
events.emit('log', 'Removing platform ' + target + ' from config.xml file...');
cfg.removeEngine(platformName);
cfg.write();
}
// If package.json exists and contains a specified platform in cordova.platforms, it will be removed.
if (pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.platforms !== undefined) {
var index = pkgJson.cordova.platforms.indexOf(platformName);
// Check if platform exists in platforms array.
if (pkgJson.cordova.platforms !== undefined && index > -1) {
events.emit('log', 'Removing ' + platformName + ' from cordova.platforms array in package.json');
pkgJson.cordova.platforms.splice(index, 1);
modifiedPkgJson = true;
}
}
});
targets.forEach(function(target) {
var platformName = target.split('@')[0];
var xml = cordova_util.projectConfig(projectRoot);
var cfg = new ConfigParser(xml);
events.emit('log', 'Removing platform ' + target + ' from config.xml file...');
cfg.removeEngine(platformName);
cfg.write();
// If package.json exists and contains a specified platform in cordova.platforms, it will be removed.
if(pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.platforms !== undefined) {
var index = pkgJson.cordova.platforms.indexOf(platformName);
// Check if platform exists in platforms array.
if (pkgJson.cordova.platforms !== undefined && index > -1) {
events.emit('log', 'Removing ' + platformName + ' from cordova.platforms array in package.json');
pkgJson.cordova.platforms.splice(index, 1);
modifiedPkgJson = true;
}
}
});
//Write out new package.json if changes have been made.
function save(projectRoot, opts){
var xml = cordova_util.projectConfig(projectRoot);
var cfg = new ConfigParser(xml);
// First, remove all pre-existing plugins from config.xml
cfg.getPluginIdList().forEach(function(plugin){
cfg.removePlugin(plugin);
});
// Then, save top-level plugins and their sources
var jsonFile = path.join(projectRoot, 'plugins', 'fetch.json');
var plugins;
try {
// It might be the case that fetch.json file is not yet existent.
// for example: when we have never ran the command 'cordova plugin add foo' on the project
// in that case, there's nothing to do except bubble up the error
plugins = JSON.parse(fs.readFileSync(jsonFile, 'utf-8'));
} catch (err) {
return Q.reject(err.message);
function save(projectRoot, opts){
var xml = cordova_util.projectConfig(projectRoot);
var cfg = new ConfigParser(xml);
// First, remove all pre-existing plugins from config.xml
cfg.getPluginIdList().forEach(function(plugin){
cfg.removePlugin(plugin);
});
// Then, save top-level plugins and their sources
var jsonFile = path.join(projectRoot, 'plugins', 'fetch.json');
var plugins;
try {
// It might be the case that fetch.json file is not yet existent.
// for example: when we have never ran the command 'cordova plugin add foo' on the project
// in that case, there's nothing to do except bubble up the error
plugins = JSON.parse(fs.readFileSync(jsonFile, 'utf-8'));
} catch (err) {
return Q.reject(err.message);
blackberry_parser.prototype.update_www = function () {
var projectRoot = util.isCordova(this.path);
var app_www = util.projectWww(projectRoot);
var platform_www = path.join(this.path, 'platform_www');
var platform_cfg_backup = new ConfigParser(this.config_path);
// Clear the www dir
shell.rm('-rf', this.www_dir());
shell.mkdir(this.www_dir());
// Copy over all app www assets
shell.cp('-rf', path.join(app_www, '*'), this.www_dir());
// Copy over stock platform www assets (cordova.js)
shell.cp('-rf', path.join(platform_www, '*'), this.www_dir());
// Re-Write config.xml
platform_cfg_backup.write();
};
function ubuntu_parser (project) {
// Call the base class constructor
Parser.call(this, 'ubuntu', project);
this.path = project;
this.config = new ConfigParser(this.config_xml());
this.update_manifest();
}
Api.prototype.prepare = function (cordovaProject) {
cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path);
return require('./lib/prepare').prepare.call(this, cordovaProject);
};