You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/02/03 21:22:32 UTC
[2/2] android commit: CB-8410 Fix all jshint issues for Android
platform (close #153)
CB-8410 Fix all jshint issues for Android platform (close #153)
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/aed48596
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/aed48596
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/aed48596
Branch: refs/heads/master
Commit: aed48596420b56e412f171991956b6a9e7d67760
Parents: d0ade1d
Author: Murat Sutunc <mu...@microsoft.com>
Authored: Tue Feb 3 12:10:50 2015 -0800
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Feb 3 15:21:57 2015 -0500
----------------------------------------------------------------------
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(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/lib/android_sdk_version.js
----------------------------------------------------------------------
diff --git a/bin/lib/android_sdk_version.js b/bin/lib/android_sdk_version.js
index e592378..79af272 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<results.length;i++){
apiLevels[i] = parseInt(results[i].match(reg)[0]);
}
- apiLevels.sort(function(a,b){return b-a});
+ apiLevels.sort(function(a,b){return b-a;});
console.log(apiLevels[0]);
-}
+};
-get_sdks = function() {
+var get_sdks = function() {
var d = Q.defer();
child_process.exec('android list targets', function(err, stdout, stderr) {
if (err) d.reject(stderr);
@@ -57,9 +56,9 @@ get_sdks = function() {
return Q.reject(new Error('An error occurred while listing Android targets'));
}
});
-}
+};
module.exports.run = function() {
return Q.all([get_sdks()]);
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 8fc0db5..dd2c752 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -19,6 +19,8 @@
under the License.
*/
+/* jshint sub:true */
+
var shelljs = require('shelljs'),
child_process = require('child_process'),
Q = require('q'),
@@ -63,7 +65,7 @@ module.exports.get_target = function() {
return extractFromFile(path.join(ROOT, 'project.properties'));
}
throw new Error('Could not find android target. File missing: ' + path.join(ROOT, 'project.properties'));
-}
+};
// Returns a promise. Called only by build and clean commands.
module.exports.check_ant = function() {
@@ -140,7 +142,7 @@ module.exports.check_java = function() {
return tryCommand('javac -version', msg);
});
});
-}
+};
// Returns a promise.
module.exports.check_android = function() {
@@ -242,5 +244,5 @@ module.exports.run = function() {
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
console.log('JAVA_HOME=' + process.env['JAVA_HOME']);
});
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 3139844..17c7f67 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -18,27 +18,14 @@
specific language governing permissions and limitations
under the License.
*/
+
var shell = require('shelljs'),
- child_process = require('child_process'),
Q = require('q'),
path = require('path'),
fs = require('fs'),
check_reqs = require('./check_reqs'),
ROOT = path.join(__dirname, '..', '..');
-// Returns a promise.
-function exec(command, opt_cwd) {
- var d = Q.defer();
- console.log('Running: ' + command);
- child_process.exec(command, { cwd: opt_cwd }, function(err, stdout, stderr) {
- stdout && console.log(stdout);
- stderr && console.error(stderr);
- if (err) d.reject(err);
- else d.resolve(stdout);
- });
- return d.promise;
-}
-
function setShellFatal(value, func) {
var oldVal = shell.config.fatal;
shell.config.fatal = value;
@@ -56,13 +43,13 @@ function copyJsAndLibrary(projectPath, shared, projectName) {
// Don't fail if there are no old jars.
setShellFatal(false, function() {
shell.ls(path.join(projectPath, 'libs', 'cordova-*.jar')).forEach(function(oldJar) {
- console.log("Deleting " + oldJar);
+ console.log('Deleting ' + oldJar);
shell.rm('-f', oldJar);
});
var wasSymlink = true;
try {
// Delete the symlink if it was one.
- fs.unlinkSync(nestedCordovaLibPath)
+ fs.unlinkSync(nestedCordovaLibPath);
} catch (e) {
wasSymlink = false;
}
@@ -96,9 +83,9 @@ function copyJsAndLibrary(projectPath, shared, projectName) {
function extractSubProjectPaths(data) {
var ret = {};
- var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg
+ var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg;
var m;
- while (m = r.exec(data)) {
+ while ((m = r.exec(data))) {
ret[m[1]] = 1;
}
return Object.keys(ret);
@@ -208,10 +195,8 @@ function validateProjectName(project_name) {
*/
exports.createProject = function(project_path, package_name, project_name, project_template_dir, use_shared_project, use_cli_template) {
- var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
-
// Set default values for path, package and name
- project_path = typeof project_path !== 'undefined' ? project_path : "CordovaExample";
+ project_path = typeof project_path !== 'undefined' ? project_path : 'CordovaExample';
project_path = path.relative(process.cwd(), project_path);
package_name = typeof package_name !== 'undefined' ? package_name : 'my.cordova.project';
project_name = typeof project_name !== 'undefined' ? project_name : 'CordovaExample';
@@ -290,7 +275,7 @@ exports.createProject = function(project_path, package_name, project_name, proje
writeProjectProperties(project_path, target_api);
console.log(generateDoneMessage('create', use_shared_project));
});
-}
+};
function generateDoneMessage(type, link) {
var pkg = require('../../package');
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/lib/simpleargs.js
----------------------------------------------------------------------
diff --git a/bin/lib/simpleargs.js b/bin/lib/simpleargs.js
index d286f06..8e89b8f 100644
--- a/bin/lib/simpleargs.js
+++ b/bin/lib/simpleargs.js
@@ -20,7 +20,7 @@
exports.getArgs = function(argv) {
var ret = {};
var posArgs = [];
- for (var i = 2, arg; arg = argv[i] || i < argv.length; ++i) {
+ for (var i = 2, arg; (arg = argv[i] || i < argv.length); ++i) {
if (/^--/.exec(arg)) {
ret[arg] = true;
} else {
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/appinfo.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/appinfo.js b/bin/templates/cordova/lib/appinfo.js
index 1f8ebe2..080c2ba 100644
--- a/bin/templates/cordova/lib/appinfo.js
+++ b/bin/templates/cordova/lib/appinfo.js
@@ -37,5 +37,5 @@ function readAppInfoFromManifest() {
}
exports.getActivityName = function() {
- return cachedAppInfo = cachedAppInfo || readAppInfoFromManifest();
+ return (cachedAppInfo = cachedAppInfo || readAppInfoFromManifest());
};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
index 40eec84..668a228 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -19,6 +19,8 @@
under the License.
*/
+/* jshint sub:true */
+
var shell = require('shelljs'),
spawn = require('./spawn'),
Q = require('q'),
@@ -73,7 +75,9 @@ function findOutputApksHelper(dir, build_type, arch) {
var archSpecific = !!/-x86|-arm/.exec(ret[0]);
// And show only arch-specific ones (or non-arch-specific)
ret = ret.filter(function(p) {
+ /*jshint -W018 */
return !!/-x86|-arm/.exec(p) == archSpecific;
+ /*jshint +W018 */
});
if (arch && ret.length > 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;
});
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/device.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js
index 9516ba4..c13fdc4 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);
});
});
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index 70e0305..367ae56 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);
});
});
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/exec.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/exec.js b/bin/templates/cordova/lib/exec.js
index 7a56b33..342b6fb 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;
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/log.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/log.js b/bin/templates/cordova/lib/log.js
index d61023e..ebf836d 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);
-}
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aed48596/bin/templates/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js
index ced23a0..d18c02e 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=<target_id> : Installs to the target with the specified id.');
process.exit(0);
-}
+};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org