Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
refactor!: drop q (apache#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse authored Oct 23, 2021
1 parent ae8e777 commit 4e92b63
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 84 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

extends: '@cordova/eslint-config/node'

# FIXME avoid rule exceptions
rules:
prefer-promise-reject-errors: off

overrides:
- files: [tests/spec/**/*.js]
extends: '@cordova/eslint-config/node-tests'
Expand Down
2 changes: 1 addition & 1 deletion bin/apple_osx_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var versions = require('./lib/versions.js');

versions.get_apple_osx_version().done(null, function (err) {
versions.get_apple_osx_version().catch(function (err) {
console.log(err);
process.exit(2);
});
2 changes: 1 addition & 1 deletion bin/apple_xcode_version
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var versions = require('./lib/versions.js');

versions.get_apple_xcode_version().done(function (version) {
versions.get_apple_xcode_version().then(function (version) {
console.log(version);
}, function (err) {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion bin/check_reqs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var check_reqs = require('./lib/check_reqs');
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) > -1) {
console.log('Usage: check_reqs or node check_reqs');
} else {
check_reqs.run().done(null, function (err) {
check_reqs.run().catch(function (err) {
console.error('Failed to check requirements due to ' + err);
process.exit(2);
});
Expand Down
5 changes: 4 additions & 1 deletion bin/create
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ var options = {
customTemplate: argv.argv.remain[3]
};

Api.createPlatform(projectPath, config, options).done();
Api.createPlatform(projectPath, config, options).catch(err => {
console.error(err);
process.exit(2);
});
15 changes: 7 additions & 8 deletions bin/lib/check_reqs.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 shell = require('shelljs');
var versions = require('./versions');

Expand All @@ -36,8 +35,8 @@ module.exports.run = module.exports.check_xcodebuild = function () {
module.exports.check_os = function () {
// Build OSX apps available for OSX platform only, so we reject on others platforms
return process.platform === 'darwin'
? Q.resolve(process.platform)
: Q.reject('Cordova tooling for OSX requires Apple OS X');
? Promise.resolve(process.platform)
: Promise.reject('Cordova tooling for OSX requires Apple OS X');
};

/**
Expand All @@ -51,14 +50,14 @@ function checkTool (tool, minVersion, message) {
// Check whether tool command is available at all
var tool_command = shell.which(tool);
if (!tool_command) {
return Q.reject(tool + ' was not found. ' + (message || ''));
return Promise.reject(tool + ' was not found. ' + (message || ''));
}
// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(function (version) {
version = version.trim();
return versions.compareVersions(version, minVersion) >= 0
? Q.resolve(version)
: Q.reject('Cordova needs ' + tool + ' version ' + minVersion +
? Promise.resolve(version)
: Promise.reject('Cordova needs ' + tool + ' version ' + minVersion +
' or greater, you have version ' + version + '. ' + (message || ''));
});
}
Expand Down Expand Up @@ -103,7 +102,7 @@ module.exports.check_all = function () {
return promise.then(function () {
// If fatal requirement is failed,
// we don't need to check others
if (fatalIsHit) return Q();
if (fatalIsHit) return;

var requirement = requirements[idx];
return checkFn()
Expand All @@ -117,7 +116,7 @@ module.exports.check_all = function () {
result.push(requirement);
});
});
}, Q())
}, Promise.resolve())
.then(function () {
// When chain is completed, return requirements array to upstream API
return result;
Expand Down
9 changes: 4 additions & 5 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 ROOT = path.join(__dirname, '..', '..');
Expand Down Expand Up @@ -153,12 +152,12 @@ exports.createProject = function (project_path, package_name, project_name, opts

// check that project path doesn't exist
if (fs.existsSync(project_path)) {
return Q.reject('Project already exists');
return Promise.reject('Project already exists');
}

// check that parent directory does exist so cp -r will not fail
if (!fs.existsSync(project_parent)) {
return Q.reject(project_parent + ' does not exist. Please specify an existing parent folder');
return Promise.reject(project_parent + ' does not exist. Please specify an existing parent folder');
}

// create the project directory and copy over files
Expand Down Expand Up @@ -193,7 +192,7 @@ exports.createProject = function (project_path, package_name, project_name, opts
copyScripts(project_path);

events.emit('log', generateDoneMessage('create', use_shared));
return Q.resolve();
return Promise.resolve();
};

exports.updateProject = function (projectPath, opts, events) {
Expand All @@ -203,7 +202,7 @@ exports.updateProject = function (projectPath, opts, events) {
copyScripts(projectPath);
events.emit('log', generateDoneMessage('update', opts.link));
});
return Q.resolve();
return Promise.resolve();
};

function generateDoneMessage (type, link) {
Expand Down
43 changes: 19 additions & 24 deletions bin/lib/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
*/

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

exports.get_apple_osx_version = function () {
var d = Q.defer();
child_process.exec('xcodebuild -showsdks', function (error, stdout, stderr) {
if (error) {
d.reject(stderr);
} else {
d.resolve(stdout);
}
});

return d.promise.then(function (output) {
return new Promise((resolve, reject) => {
child_process.exec('xcodebuild -showsdks', function (error, stdout, stderr) {
if (error) {
reject(stderr);
} else {
resolve(stdout);
}
});
}).then(function (output) {
var regex = /[0-9]*\.[0-9]*/;
var versions = [];
var regexOSX = /^OS X \d+/;
Expand All @@ -44,23 +42,20 @@ exports.get_apple_osx_version = function () {
}
versions.sort();
console.log(versions[0]);
return Q();
}, function (stderr) {
return Q.reject(stderr);
});
};

exports.get_apple_xcode_version = function () {
var d = Q.defer();
child_process.exec('xcodebuild -version', function (error, stdout, stderr) {
var versionMatch = /Xcode (.*)/.exec(stdout);
if (error || !versionMatch) {
d.reject(stderr);
} else {
d.resolve(versionMatch[1]);
}
return new Promise((resolve, reject) => {
child_process.exec('xcodebuild -version', function (error, stdout, stderr) {
var versionMatch = /Xcode (.*)/.exec(stdout);
if (error || !versionMatch) {
reject(stderr);
} else {
resolve(versionMatch[1]);
}
});
});
return d.promise;
};

/**
Expand All @@ -72,7 +67,7 @@ exports.get_apple_xcode_version = function () {
exports.get_tool_version = function (toolName) {
switch (toolName) {
case 'xcodebuild': return exports.get_apple_xcode_version();
default: return Q.reject(toolName + ' is not valid tool name. Valid names are: \'xcodebuild\'');
default: return Promise.reject(toolName + ' is not valid tool name. Valid names are: \'xcodebuild\'');
}
};

Expand Down
2 changes: 1 addition & 1 deletion bin/templates/scripts/cordova/build
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var buildOpts = nopt({
// Make buildOptions compatible with PlatformApi build method spec
buildOpts.argv = buildOpts.argv.remain;

new Api().build(buildOpts).done(function () {
new Api().build(buildOpts).then(function () {
console.log('** BUILD SUCCEEDED **');
}, function (err) {
var errorMessage = (err && err.stack) ? err.stack : err;
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/scripts/cordova/clean
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >=
process.exit(0);
}

new Api().clean({ argv: process.argv.slice(2) }).done(function () {
new Api().clean({ argv: process.argv.slice(2) }).then(function () {
console.log('** CLEAN SUCCEEDED **');
}, function (err) {
console.error(err);
Expand Down
14 changes: 7 additions & 7 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

var Q = require('q');
const { promisify } = require('util');
var path = require('path');
var shell = require('shelljs');
var spawn = require('./spawn');
Expand All @@ -33,16 +33,16 @@ module.exports.run = function (buildOpts) {
buildOpts = buildOpts || {};

if (buildOpts.debug && buildOpts.release) {
return Q.reject('Only one of "debug"/"release" options should be specified');
return Promise.reject('Only one of "debug"/"release" options should be specified');
}

if (buildOpts.device && buildOpts.emulator) {
return Q.reject('Only one of "device"/"emulator" options should be specified');
return Promise.reject('Only one of "device"/"emulator" options should be specified');
}

if (buildOpts.buildConfig) {
if (!fs.existsSync(buildOpts.buildConfig)) {
return Q.reject('Build config file does not exist:' + buildOpts.buildConfig);
return Promise.reject('Build config file does not exist:' + buildOpts.buildConfig);
}
events.emit('log', 'Reading build config file:', path.resolve(buildOpts.buildConfig));
var buildConfig = JSON.parse(fs.readFileSync(buildOpts.buildConfig, 'utf-8'));
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports.run = function (buildOpts) {
if (buildOpts.provisioningProfile) {
extraConfig += 'PROVISIONING_PROFILE = ' + buildOpts.provisioningProfile + '\n';
}
return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
return promisify(fs.writeFile)(path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(function () {
var configuration = buildOpts.release ? 'Release' : 'Debug';

Expand Down Expand Up @@ -115,15 +115,15 @@ function findXCodeProjectIn (projectPath) {
});

if (xcodeProjFiles.length === 0) {
return Q.reject('No Xcode project found in ' + projectPath);
return Promise.reject('No Xcode project found in ' + projectPath);
}
if (xcodeProjFiles.length > 1) {
events.emit('warn', 'Found multiple .xcodeproj directories in \n' +
projectPath + '\nUsing first one');
}

var projectName = path.basename(xcodeProjFiles[0], '.xcodeproj');
return Q.resolve(projectName);
return Promise.resolve(projectName);
}

module.exports.findXCodeProjectIn = findXCodeProjectIn;
Expand Down
3 changes: 1 addition & 2 deletions bin/templates/scripts/cordova/lib/clean.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 path = require('path');
var shell = require('shelljs');
var spawn = require('./spawn');
Expand All @@ -30,7 +29,7 @@ module.exports.run = function () {
})[0];

if (!projectName) {
return Q.reject('No Xcode project found in ' + projectPath);
return Promise.reject('No Xcode project found in ' + projectPath);
}

return spawn('xcodebuild', ['-project', projectName, '-configuration', 'Debug', '-alltargets', 'clean'], projectPath)
Expand Down
5 changes: 2 additions & 3 deletions bin/templates/scripts/cordova/lib/plugman/Plugman.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 path = require('path');
var fs = require('fs');
var shell = require('shelljs');
Expand Down Expand Up @@ -53,7 +52,7 @@ Plugman.get = function (locations, events) {
module.exports = Plugman;

Plugman.prototype.addPlugin = function (plugin, installOptions) {
if (!plugin || plugin.constructor.name !== 'PluginInfo') { return Q.reject(new CordovaError('The parameter is incorrect. The first parameter to addPlugin should be a PluginInfo instance')); }
if (!plugin || plugin.constructor.name !== 'PluginInfo') { return Promise.reject(new CordovaError('The parameter is incorrect. The first parameter to addPlugin should be a PluginInfo instance')); }

installOptions = installOptions || {};
installOptions.variables = installOptions.variables || {};
Expand Down Expand Up @@ -96,7 +95,7 @@ Plugman.prototype.addPlugin = function (plugin, installOptions) {
};

Plugman.prototype.removePlugin = function (plugin, uninstallOptions) {
if (!plugin || plugin.constructor.name !== 'PluginInfo') { return Q.reject(new CordovaError('The parameter is incorrect. The first parameter to addPlugin should be a PluginInfo instance')); }
if (!plugin || plugin.constructor.name !== 'PluginInfo') { return Promise.reject(new CordovaError('The parameter is incorrect. The first parameter to addPlugin should be a PluginInfo instance')); }

var self = this;
var actions = new ActionStack();
Expand Down
11 changes: 5 additions & 6 deletions bin/templates/scripts/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 All @@ -40,7 +39,7 @@ module.exports.prepare = function (cordovaProject) {
configMunger.get(this.locations.root), this.locations);

// 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 updateProject(self._config, self.locations);
}).then(function () {
Expand Down Expand Up @@ -161,15 +160,15 @@ function updateProject (platformConfig, locations) {
return handleBuildSettings(platformConfig, locations).then(function () {
if (name === originalName) {
events.emit('verbose', 'OSX Product Name has not changed (still "' + originalName + '")');
return Q();
return Promise.resolve();
}

// Update product name inside pbxproj file
var proj = new xcode.project(locations.pbxproj); // eslint-disable-line
try {
proj.parseSync();
} catch (err) {
return Q.reject(new CordovaError('An error occurred during parsing of project.pbxproj. Start weeping. Output: ' + err));
return Promise.reject(new CordovaError('An error occurred during parsing of project.pbxproj. Start weeping. Output: ' + err));
}

proj.updateProductName(name);
Expand All @@ -194,13 +193,13 @@ function updateProject (platformConfig, locations) {
fs.writeFileSync(locations.pbxproj, pbx_contents, 'utf-8');
events.emit('verbose', 'Wrote out OSX Product Name and updated XCode project file names from "' + originalName + '" to "' + name + '".');
// in case of updated paths we return them back to
return Q();
return Promise.resolve();
});
}

function handleBuildSettings (platformConfig, locations) {
// nothing to do
return Q();
return Promise.resolve();
}

function handleIcons (projectConfig, platformRoot) {
Expand Down
Loading

0 comments on commit 4e92b63

Please sign in to comment.