Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: drop q module #833

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/android_sdk_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var android_sdk = require('./templates/cordova/lib/android_sdk');

android_sdk.print_newest_available_sdk_target().done(null, function (err) {
android_sdk.print_newest_available_sdk_target().catch(err => {
console.error(err);
process.exit(2);
});
2 changes: 1 addition & 1 deletion bin/check_reqs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var check_reqs = require('./templates/cordova/lib/check_reqs');

check_reqs.run().done(
check_reqs.run().then(
function success () {
console.log('Looks like your environment fully supports cordova-android development!');
},
Expand Down
5 changes: 4 additions & 1 deletion bin/create
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ var options = {

require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv);

Api.createPlatform(argv.argv.remain[0], config, options).done();
Api.createPlatform(argv.argv.remain[0], config, options).catch(err => {
console.error(err);
process.exitCode = 1;
});
21 changes: 10 additions & 11 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

var shell = require('shelljs');
var Q = require('q');
var path = require('path');
var fs = require('fs');
var check_reqs = require('./../templates/cordova/lib/check_reqs');
Expand Down Expand Up @@ -197,15 +196,15 @@ function validatePackageName (package_name) {
var msg = 'Error validating package name. ';

if (!/^[a-zA-Z][a-zA-Z0-9_]+(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.test(package_name)) {
return Q.reject(new CordovaError(msg + 'Must look like: `com.company.Name`. Currently is: `' + package_name + '`'));
return Promise.reject(new CordovaError(msg + 'Must look like: `com.company.Name`. Currently is: `' + package_name + '`'));
}

// Class is a reserved word
if (/\b[Cc]lass\b/.test(package_name)) {
return Q.reject(new CordovaError(msg + '"class" is a reserved word'));
return Promise.reject(new CordovaError(msg + '"class" is a reserved word'));
}

return Q.resolve();
return Promise.resolve();
}

/**
Expand All @@ -217,20 +216,20 @@ function validateProjectName (project_name) {
var msg = 'Error validating project name. ';
// Make sure there's something there
if (project_name === '') {
return Q.reject(new CordovaError(msg + 'Project name cannot be empty'));
return Promise.reject(new CordovaError(msg + 'Project name cannot be empty'));
}

// Enforce stupid name error
if (project_name === 'CordovaActivity') {
return Q.reject(new CordovaError(msg + 'Project name cannot be CordovaActivity'));
return Promise.reject(new CordovaError(msg + 'Project name cannot be CordovaActivity'));
}

// Classes in Java don't begin with numbers
if (/^[0-9]/.test(project_name)) {
return Q.reject(new CordovaError(msg + 'Project name must not begin with a number'));
return Promise.reject(new CordovaError(msg + 'Project name must not begin with a number'));
}

return Q.resolve();
return Promise.resolve();
}

/**
Expand Down Expand Up @@ -259,7 +258,7 @@ exports.create = function (project_path, config, options, events) {
project_path = path.relative(process.cwd(), (project_path || 'CordovaExample'));
// Check if project already exists
if (fs.existsSync(project_path)) {
return Q.reject(new CordovaError('Project already exists! Delete and recreate'));
return Promise.reject(new CordovaError('Project already exists! Delete and recreate'));
}

var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
Expand Down Expand Up @@ -333,7 +332,7 @@ exports.create = function (project_path, config, options, events) {
exports.writeProjectProperties(project_path, target_api);
exports.prepBuildFiles(project_path);
events.emit('log', generateDoneMessage('create', options.link));
}).thenResolve(project_path);
}).then(() => project_path);
};

function generateDoneMessage (type, link) {
Expand All @@ -358,5 +357,5 @@ exports.update = function (projectPath, options, events) {
'\tcordova platform add android\n'
;

return Q.reject(errorString);
return Promise.reject(errorString);
};
7 changes: 3 additions & 4 deletions bin/templates/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

var path = require('path');
var Q = require('q');

var AndroidProject = require('./lib/AndroidProject');
var PluginManager = require('cordova-common').PluginManager;
Expand Down Expand Up @@ -206,7 +205,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
installOptions.variables.PACKAGE_NAME = project.getPackageName();
}

return Q().then(function () {
return Promise.resolve().then(function () {
return PluginManager.get(self.platform, self.locations, project).addPlugin(plugin, installOptions);
}).then(function () {
if (plugin.getFrameworks(this.platform).length === 0) return;
Expand All @@ -215,7 +214,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
require('./lib/builders/builders').getBuilder().prepBuildFiles();
}.bind(this))
// CB-11022 Return truthy value to prevent running prepare after
.thenResolve(true);
.then(() => true);
};

/**
Expand Down Expand Up @@ -247,7 +246,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
require('./lib/builders/builders').getBuilder().prepBuildFiles();
}.bind(this))
// CB-11022 Return truthy value to prevent running prepare after
.thenResolve(true);
.then(() => true);
};

/**
Expand Down
7 changes: 3 additions & 4 deletions bin/templates/cordova/lib/Adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
under the License.
*/

var Q = require('q');
var os = require('os');
var execa = require('execa');
var events = require('cordova-common').events;
Expand Down Expand Up @@ -70,7 +69,7 @@ Adb.install = function (target, packagePath, opts) {
'\nEither uninstall an app or increment the versionCode.';
}

return Q.reject(new CordovaError('Failed to install apk to device: ' + output));
return Promise.reject(new CordovaError('Failed to install apk to device: ' + output));
}
});
};
Expand All @@ -85,15 +84,15 @@ Adb.shell = function (target, shellCommand) {
var args = ['-s', target, 'shell'];
shellCommand = shellCommand.split(/\s+/);
return execa('adb', args.concat(shellCommand), { cwd: os.tmpdir() }).catch((error) => {
return Q.reject(new CordovaError('Failed to execute shell command "' +
return Promise.reject(new CordovaError('Failed to execute shell command "' +
shellCommand + '"" on device: ' + error));
});
};

Adb.start = function (target, activityName) {
events.emit('verbose', 'Starting application "' + activityName + '" on target ' + target + '...');
return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName).catch((error) => {
return Q.reject(new CordovaError('Failed to start application "' +
return Promise.reject(new CordovaError('Failed to start application "' +
activityName + '"" on device: ' + error));
});
};
Expand Down
17 changes: 13 additions & 4 deletions bin/templates/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
under the License.
*/

var Q = require('q');
var path = require('path');
var fs = require('fs');
var nopt = require('nopt');
Expand Down Expand Up @@ -204,9 +203,19 @@ module.exports.detectArchitecture = function (target) {
return /intel/i.exec(output) ? 'x86' : 'arm';
});
}
function timeout (ms, err) {
return new Promise((resolve, reject) => {
setTimeout(() => reject(err), ms);
});
}
// It sometimes happens (at least on OS X), that this command will hang forever.
// To fix it, either unplug & replug device, or restart adb server.
return helper().timeout(1000, new CordovaError('Device communication timed out. Try unplugging & replugging the device.')).then(null, function (err) {
return Promise.race([
helper(),
timeout(1000, new CordovaError(
'Device communication timed out. Try unplugging & replugging the device.'
))
]).catch(err => {
if (/timed out/.exec('' + err)) {
// adb kill-server doesn't seem to do the trick.
// Could probably find a x-platform version of killall, but I'm not actually
Expand All @@ -218,13 +227,13 @@ module.exports.detectArchitecture = function (target) {
events.emit('warn', 'adb timed out a second time while detecting device/emulator architecture. Killing adb and trying again.');
return execa('killall', ['adb']).then(function () {
return helper().then(null, function () {
return Q.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
return Promise.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
});
});
});
}, function () {
// For non-killall OS's.
return Q.reject(err);
return Promise.reject(err);
});
}
throw err;
Expand Down
24 changes: 11 additions & 13 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

const execa = require('execa');
var shelljs = require('shelljs');
var Q = require('q');
var path = require('path');
var fs = require('fs');
var os = require('os');
Expand Down Expand Up @@ -125,26 +124,25 @@ module.exports.get_gradle_wrapper = function () {
// Returns a promise. Called only by build and clean commands.
module.exports.check_gradle = function () {
var sdkDir = process.env['ANDROID_HOME'];
var d = Q.defer();
if (!sdkDir) {
return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' +
return Promise.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' +
'Might need to install Android SDK or set up \'ANDROID_HOME\' env variable.'));
}

var gradlePath = module.exports.get_gradle_wrapper();
if (gradlePath.length !== 0) { d.resolve(gradlePath); } else {
d.reject(new CordovaError('Could not find an installed version of Gradle either in Android Studio,\n' +
'or on your system to install the gradle wrapper. Please include gradle \n' +
'in your path, or install Android Studio'));
}
return d.promise;

if (gradlePath.length !== 0) return Promise.resolve(gradlePath);

return Promise.reject(new CordovaError('Could not find an installed version of Gradle either in Android Studio,\n' +
'or on your system to install the gradle wrapper. Please include gradle \n' +
'in your path, or install Android Studio'));
};

// Returns a promise.
module.exports.check_java = function () {
var javacPath = forgivingWhichSync('javac');
var hasJavaHome = !!process.env['JAVA_HOME'];
return Q().then(function () {
return Promise.resolve().then(function () {
if (hasJavaHome) {
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
if (!javacPath) {
Expand Down Expand Up @@ -214,7 +212,7 @@ module.exports.check_java = function () {

// Returns a promise.
module.exports.check_android = function () {
return Q().then(function () {
return Promise.resolve().then(function () {
var androidCmdPath = forgivingWhichSync('android');
var adbInPath = forgivingWhichSync('adb');
var avdmanagerInPath = forgivingWhichSync('avdmanager');
Expand Down Expand Up @@ -359,7 +357,7 @@ module.exports.check_android_target = function (originalError) {

// Returns a promise.
module.exports.run = function () {
return Q.all([this.check_java(), this.check_android()]).then(function (values) {
return Promise.all([this.check_java(), this.check_android()]).then(function (values) {
console.log('Checking Java JDK and Android SDK versions');
console.log('ANDROID_SDK_ROOT=' + process.env['ANDROID_SDK_ROOT'] + ' (recommended setting)');
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME'] + ' (DEPRECATED)');
Expand Down Expand Up @@ -426,7 +424,7 @@ module.exports.check_all = function () {
}, function (err) {
requirement.metadata.reason = err instanceof Error ? err.message : err;
});
}, Q()).then(function () {
}, Promise.resolve()).then(function () {
// When chain is completed, return requirements array to upstream API
return requirements;
});
Expand Down
7 changes: 3 additions & 4 deletions bin/templates/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
under the License.
*/

var Q = require('q');
var fs = require('fs');
var path = require('path');
var shell = require('shelljs');
Expand Down Expand Up @@ -56,7 +55,7 @@ module.exports.prepare = function (cordovaProject, options) {
gradlePropertiesParser.configure(gradlePropertiesUserConfig);

// Update own www dir with project's www assets and plugins' assets and js-files
return Q.when(updateWww(cordovaProject, this.locations)).then(function () {
return Promise.resolve(updateWww(cordovaProject, this.locations)).then(function () {
// update project according to config.xml changes.
return updateProjectAccordingTo(self._config, self.locations);
}).then(function () {
Expand All @@ -76,13 +75,13 @@ module.exports.clean = function (options) {
var projectRoot = path.resolve(this.root, '../..');
if ((options && options.noPrepare) || !fs.existsSync(this.locations.configXml) ||
!fs.existsSync(this.locations.configXml)) {
return Q();
return Promise.resolve();
}

var projectConfig = new ConfigParser(this.locations.configXml);

var self = this;
return Q().then(function () {
return Promise.resolve().then(function () {
cleanWww(projectRoot, self.locations);
cleanIcons(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
cleanSplashes(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
Expand Down
7 changes: 3 additions & 4 deletions bin/templates/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
var path = require('path');
var emulator = require('./emulator');
var device = require('./device');
var Q = require('q');
var PackageType = require('./PackageType');
var events = require('cordova-common').events;
const { CordovaError, events } = require('cordova-common');

function getInstallTarget (runOptions) {
var install_target;
Expand Down Expand Up @@ -55,7 +54,7 @@ module.exports.run = function (runOptions) {
var self = this;
var install_target = getInstallTarget(runOptions);

return Q().then(function () {
return Promise.resolve().then(function () {
if (!install_target) {
// no target given, deploy to device if available, otherwise use the emulator.
return device.list().then(function (device_list) {
Expand Down Expand Up @@ -97,7 +96,7 @@ module.exports.run = function (runOptions) {
});
}
}
return Q.reject('Target \'' + install_target + '\' not found, unable to run project');
return Promise.reject(new CordovaError(`Target '${install_target}' not found, unable to run project`));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/cordova/log
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var args = process.argv;
if (args.length > 2) {
log.help();
} else {
reqs.run().done(function () {
reqs.run().then(function () {
return log.run();
}, function (err) {
console.error('ERROR: ' + err);
Expand Down
5 changes: 4 additions & 1 deletion bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ if (args.help || args.argv.remain.length === 0) {

require('./templates/cordova/loggingHelper').adjustLoggerLevel(args);

Api.updatePlatform(args.argv.remain[0], { link: (args.link || args.shared) }).done();
Api.updatePlatform(args.argv.remain[0], { link: (args.link || args.shared) }).catch(err => {
console.error(err);
process.exitCode = 1;
});
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"execa": "^3.2.0",
"nopt": "^4.0.1",
"properties-parser": "^0.3.1",
"q": "^1.5.1",
"shelljs": "^0.5.3"
},
"devDependencies": {
Expand Down
Loading