diff --git a/cordova.js b/cordova.js index 687d74c9..30c7c3bf 100644 --- a/cordova.js +++ b/cordova.js @@ -20,7 +20,7 @@ // All cordova js API moved to cordova-lib. If you don't need the cordova CLI, // use cordova-lib directly. -var cordova_lib = require('cordova-lib'); +const cordova_lib = require('cordova-lib'); module.exports = cordova_lib.cordova; // Also export the cordova-lib so that downstream consumers of cordova lib and diff --git a/src/cli.js b/src/cli.js index d96e2625..196591eb 100644 --- a/src/cli.js +++ b/src/cli.js @@ -15,21 +15,21 @@ under the License. */ -var nopt = require('nopt'); -var updateNotifier = require('update-notifier'); -var pkg = require('../package.json'); -var telemetry = require('./telemetry'); -var help = require('./help'); +const nopt = require('nopt'); +const updateNotifier = require('update-notifier'); +const pkg = require('../package.json'); +const telemetry = require('./telemetry'); +const help = require('./help'); const info = require('./info'); -var cordova_lib = require('cordova-lib'); -var CordovaError = cordova_lib.CordovaError; -var cordova = cordova_lib.cordova; -var events = cordova_lib.events; -var logger = require('cordova-common').CordovaLogger.get(); -var cordovaCreate = require('cordova-create'); -var Configstore = require('configstore'); -var conf = new Configstore(pkg.name + '-config'); -var editor = require('editor'); +const cordova_lib = require('cordova-lib'); +const CordovaError = cordova_lib.CordovaError; +const cordova = cordova_lib.cordova; +const events = cordova_lib.events; +const logger = require('cordova-common').CordovaLogger.get(); +const cordovaCreate = require('cordova-create'); +const Configstore = require('configstore'); +const conf = new Configstore(pkg.name + '-config'); +const editor = require('editor'); const semver = require('semver'); // process.version is not declared writable or has no setter so storing in const for Jasmine. @@ -39,7 +39,7 @@ const NODE_VERSION = process.version; const NODE_VERSION_REQUIREMENT = false; const NODE_VERSION_DEPRECATING_RANGE = '<10'; -var knownOpts = { +const knownOpts = { verbose: Boolean, version: Boolean, help: Boolean, @@ -69,7 +69,7 @@ var knownOpts = { noprod: Boolean }; -var shortHands = { +const shortHands = { d: '--verbose', v: '--version', h: '--help', @@ -79,7 +79,7 @@ var shortHands = { function checkForUpdates () { try { // Checks for available update and returns an instance - var notifier = updateNotifier({ pkg: pkg }); + const notifier = updateNotifier({ pkg: pkg }); if (notifier.update && notifier.update.latest !== pkg.version) { @@ -97,15 +97,15 @@ function checkForUpdates () { } } -var shouldCollectTelemetry = false; +let shouldCollectTelemetry = false; module.exports = function (inputArgs) { // If no inputArgs given, use process.argv. inputArgs = inputArgs || process.argv; - var cmd = inputArgs[2]; // e.g: inputArgs= 'node cordova run ios' - var subcommand = getSubCommand(inputArgs, cmd); - var isTelemetryCmd = (cmd === 'telemetry'); - var isConfigCmd = (cmd === 'config'); + let cmd = inputArgs[2]; // e.g: inputArgs= 'node cordova run ios' + const subcommand = getSubCommand(inputArgs, cmd); + const isTelemetryCmd = (cmd === 'telemetry'); + const isConfigCmd = (cmd === 'config'); // ToDO: Move nopt-based parsing of args up here if (cmd === '--version' || cmd === '-v') { @@ -174,7 +174,7 @@ module.exports = function (inputArgs) { * Also, if the user has already been prompted and made a decision, use his saved answer */ if (isTelemetryCmd) { - var isOptedIn = telemetry.isOptedIn(); + const isOptedIn = telemetry.isOptedIn(); return handleTelemetryCmd(subcommand, isOptedIn); } @@ -213,7 +213,7 @@ function getSubCommand (args, cmd) { } function printHelp (command) { - var result = help([command]); + const result = help([command]); cordova.emit('results', result); } @@ -224,8 +224,8 @@ function handleTelemetryCmd (subcommand, isOptedIn) { return; } - var turnOn = subcommand === 'on'; - var cmdSuccess = true; + const turnOn = subcommand === 'on'; + let cmdSuccess = true; // turn telemetry on or off try { @@ -258,7 +258,7 @@ function handleTelemetryCmd (subcommand, isOptedIn) { function cli (inputArgs) { checkForUpdates(); - var args = nopt(knownOpts, shortHands, inputArgs); + const args = nopt(knownOpts, shortHands, inputArgs); process.on('uncaughtException', function (err) { if (err.message) { @@ -281,11 +281,11 @@ function cli (inputArgs) { logger.setLevel('verbose'); } - var cliVersion = pkg.version; - var usingPrerelease = !!semver.prerelease(cliVersion); + const cliVersion = pkg.version; + const usingPrerelease = !!semver.prerelease(cliVersion); if (args.version || usingPrerelease) { - var libVersion = require('cordova-lib/package').version; - var toPrint = cliVersion; + const libVersion = require('cordova-lib/package').version; + let toPrint = cliVersion; if (cliVersion !== libVersion || usingPrerelease) { toPrint += ' (cordova-lib@' + libVersion + ')'; } @@ -325,8 +325,8 @@ function cli (inputArgs) { // In this case "--verbose" is not parsed by nopt and args.vergbose will be // false, the unparsed args after -- are kept in unparsedArgs and can be // passed downstream to some scripts invoked by Cordova. - var unparsedArgs = []; - var parseStopperIdx = args.argv.original.indexOf('--'); + let unparsedArgs = []; + const parseStopperIdx = args.argv.original.indexOf('--'); if (parseStopperIdx !== -1) { unparsedArgs = args.argv.original.slice(parseStopperIdx + 1); } @@ -334,10 +334,10 @@ function cli (inputArgs) { // args.argv.remain contains both the undashed args (like platform names) // and whatever unparsed args that were protected by " -- ". // "undashed" stores only the undashed args without those after " -- " . - var remain = args.argv.remain; - var undashed = remain.slice(0, remain.length - unparsedArgs.length); - var cmd = undashed[0]; - var subcommand; + const remain = args.argv.remain; + const undashed = remain.slice(0, remain.length - unparsedArgs.length); + const cmd = undashed[0]; + let subcommand; if (!cmd || cmd === 'help' || args.help) { if (!args.help && remain[0] === 'help') { @@ -357,12 +357,12 @@ function cli (inputArgs) { } if (!Object.prototype.hasOwnProperty.call(cordova, cmd)) { - var msg2 = 'Cordova does not know ' + cmd + '; try `' + cordova_lib.binname + + const msg2 = 'Cordova does not know ' + cmd + '; try `' + cordova_lib.binname + ' help` for a list of all the available commands.'; throw new CordovaError(msg2); } - var opts = { + const opts = { platforms: [], options: [], verbose: args.verbose || false, @@ -371,7 +371,7 @@ function cli (inputArgs) { searchpath: args.searchpath }; - var platformCommands = ['emulate', 'build', 'prepare', 'compile', 'run', 'clean']; + const platformCommands = ['emulate', 'build', 'prepare', 'compile', 'run', 'clean']; if (platformCommands.indexOf(cmd) !== -1) { // All options without dashes are assumed to be platform names opts.platforms = undashed.slice(1); @@ -389,21 +389,21 @@ function cli (inputArgs) { return cordova[cmd].call(null, opts.platforms) .then(function (platformChecks) { - var someChecksFailed = Object.keys(platformChecks).map(function (platformName) { + const someChecksFailed = Object.keys(platformChecks).map(function (platformName) { events.emit('log', '\nRequirements check results for ' + platformName + ':'); - var platformCheck = platformChecks[platformName]; + const platformCheck = platformChecks[platformName]; if (platformCheck instanceof CordovaError) { events.emit('warn', 'Check failed for ' + platformName + ' due to ' + platformCheck); return true; } - var someChecksFailed = false; + let someChecksFailed = false; // platformCheck is expected to be an array of conditions that must be met // the browser platform currently returns nothing, which was breaking here. if (platformCheck && platformCheck.forEach) { platformCheck.forEach(function (checkItem) { - var checkSummary = checkItem.name + ': ' + + const checkSummary = checkItem.name + ': ' + (checkItem.installed ? 'installed ' : 'not installed ') + (checkItem.installed ? checkItem.metadata.version.version || checkItem.metadata.version : ''); events.emit('log', checkSummary); @@ -423,22 +423,22 @@ function cli (inputArgs) { } }); } else if (cmd === 'serve') { - var port = undashed[1]; + const port = undashed[1]; return cordova.serve(port); } else { // platform/plugins add/rm [target(s)] subcommand = undashed[1]; // sub-command like "add", "ls", "rm" etc. - var targets = undashed.slice(2); // array of targets, either platforms or plugins - var cli_vars = {}; + const targets = undashed.slice(2); // array of targets, either platforms or plugins + const cli_vars = {}; if (args.variable) { args.variable.forEach(function (strVar) { // CB-9171 - var keyVal = strVar.split('='); + const keyVal = strVar.split('='); if (keyVal.length < 2) { throw new CordovaError('invalid variable format: ' + strVar); } else { - var key = keyVal.shift().toUpperCase(); - var val = keyVal.join('='); + const key = keyVal.shift().toUpperCase(); + const val = keyVal.join('='); cli_vars[key] = val; } }); @@ -456,7 +456,7 @@ function cli (inputArgs) { args['save-exact'] = conf.get('save-exact'); } - var download_opts = { + const download_opts = { searchpath: args.searchpath, noregistry: args.noregistry, nohooks: args.nohooks, diff --git a/src/help.js b/src/help.js index 9e2480de..c1c7145e 100644 --- a/src/help.js +++ b/src/help.js @@ -16,12 +16,12 @@ specific language governing permissions and limitations under the License. */ -var fs = require('fs'); -var cordova_lib = require('cordova-lib'); -var path = require('path'); +const fs = require('fs'); +const cordova_lib = require('cordova-lib'); +const path = require('path'); module.exports = function help (args) { - var command, + let command, file, raw, docdir; @@ -34,7 +34,7 @@ module.exports = function help (args) { 'cordova.md', 'cordova.txt' ].map(function (file) { - var f = path.join(docdir, file); + const f = path.join(docdir, file); if (fs.existsSync(f)) { return f; } diff --git a/src/telemetry.js b/src/telemetry.js index 167d3821..6c20c4db 100644 --- a/src/telemetry.js +++ b/src/telemetry.js @@ -21,10 +21,10 @@ const { EOL } = require('os'); // Google Analytics tracking code -var GA_TRACKING_CODE = 'UA-64283057-7'; +const GA_TRACKING_CODE = 'UA-64283057-7'; -var pkg = require('../package.json'); -var Insight = require('insight'); +const pkg = require('../package.json'); +const Insight = require('insight'); /** * By redefining `get optOut` we trick Insight into tracking @@ -38,7 +38,7 @@ class RelentlessInsight extends Insight { get realOptOut () { return super.optOut; } } -var insight = new RelentlessInsight({ +const insight = new RelentlessInsight({ trackingCode: GA_TRACKING_CODE, pkg: pkg }); @@ -96,7 +96,7 @@ function isOptedIn () { * Has the user already answered the telemetry prompt? (thereby opting in or out?) */ function hasUserOptedInOrOut () { - var insightOptOut = insight.realOptOut === undefined; + const insightOptOut = insight.realOptOut === undefined; return !(insightOptOut); }