Skip to content

Commit

Permalink
refactor: drop q
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Jan 10, 2020
1 parent 770ec19 commit b7c40dc
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 91 deletions.
11 changes: 5 additions & 6 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
*/

const shell = require('shelljs');
const Q = require('q');
const path = require('path');
const fs = require('fs');
const xcode = require('xcode');
const xmlescape = require('xml-escape');
const ROOT = path.join(__dirname, '..', '..');
const events = require('cordova-common').events;
const { CordovaError, events } = require('cordova-common');

function updateSubprojectHelp () {
console.log('Updates the subproject path of the CordovaLib entry to point to this script\'s version of Cordova.');
Expand Down Expand Up @@ -205,12 +204,12 @@ exports.createProject = (project_path, package_name, project_name, opts, config)

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

// check that parent directory does exist so cp -r will not fail
if (!fs.existsSync(project_parent)) {
return Q.reject(`Parent directory "${project_parent}" of given project path does not exist`);
return Promise.reject(new CordovaError(`Parent directory "${project_parent}" of given project path does not exist`));
}

events.emit('log', 'Creating Cordova project for the iOS platform:');
Expand All @@ -235,7 +234,7 @@ exports.createProject = (project_path, package_name, project_name, opts, config)
copyScripts(project_path, project_name);

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

exports.updateProject = (projectPath, opts) => {
Expand All @@ -248,7 +247,7 @@ exports.updateProject = (projectPath, opts) => {
'\tcordova platform rm ios\n' +
'\tcordova platform add ios\n';

return Q.reject(errorString);
return Promise.reject(new CordovaError(errorString));
};

function generateDoneMessage (type, link) {
Expand Down
5 changes: 2 additions & 3 deletions bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const CordovaError = require('cordova-common').CordovaError;
const CordovaLogger = require('cordova-common').CordovaLogger;
const events = require('cordova-common').events;
const PluginManager = require('cordova-common').PluginManager;
const Q = require('q');
const util = require('util');
const xcode = require('xcode');
const ConfigParser = require('cordova-common').ConfigParser;
Expand Down Expand Up @@ -434,7 +433,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
return Promise.resolve();
};

/**
Expand Down Expand Up @@ -552,7 +551,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
}
}
return Q.when();
return Promise.resolve();
};

/**
Expand Down
5 changes: 2 additions & 3 deletions bin/templates/scripts/cordova/lib/Podfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const path = require('path');
const util = require('util');
const split2 = require('split2');
const events = require('cordova-common').events;
const Q = require('q');
const execa = require('execa');
const CordovaError = require('cordova-common').CordovaError;

Expand Down Expand Up @@ -375,7 +374,7 @@ Podfile.prototype.before_install = function (toolOptions) {
fs.writeFileSync(debugConfigPath, debugContents, 'utf8');
fs.writeFileSync(releaseConfigPath, releaseContents, 'utf8');

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

Podfile.prototype.install = function (requirementsCheckerFunction) {
Expand All @@ -384,7 +383,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
opts.stderr = 'inherit';

if (!requirementsCheckerFunction) {
requirementsCheckerFunction = Q();
requirementsCheckerFunction = Promise.resolve();
}

return requirementsCheckerFunction()
Expand Down
19 changes: 9 additions & 10 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
* under the License.
*/

const Q = require('q');
const path = require('path');
const shell = require('shelljs');
const execa = require('execa');
const fs = require('fs');
const fs = require('fs-extra');
const plist = require('plist');
const util = require('util');

const check_reqs = require('./check_reqs');
const projectFile = require('./projectFile');

const events = require('cordova-common').events;
const { CordovaError, events } = require('cordova-common');

// These are regular expressions to detect if the user is changing any of the built-in xcodebuildArgs
/* eslint-disable no-useless-escape */
Expand Down Expand Up @@ -111,16 +110,16 @@ module.exports.run = buildOpts => {
buildOpts = buildOpts || {};

if (buildOpts.debug && buildOpts.release) {
return Q.reject('Cannot specify "debug" and "release" options together.');
return Promise.reject(new CordovaError('Cannot specify "debug" and "release" options together.'));
}

if (buildOpts.device && buildOpts.emulator) {
return Q.reject('Cannot specify "device" and "emulator" options together.');
return Promise.reject(new CordovaError('Cannot specify "device" and "emulator" options together.'));
}

if (buildOpts.buildConfig) {
if (!fs.existsSync(buildOpts.buildConfig)) {
return Q.reject(`Build config file does not exist: ${buildOpts.buildConfig}`);
return Promise.reject(new CordovaError(`Build config file does not exist: ${buildOpts.buildConfig}`));
}
events.emit('log', `Reading build config file: ${path.resolve(buildOpts.buildConfig)}`);
const contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
Expand Down Expand Up @@ -210,7 +209,7 @@ module.exports.run = buildOpts => {
writeCodeSignStyle('Automatic');
}

return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
return fs.writeFile(path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(() => {
const configuration = buildOpts.release ? 'Release' : 'Debug';

Expand Down Expand Up @@ -276,7 +275,7 @@ module.exports.run = buildOpts => {
return execa('xcodebuild', xcodearchiveArgs, { cwd: projectPath, stdio: 'inherit' }).then(({ stdout }) => stdout);
}

return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8')
return fs.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
.then(checkSystemRuby)
.then(packageArchive);
});
Expand All @@ -292,14 +291,14 @@ function findXCodeProjectIn (projectPath) {
const xcodeProjFiles = shell.ls(projectPath).filter(name => path.extname(name) === '.xcodeproj');

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

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

module.exports.findXCodeProjectIn = findXCodeProjectIn;
Expand Down
26 changes: 13 additions & 13 deletions bin/templates/scripts/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

'use strict';

const Q = require('q');
const shell = require('shelljs');
const util = require('util');
const versions = require('./versions');
const { CordovaError } = require('cordova-common');

const SUPPORTED_OS_PLATFORMS = ['darwin'];

Expand Down Expand Up @@ -63,8 +63,8 @@ module.exports.check_ios_deploy = () => {
module.exports.check_os = () => {
// Build iOS apps available for OSX platform only, so we reject on others platforms
return os_platform_is_supported()
? Q.resolve(process.platform)
: Q.reject('Cordova tooling for iOS requires Apple macOS');
? Promise.resolve(process.platform)
: Promise.reject(new CordovaError('Cordova tooling for iOS requires Apple macOS'));
};

function os_platform_is_supported () {
Expand All @@ -76,7 +76,7 @@ function check_cocoapod_tool (toolChecker) {
if (os_platform_is_supported()) { // CB-12856
return toolChecker('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
} else {
return Q.resolve({
return Promise.resolve({
ignore: true,
ignoreMessage: `CocoaPods check and installation ignored on ${process.platform}`
});
Expand All @@ -97,16 +97,16 @@ module.exports.check_cocoapods_repo_size = () => {
const size = toolOptions.ignore ? 0 : parseFloat(command.output);

if (toolOptions.ignore || command.code === 0) { // success, parse output
return Q.resolve(size, toolOptions);
return Promise.resolve(size, toolOptions);
} else { // error, perhaps not found
return Q.reject(util.format('%s (%s)', COCOAPODS_REPO_NOT_FOUND_MESSAGE, command.output));
return Promise.reject(util.format('%s (%s)', COCOAPODS_REPO_NOT_FOUND_MESSAGE, command.output));
}
})
.then((repoSize, toolOptions) => {
if (toolOptions.ignore || COCOAPODS_SYNCED_MIN_SIZE <= repoSize) { // success, expected size
return Q.resolve(toolOptions);
return Promise.resolve(toolOptions);
} else {
return Q.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
return Promise.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
}
});
};
Expand Down Expand Up @@ -154,15 +154,15 @@ function checkTool (tool, minVersion, message, toolFriendlyName) {
// Check whether tool command is available at all
const tool_command = shell.which(tool);
if (!tool_command) {
return Q.reject(`${toolFriendlyName} was not found. ${message || ''}`);
return Promise.reject(new CordovaError(`${toolFriendlyName} was not found. ${message || ''}`));
}

// check if tool version is greater than specified one
return versions.get_tool_version(tool).then(version => {
version = version.trim();
return versions.compareVersions(version, minVersion) >= 0
? Q.resolve({ version })
: Q.reject(`Cordova needs ${toolFriendlyName} version ${minVersion} or greater, you have version ${version}. ${message || ''}`);
? Promise.resolve({ version })
: Promise.reject(new CordovaError(`Cordova needs ${toolFriendlyName} version ${minVersion} or greater, you have version ${version}. ${message || ''}`));
});
}

Expand Down Expand Up @@ -210,7 +210,7 @@ module.exports.check_all = () => {
return promise.then(() => {
// If fatal requirement is failed,
// we don't need to check others
if (fatalIsHit) return Q();
if (fatalIsHit) return Promise.resolve();

const requirement = requirements[idx];
return checkFn()
Expand All @@ -224,7 +224,7 @@ module.exports.check_all = () => {
result.push(requirement);
});
});
}, Q())
}, Promise.resolve())
// When chain is completed, return requirements array to upstream API
.then(() => result);
};
4 changes: 2 additions & 2 deletions bin/templates/scripts/cordova/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
* under the License.
*/

const Q = require('q');
const path = require('path');
const shell = require('shelljs');
const execa = require('execa');
const { CordovaError } = require('cordova-common');

const projectPath = path.join(__dirname, '..', '..');

module.exports.run = () => {
const projectName = shell.ls(projectPath).filter(name => path.extname(name) === '.xcodeproj')[0];

if (!projectName) {
return Q.reject(`No Xcode project found in ${projectPath}`);
return Promise.reject(new CordovaError(`No Xcode project found in ${projectPath}`));
}

const xcodebuildClean = configName => {
Expand Down
3 changes: 1 addition & 2 deletions bin/templates/scripts/cordova/lib/list-emulator-images
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
under the License.
*/

var Q = require('q');
var iossim = require('ios-sim');

/**
* Gets list of iOS devices available for simulation
* @return {Promise} Promise fulfilled with list of devices available for simulation
*/
function listEmulatorImages () {
return Q.resolve(iossim.getdevicetypes());
return Promise.resolve(iossim.getdevicetypes());
}

exports.run = listEmulatorImages;
Expand Down
20 changes: 11 additions & 9 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

'use strict';
const Q = require('q');

const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports.prepare = function (cordovaProject, options) {
this._config = updateConfigFile(cordovaProject.projectConfig, munger, this.locations);

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

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

return Q().then(() => {
return Promise.resolve().then(() => {
cleanWww(projectRoot, this.locations);
cleanIcons(projectRoot, projectConfig, this.locations);
cleanSplashScreens(projectRoot, projectConfig, this.locations);
Expand Down Expand Up @@ -157,6 +157,8 @@ function updateWww (cordovaProject, destinations) {
'verbose', `Merging and updating files from [${sourceDirs.join(', ')}] to ${targetDir}`);
FileUpdater.mergeAndUpdateDir(
sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);

return Promise.resolve();
}

/**
Expand Down Expand Up @@ -228,7 +230,7 @@ function updateProject (platformConfig, locations) {
return handleBuildSettings(platformConfig, locations, infoPlist).then(() => {
if (name === originalName) {
events.emit('verbose', `iOS Product Name has not changed (still "${originalName}")`);
return Q();
return Promise.resolve();
} else { // CB-11712 <name> was changed, we don't support it'
const errorString =
'The product name change (<name> tag) in config.xml is not supported dynamically.\n' +
Expand All @@ -238,7 +240,7 @@ function updateProject (platformConfig, locations) {
'\tcordova platform rm ios\n' +
'\tcordova platform add ios\n';

return Q.reject(new CordovaError(errorString));
return Promise.reject(new CordovaError(errorString));
}
});
}
Expand Down Expand Up @@ -280,15 +282,15 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
try {
project = projectFile.parse(locations);
} catch (err) {
return Q.reject(new CordovaError(`Could not parse ${locations.pbxproj}: ${err}`));
return Promise.reject(new CordovaError(`Could not parse ${locations.pbxproj}: ${err}`));
}

const origPkg = project.xcode.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER');

// no build settings provided and we don't need to update build settings for launch storyboards,
// then we don't need to parse and update .pbxproj file
if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion && !wkWebViewOnly) {
return Q();
return Promise.resolve();
}

if (origPkg !== pkg) {
Expand Down Expand Up @@ -331,7 +333,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {

project.write();

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

function mapIconResources (icons, iconsDir) {
Expand Down
Loading

0 comments on commit b7c40dc

Please sign in to comment.