From aed48596420b56e412f171991956b6a9e7d67760 Mon Sep 17 00:00:00 2001 From: Murat Sutunc Date: Tue, 3 Feb 2015 12:10:50 -0800 Subject: [PATCH] CB-8410 Fix all jshint issues for Android platform (close #153) --- bin/lib/android_sdk_version.js | 15 +++++------ bin/lib/check_reqs.js | 8 +++--- bin/lib/create.js | 29 +++++--------------- bin/lib/simpleargs.js | 2 +- bin/templates/cordova/lib/appinfo.js | 2 +- bin/templates/cordova/lib/build.js | 14 +++++----- bin/templates/cordova/lib/device.js | 8 +++--- bin/templates/cordova/lib/emulator.js | 38 +++++++++++++-------------- bin/templates/cordova/lib/exec.js | 2 +- bin/templates/cordova/lib/log.js | 8 +++--- bin/templates/cordova/lib/run.js | 8 +++--- 11 files changed, 59 insertions(+), 75 deletions(-) diff --git a/bin/lib/android_sdk_version.js b/bin/lib/android_sdk_version.js index e5923784..79af2727 100755 --- a/bin/lib/android_sdk_version.js +++ b/bin/lib/android_sdk_version.js @@ -19,21 +19,20 @@ under the License. */ -var shell = require('shelljs'), - child_process = require('child_process'), +var child_process = require('child_process'), Q = require('q'); -get_highest_sdk = function(results){ +var get_highest_sdk = function(results){ var reg = /\d+/; var apiLevels = []; for(var i=0;i 1) { ret = ret.filter(function(p) { @@ -100,7 +104,7 @@ function extractProjectNameFromManifest(projectPath) { function findAllUniq(data, r) { var s = {}; var m; - while (m = r.exec(data)) { + while ((m = r.exec(data))) { s[m[1]] = 1; } return Object.keys(s); @@ -165,7 +169,6 @@ var builders = { ret = this.clean(); } - var builder = this; var args = this.getArgs(build_type == 'debug' ? 'debug' : 'release'); return check_reqs.check_ant() .then(function() { @@ -243,7 +246,7 @@ var builders = { } } - var subProjectsAsGradlePaths = subProjects.map(function(p) { return ':' + p.replace(/[/\\]/g, ':') }); + var subProjectsAsGradlePaths = subProjects.map(function(p) { return ':' + p.replace(/[/\\]/g, ':'); }); // Write the settings.gradle file. fs.writeFileSync(path.join(projectPath, 'settings.gradle'), '// GENERATED FILE - DO NOT EDIT\n' + @@ -295,7 +298,6 @@ var builders = { * Returns a promise. */ build: function(build_type, arch, extraArgs) { - var builder = this; var wrapper = path.join(ROOT, 'gradlew'); var args = this.getArgs(build_type == 'debug' ? 'debug' : 'release', arch, extraArgs); return Q().then(function() { @@ -339,7 +341,7 @@ var builders = { function parseOpts(options, resolvedTarget) { // Backwards-compatibility: Allow a single string argument - if (typeof options == "string") options = [options]; + if (typeof options == 'string') options = [options]; var ret = { buildType: 'debug', @@ -480,7 +482,7 @@ module.exports.detectArchitecture = function(target) { }, function() { // For non-killall OS's. return Q.reject(err); - }) + }); } throw err; }); diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js index 9516ba4a..c13fdc40 100644 --- a/bin/templates/cordova/lib/device.js +++ b/bin/templates/cordova/lib/device.js @@ -21,11 +21,9 @@ var exec = require('./exec'), Q = require('q'), - path = require('path'), os = require('os'), build = require('./build'), - appinfo = require('./appinfo'), - ROOT = path.join(__dirname, '..', '..'); + appinfo = require('./appinfo'); /** * Returns a promise for the list of the device ID's found @@ -62,7 +60,7 @@ module.exports.list = function(lookHarder) { } return list; }); -} +}; module.exports.resolveTarget = function(target) { return this.list(true) @@ -120,4 +118,4 @@ module.exports.install = function(target, buildResults) { return Q.reject('ERROR: Failed to launch application on device: ' + err); }); }); -} +}; diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 70e03055..367ae565 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -19,16 +19,14 @@ under the License. */ -var shell = require('shelljs'), - exec = require('./exec'), +/* jshint sub:true */ + +var exec = require('./exec'), Q = require('q'), - path = require('path'), os = require('os'), appinfo = require('./appinfo'), build = require('./build'), - ROOT = path.join(__dirname, '..', '..'), - child_process = require('child_process'), - new_emulator = 'cordova_emulator'; + child_process = require('child_process'); var check_reqs = require('./check_reqs'); /** @@ -78,7 +76,7 @@ module.exports.list_images = function() { } return emulator_list; }); -} +}; /** * Will return the closest avd to the projects target @@ -91,21 +89,21 @@ module.exports.best_image = function() { .then(function(images) { var closest = 9999; var best = images[0]; - for (i in images) { + for (var i in images) { var target = images[i].target; if(target) { var num = target.split('(API level ')[1].replace(')', ''); if (num == project_target) { return images[i]; } else if (project_target - num < closest && project_target > num) { - var closest = project_target - num; + closest = project_target - num; best = images[i]; } } } return best; }); -} +}; // Returns a promise. module.exports.list_started = function() { @@ -120,7 +118,7 @@ module.exports.list_started = function() { } return started_emulator_list; }); -} +}; // Returns a promise. module.exports.list_targets = function() { @@ -135,7 +133,7 @@ module.exports.list_targets = function() { } return targets; }); -} +}; /* * Starts an emulator with the given ID, @@ -185,7 +183,7 @@ module.exports.start = function(emulator_ID) { return self.wait_for_emulator(num_started); }).then(function(new_started) { if (new_started.length > 1) { - for (i in new_started) { + for (var i in new_started) { if (started_emulators.indexOf(new_started[i]) < 0) { emulator_id = new_started[i]; } @@ -207,7 +205,7 @@ module.exports.start = function(emulator_ID) { //return the new emulator id for the started emulators return emulator_id; }); -} +}; /* * Waits for the new emulator to apear on the started-emulator list. @@ -225,7 +223,7 @@ module.exports.wait_for_emulator = function(num_running) { }); } }); -} +}; /* * Waits for the boot animation property of the emulator to switch to 'stopped' @@ -243,7 +241,7 @@ module.exports.wait_for_boot = function(emulator_id) { }); } }); -} +}; /* * Create avd @@ -257,7 +255,7 @@ module.exports.create_image = function(name, target) { .then(null, function(error) { console.error('ERROR : Failed to create emulator image : '); console.error(' Do you have the latest android targets including ' + target + '?'); - console.error(create.output); + console.error(error); }); } else { console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.'); @@ -272,7 +270,7 @@ module.exports.create_image = function(name, target) { console.error(error); }); } -} +}; module.exports.resolveTarget = function(target) { return this.list_started() @@ -325,7 +323,7 @@ module.exports.install = function(target, buildResults) { // launch the application console.log('Launching application...'); var launchName = appinfo.getActivityName(); - cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName; + var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName; return exec(cmd, os.tmpdir()); }).then(function(output) { console.log('LAUNCH SUCCESS'); @@ -333,4 +331,4 @@ module.exports.install = function(target, buildResults) { return Q.reject('Failed to launch app on emulator: ' + err); }); }); -} +}; diff --git a/bin/templates/cordova/lib/exec.js b/bin/templates/cordova/lib/exec.js index 7a56b330..342b6fbb 100644 --- a/bin/templates/cordova/lib/exec.js +++ b/bin/templates/cordova/lib/exec.js @@ -37,5 +37,5 @@ module.exports = function(cmd, opt_cwd) { d.reject(e); } return d.promise; -} +}; diff --git a/bin/templates/cordova/lib/log.js b/bin/templates/cordova/lib/log.js index d61023e8..ebf836d5 100644 --- a/bin/templates/cordova/lib/log.js +++ b/bin/templates/cordova/lib/log.js @@ -19,8 +19,7 @@ under the License. */ -var shell = require('shelljs'), - path = require('path'), +var path = require('path'), os = require('os'), Q = require('q'), child_process = require('child_process'), @@ -31,7 +30,6 @@ var shell = require('shelljs'), * Returns a promise. */ module.exports.run = function() { - var cmd = 'adb logcat | grep -v nativeGetEnabledTags'; var d = Q.defer(); var adb = child_process.spawn('adb', ['logcat'], {cwd: os.tmpdir()}); @@ -49,10 +47,10 @@ module.exports.run = function() { }); return d.promise; -} +}; module.exports.help = function() { console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log'))); console.log('Gives the logcat output on the command line.'); process.exit(0); -} +}; diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js index ced23a09..d18c02e9 100644 --- a/bin/templates/cordova/lib/run.js +++ b/bin/templates/cordova/lib/run.js @@ -19,6 +19,8 @@ under the License. */ +/* jshint loopfunc:true */ + var path = require('path'), build = require('./build'), emulator = require('./emulator'), @@ -122,7 +124,7 @@ var path = require('path'), return emulator.list_images() .then(function(avds) { // if target emulator isn't started, then start it. - for (avd in avds) { + for (var avd in avds) { if (avds[avd].name == install_target) { return emulator.start(install_target) .then(function(emulatorId) { @@ -142,7 +144,7 @@ var path = require('path'), return device.install(resolvedTarget, buildResults); }); }); -} +}; module.exports.help = function(args) { console.log('Usage: ' + path.relative(process.cwd(), args[1]) + ' [options]'); @@ -155,4 +157,4 @@ module.exports.help = function(args) { console.log(' --emulator : Will deploy the built project to an emulator if one exists'); console.log(' --target= : Installs to the target with the specified id.'); process.exit(0); -} +};