How to use the cordova-common.events.emit function in cordova-common

To help you get started, we’ve selected a few cordova-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / cordova-lib / cordova-lib / src / cordova / platform.js View on Github external
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 +
github apache / cordova-electron / bin / templates / cordova / lib / prepare.js View on Github external
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);
}
github apache / cordova-lib / cordova-lib / src / cordova / platform.js View on Github external
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)
github apache / cordova-electron / bin / templates / cordova / parser.js View on Github external
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);
    }
github katzer / cordova-plugin-badge / platforms / ios / cordova / lib / build.js View on Github external
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) {
github qualintitative / egoweb / app / node_modules / cordova-android / bin / templates / cordova / lib / emulator.js View on Github external
.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\'' +
github brvier / ForRunners / platforms / ios / cordova / lib / prepare.js View on Github external
function updateBuildSettingsForLaunchStoryboard (proj, platformConfig, infoPlist) {
    var hasLaunchStoryboardImages = platformHasLaunchStoryboardImages(platformConfig);
    var hasLegacyLaunchImages = platformHasLegacyLaunchImages(platformConfig);
    var currentLaunchStoryboard = infoPlist[UI_LAUNCH_STORYBOARD_NAME];

    if (hasLaunchStoryboardImages && currentLaunchStoryboard === CDV_LAUNCH_STORYBOARD_NAME && !hasLegacyLaunchImages) {
        // don't need legacy launch images if we are using our launch storyboard
        events.emit('verbose', 'Removed ' + LAUNCHIMAGE_BUILD_SETTING + ' because project is using our launch storyboard.');
        proj.removeBuildProperty(LAUNCHIMAGE_BUILD_SETTING);
    } else if (hasLegacyLaunchImages && !currentLaunchStoryboard) {
        // we do need to ensure legacy launch images are used if there's no launch storyboard present
        events.emit('verbose', 'Set ' + LAUNCHIMAGE_BUILD_SETTING + ' to ' + LAUNCHIMAGE_BUILD_SETTING_VALUE + ' because project is using legacy launch images and no storyboard.');
        proj.updateBuildProperty(LAUNCHIMAGE_BUILD_SETTING, LAUNCHIMAGE_BUILD_SETTING_VALUE);
    } else {
        events.emit('verbose', 'Did not update build settings for launch storyboard support.');
    }
}
github apache / cordova-lib / src / cordova / plugin / remove.js View on Github external
function persistRemovalToCfg (target) {
        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);

            if (configXml.getPlugin(target)) {
                events.emit('log', 'Removing plugin ' + target + ' from config.xml file...');
                configXml.removePlugin(target);
                configXml.write();
            }
        }
    }
github katzer / cordova-plugin-background-mode / platforms / ios / cordova / lib / prepare.js View on Github external
function parseTargetDevicePreference(value) {
    if (!value) return null;
    var map = { 'universal': '"1,2"', 'handset': '"1"', 'tablet': '"2"'};
    if (map[value.toLowerCase()]) {
        return map[value.toLowerCase()];
    }
    events.emit('warn', 'Unrecognized value for target-device preference: ' + value + '.');
    return null;
}
github aayusharora / Aftershoot / poc / Cordova / platforms / android / cordova / lib / config / GradlePropertiesParser.js View on Github external
_save () {
        events.emit('verbose', '[Gradle Properties] Updating and Saving File');
        this.gradleFile.save();
    }
}