forked from github/cordova-android
refactor(run)!: cleanup run method (#1266)
* refactor(run)!: get rid of emit-and-throw & throw-literal antipatterns * refactor(run)!: convert run method to async/await * refactor(run): require build module in advance * refactor(run): minor cleanup * refactor(run): drop always-undefined option arch `parseBuildOptions` only sets `arch` if something truthy is passed for parameter `resolvedTarget` to which we pass `null`. * refactor(run): destructure buildOptions
This commit is contained in:
parent
8a9cb8f6b7
commit
fb36e03aeb
41
bin/templates/cordova/lib/run.js
vendored
41
bin/templates/cordova/lib/run.js
vendored
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
var emulator = require('./emulator');
|
var emulator = require('./emulator');
|
||||||
const target = require('./target');
|
const target = require('./target');
|
||||||
var PackageType = require('./PackageType');
|
const build = require('./build');
|
||||||
const { events } = require('cordova-common');
|
const PackageType = require('./PackageType');
|
||||||
|
const { CordovaError, events } = require('cordova-common');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a target spec from a runOptions object
|
* Builds a target spec from a runOptions object
|
||||||
@ -54,32 +55,22 @@ function formatResolvedTarget ({ id, type }) {
|
|||||||
*
|
*
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
module.exports.run = function (runOptions) {
|
module.exports.run = async function (runOptions = {}) {
|
||||||
runOptions = runOptions || {};
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
const spec = buildTargetSpec(runOptions);
|
const spec = buildTargetSpec(runOptions);
|
||||||
|
const resolvedTarget = await target.resolve(spec);
|
||||||
|
events.emit('log', `Deploying to ${formatResolvedTarget(resolvedTarget)}`);
|
||||||
|
|
||||||
return target.resolve(spec).then(function (resolvedTarget) {
|
const { packageType, buildType } = build.parseBuildOptions(runOptions, null, this.root);
|
||||||
events.emit('log', `Deploying to ${formatResolvedTarget(resolvedTarget)}`);
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
// Android app bundles cannot be deployed directly to the device
|
||||||
const buildOptions = require('./build').parseBuildOptions(runOptions, null, self.root);
|
if (packageType === PackageType.BUNDLE) {
|
||||||
|
throw new CordovaError('Package type "bundle" is not supported during cordova run.');
|
||||||
|
}
|
||||||
|
|
||||||
// Android app bundles cannot be deployed directly to the device
|
const buildResults = this._builder.fetchBuildResults(buildType);
|
||||||
if (buildOptions.packageType === PackageType.BUNDLE) {
|
|
||||||
const packageTypeErrorMessage = 'Package type "bundle" is not supported during cordova run.';
|
|
||||||
events.emit('error', packageTypeErrorMessage);
|
|
||||||
throw packageTypeErrorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(self._builder.fetchBuildResults(buildOptions.buildType, buildOptions.arch));
|
if (resolvedTarget.type === 'emulator') {
|
||||||
}).then(async function (buildResults) {
|
await emulator.wait_for_boot(resolvedTarget.id);
|
||||||
if (resolvedTarget.type === 'emulator') {
|
}
|
||||||
await emulator.wait_for_boot(resolvedTarget.id);
|
return target.install(resolvedTarget, buildResults);
|
||||||
}
|
|
||||||
|
|
||||||
return target.install(resolvedTarget, buildResults);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
@ -77,7 +77,7 @@ describe('run', () => {
|
|||||||
it('should fail with the error message if --packageType=bundle setting is used', () => {
|
it('should fail with the error message if --packageType=bundle setting is used', () => {
|
||||||
targetSpyObj.resolve.and.resolveTo(resolvedTarget);
|
targetSpyObj.resolve.and.resolveTo(resolvedTarget);
|
||||||
return expectAsync(run.run({ argv: ['--packageType=bundle'] }))
|
return expectAsync(run.run({ argv: ['--packageType=bundle'] }))
|
||||||
.toBeRejectedWith(jasmine.stringMatching(/Package type "bundle" is not supported/));
|
.toBeRejectedWithError(/Package type "bundle" is not supported/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user