Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'cordova-common' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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')
};
});
const FIXTURES = path.join(__dirname, '../fixtures');
const iosProject = path.join(FIXTURES, 'ios-config-xml', '*');
const faultyplugin = path.join(FIXTURES, 'org.test.plugins.faultyplugin');
const dummyplugin = path.join(FIXTURES, 'org.test.plugins.dummyplugin');
const weblessplugin = path.join(FIXTURES, 'org.test.plugins.weblessplugin');
const dummyPluginInfo = new PluginInfo(dummyplugin);
const dummy_id = dummyPluginInfo.id;
const valid_source = dummyPluginInfo.getSourceFiles('ios');
const valid_headers = dummyPluginInfo.getHeaderFiles('ios');
const valid_resources = dummyPluginInfo.getResourceFiles('ios');
const valid_custom_frameworks = dummyPluginInfo.getFrameworks('ios').filter(f => f.custom);
const valid_embeddable_custom_frameworks = dummyPluginInfo.getFrameworks('ios').filter(f => f.custom && f.embed);
const valid_weak_frameworks = dummyPluginInfo.getFrameworks('ios').filter(f => !(f.custom) && f.weak);
const faultyPluginInfo = new PluginInfo(faultyplugin);
const invalid_source = faultyPluginInfo.getSourceFiles('ios');
const invalid_headers = faultyPluginInfo.getHeaderFiles('ios');
const invalid_resources = faultyPluginInfo.getResourceFiles('ios');
const invalid_custom_frameworks = faultyPluginInfo.getFrameworks('ios').filter(f => f.custom);
const weblessPluginInfo = new PluginInfo(weblessplugin);
function copyArray (arr) {
return Array.prototype.slice.call(arr, 0);
}
function slashJoin () {
// In some places we need to use forward slash instead of path.join().
// See CB-7311.
return Array.prototype.join.call(arguments, '/');
}
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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 path = require('path');
const fs = require('fs');
const EventEmitter = require('events');
const PluginManager = require('cordova-common').PluginManager;
const Api = require('../../../bin/templates/scripts/cordova/Api');
const check_reqs = require('../../../bin/templates/scripts/cordova/lib/check_reqs');
// The lib/run module pulls in ios-sim, which has a hard requirement that it
// be run on a Mac OS - simply requiring the module is enough to trigger the
// environment checks. These checks will blow up on Windows + Linux.
// So, conditionally pull in the module, and conditionally test the `run`
// method (more below).
let run_mod;
if (process.platform === 'darwin') {
run_mod = require('../../../bin/templates/scripts/cordova/lib/run');
}
const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectFile');
const BridgingHeader_mod = require('../../../bin/templates/scripts/cordova/lib/BridgingHeader.js');
const Podfile_mod = require('../../../bin/templates/scripts/cordova/lib/Podfile');
.then(toolOptions => {
if (toolOptions.ignore) {
events.emit('verbose', '==== pod install start ====\n');
events.emit('verbose', toolOptions.ignoreMessage);
return Q.resolve();
} else {
return superspawn.spawn('pod', ['install', '--verbose'], opts)
.progress(stdio => {
if (stdio.stderr) { console.error(stdio.stderr); }
if (stdio.stdout) {
if (first) {
events.emit('verbose', '==== pod install start ====\n');
first = false;
}
events.emit('verbose', stdio.stdout);
}
});
}
})
.then(() => { // done
if (opts.fetch) {
//append cordova to platform
if(platform in platforms) {
target = 'cordova-'+target;
}
//gitURLs don't supply a platform, it equals null
if(!platform) {
target = version;
}
events.emit('log', 'Using cordova-fetch for '+ target);
return fetch(target, projectRoot, opts);
}
if (cordova_util.isUrl(version)) {
events.emit('log', 'git cloning: ' + version);
var parts = version.split('#');
var git_url = parts[0];
var branchToCheckout = parts[1];
return lazy_load.git_clone(git_url, branchToCheckout).fail(function(err) {
// If it looks like a url, but cannot be cloned, try handling it differently.
// it's because it's a tarball of the form:
// - https://api.github.com/repos/msopenTech/cordova-browser/tarball/my-branch
events.emit('verbose', err.message);
events.emit('verbose', 'Cloning failed. Let\'s try handling it as a tarball');
return lazy_load.based_on_config(projectRoot, target, opts);
});
}
return lazy_load.based_on_config(projectRoot, target, opts);
}).fail(function (error) {
var message = 'Failed to fetch platform ' + target +
function updateSplashScreens (cordovaProject, config, locations) {
const splashScreens = cordovaProject.projectConfig.getSplashScreens('electron');
// Skip if there are no splash screens defined in config.xml
if (!splashScreens.length) {
events.emit('verbose', 'This app does not have splash screens defined.');
return;
}
const splashScreen = prepareSplashScreens(splashScreens);
const resourceMap = createResourceMap(cordovaProject, locations, splashScreen);
updatePathToSplashScreen(config, locations, resourceMap);
events.emit('verbose', 'Updating splash screens');
copyResources(cordovaProject.root, resourceMap);
}
function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
var msg;
if ( !targets || !targets.length ) {
msg = 'No platform specified. Please specify a platform to ' + cmd + '. ' +
'See `' + cordova_util.binname + ' platform list`.';
return Q.reject(new CordovaError(msg));
}
for (var i = 0 ; i < targets.length; i++) {
if (!hostSupports(targets[i])) {
msg = 'WARNING: Applications for platform ' + targets[i] +
' can not be built on this OS - ' + process.platform + '.';
events.emit('log', msg);
}
}
var xml = cordova_util.projectConfig(projectRoot);
var cfg = new ConfigParser(xml);
var config_json = config.read(projectRoot);
var autosave = config_json.auto_save_platforms || false;
opts = opts || {};
opts.searchpath = opts.searchpath || config_json.plugin_search_path;
// The "platforms" dir is safe to delete, it's almost equivalent to
// cordova platform rm
var platformsDir = path.join(projectRoot, 'platforms');
shell.mkdir('-p', platformsDir);
return hooksRunner.fire('before_platform_' + cmd, opts)
update_www (cordovaProject, opts) {
const platform_www = path.join(this.path, 'platform_www');
const my_www = this.www_dir();
// add cordova www and platform_www to sourceDirs
const sourceDirs = [
path.relative(cordovaProject.root, cordovaProject.locations.www),
path.relative(cordovaProject.root, platform_www)
];
// If project contains 'merges' for our platform, use them as another overrides
const merges_path = path.join(cordovaProject.root, 'merges', 'electron');
if (fs.existsSync(merges_path)) {
events.emit('verbose', 'Found "merges/electron" folder. Copying its contents into the electron project.');
// add merges/electron to sourceDirs
sourceDirs.push(path.join('merges', 'electron'));
}
// targetDir points to electron/www
const targetDir = path.relative(cordovaProject.root, my_www);
events.emit('verbose', `Merging and updating files from [${sourceDirs.join(', ')}] to ${targetDir}`);
FileUpdater.mergeAndUpdateDir(sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);
}
buildOpts = buildOpts || {};
if (buildOpts.debug && buildOpts.release) {
return Q.reject('Cannot specify "debug" and "release" options together.');
}
if (buildOpts.device && buildOpts.emulator) {
return Q.reject('Cannot specify "device" and "emulator" options together.');
}
if (buildOpts.buildConfig) {
if (!fs.existsSync(buildOpts.buildConfig)) {
return Q.reject('Build config file does not exist:' + buildOpts.buildConfig);
}
events.emit('log', 'Reading build config file:', path.resolve(buildOpts.buildConfig));
var contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
var buildConfig = JSON.parse(contents.replace(/^\ufeff/, '')); // Remove BOM
if (buildConfig.ios) {
var buildType = buildOpts.release ? 'release' : 'debug';
var config = buildConfig.ios[buildType];
if (config) {
['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach(
function (key) {
buildOpts[key] = buildOpts[key] || config[key];
});
}
}
}
return require('./list-devices').run()
.then(function (devices) {
.then(function() {
var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
var execOptions = {
cwd: os.tmpdir(),
timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
killSignal: EXEC_KILL_SIGNAL
};
events.emit('log', 'Using apk: ' + apk_path);
events.emit('log', 'Package name: ' + pkgName);
events.emit('verbose', 'Installing app on emulator...');
// A special function to call adb install in specific environment w/ specific options.
// Introduced as a part of fix for http://issues.apache.org/jira/browse/CB-9119
// to workaround sporadic emulator hangs
function adbInstallWithOptions(target, apk, opts) {
events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');
var command = 'adb -s ' + target + ' install -r "' + apk + '"';
return Q.promise(function (resolve, reject) {
child_process.exec(command, opts, function(err, stdout, stderr) {
if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
// adb does not return an error code even if installation fails. Instead it puts a specific
// message to stdout, so we have to use RegExp matching to detect installation failure.
else if (/Failure/.test(stdout)) {
if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +