Skip to content

Commit db95264

Browse files
committed
breaking: remove q dependency
1 parent 8d002cd commit db95264

25 files changed

+116
-121
lines changed

bin/apple_ios_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
var versions = require('./templates/scripts/cordova/lib/versions.js');
2323

24-
versions.get_apple_ios_version().done(null, function (err) {
24+
versions.get_apple_ios_version().catch(err => {
2525
console.log(err);
2626
process.exit(2);
2727
});

bin/apple_osx_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
var versions = require('./templates/scripts/cordova/lib/versions.js');
2323

24-
versions.get_apple_osx_version().done(null, function (err) {
24+
versions.get_apple_osx_version().catch(err => {
2525
console.log(err);
2626
process.exit(2);
2727
});

bin/apple_xcode_version

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121

2222
var versions = require('./templates/scripts/cordova/lib/versions.js');
2323

24-
versions.get_apple_xcode_version().done(function (version) {
25-
console.log(version);
26-
}, function (err) {
27-
console.error(err);
28-
process.exit(2);
29-
});
24+
versions.get_apple_xcode_version().then(
25+
version => {
26+
console.log(version);
27+
},
28+
err => {
29+
console.error(err);
30+
process.exit(2);
31+
}
32+
);

bin/check_reqs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var check_reqs = require('./templates/scripts/cordova/lib/check_reqs');
2525
if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) > -1) {
2626
console.log('Usage: check_reqs or node check_reqs');
2727
} else {
28-
check_reqs.run().done(null, function (err) {
28+
check_reqs.run().catch(err => {
2929
console.error('Failed to check requirements due to ' + err);
3030
process.exit(2);
3131
});

bin/lib/create.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
under the License.
1818
*/
1919

20-
const Q = require('q');
2120
const path = require('path');
2221
const fs = require('fs-extra');
2322
const xmlescape = require('xml-escape');
2423
const ROOT = path.join(__dirname, '..', '..');
25-
const events = require('cordova-common').events;
24+
const { CordovaError, events } = require('cordova-common');
2625
const utils = require('./utils');
2726

2827
function updateSubprojectHelp () {
@@ -204,12 +203,12 @@ exports.createProject = (project_path, package_name, project_name, opts, config)
204203

205204
// check that project path doesn't exist
206205
if (fs.existsSync(project_path)) {
207-
return Q.reject('Project already exists');
206+
return Promise.reject(new CordovaError('Project already exists'));
208207
}
209208

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

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

237236
events.emit('log', generateDoneMessage('create', use_shared));
238-
return Q.resolve();
237+
return Promise.resolve();
239238
};
240239

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

251-
return Q.reject(errorString);
250+
return Promise.reject(new CordovaError(errorString));
252251
};
253252

254253
function generateDoneMessage (type, link) {

bin/templates/scripts/cordova/Api.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const CordovaError = require('cordova-common').CordovaError;
3737
const CordovaLogger = require('cordova-common').CordovaLogger;
3838
const events = require('cordova-common').events;
3939
const PluginManager = require('cordova-common').PluginManager;
40-
const Q = require('q');
4140
const util = require('util');
4241
const xcode = require('xcode');
4342
const ConfigParser = require('cordova-common').ConfigParser;
@@ -278,10 +277,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
278277
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
279278
return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
280279
}
281-
})
282-
// CB-11022 return non-falsy value to indicate
283-
// that there is no need to run prepare after
284-
.thenResolve(true);
280+
});
285281
};
286282

287283
/**
@@ -327,10 +323,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
327323
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
328324
return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
329325
}
330-
})
331-
// CB-11022 return non-falsy value to indicate
332-
// that there is no need to run prepare after
333-
.thenResolve(true);
326+
});
334327
};
335328

336329
/**
@@ -449,7 +442,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp
449442
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
450443
}
451444
}
452-
return Q.when();
445+
return Promise.resolve();
453446
};
454447

455448
/**
@@ -567,7 +560,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst
567560
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
568561
}
569562
}
570-
return Q.when();
563+
return Promise.resolve();
571564
};
572565

573566
/**

bin/templates/scripts/cordova/build

+10-7
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ buildOpts.argv = buildOpts.argv.remain;
5454

5555
require('./loggingHelper').adjustLoggerLevel(buildOpts);
5656

57-
new Api().build(buildOpts).done(function () {
58-
console.log('** BUILD SUCCEEDED **');
59-
}, function (err) {
60-
var errorMessage = (err && err.stack) ? err.stack : err;
61-
console.error(errorMessage);
62-
process.exit(2);
63-
});
57+
new Api().build(buildOpts).then(
58+
() => {
59+
console.log('** BUILD SUCCEEDED **');
60+
},
61+
err => {
62+
var errorMessage = (err && err.stack) ? err.stack : err;
63+
console.error(errorMessage);
64+
process.exit(2);
65+
}
66+
);

bin/templates/scripts/cordova/clean

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ opts.noPrepare = true;
4141

4242
require('./loggingHelper').adjustLoggerLevel(opts);
4343

44-
new Api().clean(opts).done(function () {
45-
console.log('** CLEAN SUCCEEDED **');
46-
}, function (err) {
47-
console.error(err);
48-
process.exit(2);
49-
});
44+
new Api().clean(opts).then(
45+
() => {
46+
console.log('** CLEAN SUCCEEDED **');
47+
},
48+
err => {
49+
console.error(err);
50+
process.exit(2);
51+
}
52+
);

bin/templates/scripts/cordova/lib/Podfile.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
const fs = require('fs-extra');
2222
const path = require('path');
2323
const util = require('util');
24-
const Q = require('q');
2524
const {
2625
CordovaError,
2726
events,
@@ -376,7 +375,7 @@ Podfile.prototype.before_install = function (toolOptions) {
376375
fs.writeFileSync(debugConfigPath, debugContents, 'utf8');
377376
fs.writeFileSync(releaseConfigPath, releaseContents, 'utf8');
378377

379-
return Q.resolve(toolOptions);
378+
return Promise.resolve(toolOptions);
380379
};
381380

382381
Podfile.prototype.install = function (requirementsCheckerFunction) {
@@ -387,7 +386,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
387386
let first = true;
388387

389388
if (!requirementsCheckerFunction) {
390-
requirementsCheckerFunction = Q();
389+
requirementsCheckerFunction = Promise.resolve();
391390
}
392391

393392
return requirementsCheckerFunction()
@@ -396,7 +395,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
396395
if (toolOptions.ignore) {
397396
events.emit('verbose', '==== pod install start ====\n');
398397
events.emit('verbose', toolOptions.ignoreMessage);
399-
return Q.resolve();
398+
return Promise.resolve();
400399
} else {
401400
return spawn('pod', ['install', '--verbose'], opts)
402401
.progress(stdio => {

bin/templates/scripts/cordova/lib/build.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
const Q = require('q');
2120
const path = require('path');
2221
const which = require('which');
2322
const {
23+
CordovaError,
2424
events,
2525
superspawn: { spawn }
2626
} = require('cordova-common');
@@ -112,16 +112,16 @@ module.exports.run = buildOpts => {
112112
buildOpts = buildOpts || {};
113113

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

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

122122
if (buildOpts.buildConfig) {
123123
if (!fs.existsSync(buildOpts.buildConfig)) {
124-
return Q.reject(`Build config file does not exist: ${buildOpts.buildConfig}`);
124+
return Promise.reject(new CordovaError(`Build config file does not exist: ${buildOpts.buildConfig}`));
125125
}
126126
events.emit('log', `Reading build config file: ${path.resolve(buildOpts.buildConfig)}`);
127127
const contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
@@ -211,7 +211,7 @@ module.exports.run = buildOpts => {
211211
writeCodeSignStyle('Automatic');
212212
}
213213

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

@@ -277,7 +277,7 @@ module.exports.run = buildOpts => {
277277
return spawn('xcodebuild', xcodearchiveArgs, { cwd: projectPath, printCommand: true, stdio: 'inherit' });
278278
}
279279

280-
return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8')
280+
return fs.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
281281
.then(checkSystemRuby)
282282
.then(packageArchive);
283283
});
@@ -293,14 +293,14 @@ function findXCodeProjectIn (projectPath) {
293293
const xcodeProjFiles = fs.readdirSync(projectPath).filter(name => path.extname(name) === '.xcodeproj');
294294

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

302302
const projectName = path.basename(xcodeProjFiles[0], '.xcodeproj');
303-
return Q.resolve(projectName);
303+
return Promise.resolve(projectName);
304304
}
305305

306306
module.exports.findXCodeProjectIn = findXCodeProjectIn;

bin/templates/scripts/cordova/lib/check_reqs.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
'use strict';
2121

22-
const Q = require('q');
2322
const which = require('which');
2423
const versions = require('./versions');
24+
const { CordovaError } = require('cordova-common');
2525

2626
const SUPPORTED_OS_PLATFORMS = ['darwin'];
2727

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

6262
function os_platform_is_supported () {
@@ -85,15 +85,15 @@ function checkTool (tool, minVersion, message, toolFriendlyName) {
8585
// Check whether tool command is available at all
8686
const tool_command = which.sync(tool, { nothrow: true });
8787
if (!tool_command) {
88-
return Q.reject(`${toolFriendlyName} was not found. ${message || ''}`);
88+
return Promise.reject(new CordovaError(`${toolFriendlyName} was not found. ${message || ''}`));
8989
}
9090

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

@@ -141,7 +141,7 @@ module.exports.check_all = () => {
141141
return promise.then(() => {
142142
// If fatal requirement is failed,
143143
// we don't need to check others
144-
if (fatalIsHit) return Q();
144+
if (fatalIsHit) return Promise.resolve();
145145

146146
const requirement = requirements[idx];
147147
return checkFn()
@@ -155,7 +155,7 @@ module.exports.check_all = () => {
155155
result.push(requirement);
156156
});
157157
});
158-
}, Q())
158+
}, Promise.resolve())
159159
// When chain is completed, return requirements array to upstream API
160160
.then(() => result);
161161
};

bin/templates/scripts/cordova/lib/clean.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@
1717
* under the License.
1818
*/
1919

20-
const Q = require('q');
2120
const path = require('path');
2221
const fs = require('fs-extra');
23-
const { superspawn: { spawn } } = require('cordova-common');
22+
const {
23+
CordovaError,
24+
superspawn: { spawn }
25+
} = require('cordova-common');
2426

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

2729
module.exports.run = () => {
2830
const projectName = fs.readdirSync(projectPath).filter(name => path.extname(name) === '.xcodeproj');
2931

3032
if (!projectName) {
31-
return Q.reject(`No Xcode project found in ${projectPath}`);
33+
return Promise.reject(new CordovaError(`No Xcode project found in ${projectPath}`));
3234
}
3335

3436
const xcodebuildClean = configName => {

bin/templates/scripts/cordova/lib/listEmulatorImages.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
under the License.
1818
*/
1919

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

2322
/**
2423
* Gets list of iOS devices available for simulation
2524
* @return {Promise} Promise fulfilled with list of devices available for simulation
2625
*/
2726
function listEmulatorImages () {
28-
return Q.resolve(iossim.getdevicetypes());
27+
return Promise.resolve(iossim.getdevicetypes());
2928
}
3029

3130
exports.run = listEmulatorImages;

0 commit comments

Comments
 (0)