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 e3cc75c commit 8644935
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 70 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 events = require('cordova-common').events;
var spawn = require('cordova-common').superspawn.spawn;
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 spawn('adb', args.concat(shellCommand), { cwd: os.tmpdir() }).catch(function (output) {
return Q.reject(new CordovaError('Failed to execute shell command "' +
return Promise.reject(new CordovaError('Failed to execute shell command "' +
shellCommand + '"" on device: ' + output));
});
};

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(function (output) {
return Q.reject(new CordovaError('Failed to start application "' +
return Promise.reject(new CordovaError('Failed to start application "' +
activityName + '"" on device: ' + output));
});
};
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 spawn('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
7 changes: 3 additions & 4 deletions bin/templates/cordova/lib/builders/ProjectBuilder.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 @@ -256,18 +255,18 @@ class ProjectBuilder {
return check_reqs.check_android_target(error).then(function () {
// If due to some odd reason - check_android_target succeeds
// we should still fail here.
return Q.reject(error);
return Promise.reject(error);
});
}
return Q.reject(error);
return Promise.reject(error);
});
}

clean (opts) {
var builder = this;
var wrapper = path.join(this.root, 'gradlew');
var args = builder.getArgs('clean', opts);
return Q().then(function () {
return Promise.resolve().then(function () {
return spawn(wrapper, args, { stdio: 'inherit' });
})
.then(function () {
Expand Down
28 changes: 14 additions & 14 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

var shelljs = require('shelljs');
var child_process = require('child_process');
var Q = require('q');
var path = require('path');
var fs = require('fs');
var os = require('os');
Expand Down Expand Up @@ -126,26 +125,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 @@ -194,7 +192,9 @@ module.exports.check_java = function () {
}
}
}).then(function () {
return Q.denodeify(child_process.exec)('javac -version')
return new Promise(resolve => {
resolve(child_process.execSync('javac -version'));
})
.then(outputs => {
// outputs contains two entries: stdout and stderr
// Java <= 8 writes version info to stderr, Java >= 9 to stdout
Expand All @@ -217,7 +217,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 @@ -362,7 +362,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 @@ -429,7 +429,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
29 changes: 14 additions & 15 deletions bin/templates/cordova/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,31 @@

var path = require('path');
var os = require('os');
var Q = require('q');
var child_process = require('child_process');
const { CordovaError } = require('cordova-common');
var ROOT = path.join(__dirname, '..', '..');

/*
* Starts running logcat in the shell.
* Returns a promise.
*/
module.exports.run = function () {
var d = Q.defer();
var adb = child_process.spawn('adb', ['logcat'], { cwd: os.tmpdir() });
return new Promise((resolve, reject) => {
var adb = child_process.spawn('adb', ['logcat'], { cwd: os.tmpdir() });

adb.stdout.on('data', function (data) {
var lines = data ? data.toString().split('\n') : [];
var out = lines.filter(function (x) { return x.indexOf('nativeGetEnabledTags') < 0; });
console.log(out.join('\n'));
});
adb.stdout.on('data', function (data) {
var lines = data ? data.toString().split('\n') : [];
var out = lines.filter(function (x) { return x.indexOf('nativeGetEnabledTags') < 0; });
console.log(out.join('\n'));
});

adb.stderr.on('data', console.error);
adb.on('close', function (code) {
if (code > 0) {
d.reject('Failed to run logcat command.');
} else d.resolve();
});
adb.stderr.on('data', console.error);
adb.on('close', function (code) {
if (code > 0) return reject(new CordovaError('Failed to run logcat command.'));

return d.promise;
return resolve();
});
});
};

module.exports.help = function () {
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
Loading

0 comments on commit 8644935

Please sign in to comment.