Skip to content

Commit

Permalink
chore: drop q module
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Jan 6, 2020
1 parent fd57909 commit d9d2827
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bin/create
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ 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);
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(() => Promise.resolve(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(() => Promise.resolve(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(() => Promise.resolve(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
5 changes: 2 additions & 3 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 @@ -218,13 +217,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
9 changes: 5 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,9 @@ 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 new Promise(() => {
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 +77,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
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
4 changes: 2 additions & 2 deletions spec/unit/check_reqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('check_reqs', function () {
process.env.ProgramFiles = 'windows-program-files';
return check_reqs.check_android().then(function () {
expect(process.env.ANDROID_HOME).toContain('windows-local-app-data');
}).fin(function () {
}).finally(function () {
delete process.env.LOCALAPPDATA;
delete process.env.ProgramFiles;
});
Expand All @@ -62,7 +62,7 @@ describe('check_reqs', function () {
process.env.HOME = 'home is where the heart is';
return check_reqs.check_android().then(function () {
expect(process.env.ANDROID_HOME).toContain('home is where the heart is');
}).fin(function () {
}).finally(function () {
delete process.env.HOME;
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('run', () => {

return run.run().then(
() => fail('Expected error to be thrown'),
err => expect(err).toContain(target)
err => expect(err.message).toContain(target)
);
});

Expand Down
3 changes: 1 addition & 2 deletions test/run_java_unit_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
under the License.
*/

var Q = require('q');
var path = require('path');
var execa = require('execa');
var ProjectBuilder = require('../bin/templates/cordova/lib/builders/ProjectBuilder');

Q.resolve()
Promise.resolve()
.then(_ => console.log('Preparing Gradle wrapper for Java unit tests.'))
.then(_ => new ProjectBuilder(__dirname).runGradleWrapper('gradle'))
.then(_ => gradlew('--version'))
Expand Down

0 comments on commit d9d2827

Please sign in to comment.