You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2021/07/11 13:47:15 UTC
[cordova-android] branch master updated: refactor(run)!: cleanup
run method (#1266)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new fb36e03 refactor(run)!: cleanup run method (#1266)
fb36e03 is described below
commit fb36e03aebc4d3a994ed78caebda8d141467574a
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Sun Jul 11 15:47:07 2021 +0200
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
---
bin/templates/cordova/lib/run.js | 41 ++++++++++++++++------------------------
spec/unit/run.spec.js | 2 +-
2 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js
index 89de076..75465e9 100644
--- a/bin/templates/cordova/lib/run.js
+++ b/bin/templates/cordova/lib/run.js
@@ -19,8 +19,9 @@
var emulator = require('./emulator');
const target = require('./target');
-var PackageType = require('./PackageType');
-const { events } = require('cordova-common');
+const build = require('./build');
+const PackageType = require('./PackageType');
+const { CordovaError, events } = require('cordova-common');
/**
* Builds a target spec from a runOptions object
@@ -54,32 +55,22 @@ function formatResolvedTarget ({ id, type }) {
*
* @return {Promise}
*/
-module.exports.run = function (runOptions) {
- runOptions = runOptions || {};
-
- var self = this;
+module.exports.run = async function (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) {
- events.emit('log', `Deploying to ${formatResolvedTarget(resolvedTarget)}`);
-
- return new Promise((resolve) => {
- const buildOptions = require('./build').parseBuildOptions(runOptions, null, self.root);
+ const { packageType, buildType } = build.parseBuildOptions(runOptions, null, this.root);
- // Android app bundles cannot be deployed directly to the device
- if (buildOptions.packageType === PackageType.BUNDLE) {
- const packageTypeErrorMessage = 'Package type "bundle" is not supported during cordova run.';
- events.emit('error', packageTypeErrorMessage);
- throw packageTypeErrorMessage;
- }
+ // Android app bundles cannot be deployed directly to the device
+ if (packageType === PackageType.BUNDLE) {
+ throw new CordovaError('Package type "bundle" is not supported during cordova run.');
+ }
- resolve(self._builder.fetchBuildResults(buildOptions.buildType, buildOptions.arch));
- }).then(async function (buildResults) {
- if (resolvedTarget.type === 'emulator') {
- await emulator.wait_for_boot(resolvedTarget.id);
- }
+ const buildResults = this._builder.fetchBuildResults(buildType);
- return target.install(resolvedTarget, buildResults);
- });
- });
+ if (resolvedTarget.type === 'emulator') {
+ await emulator.wait_for_boot(resolvedTarget.id);
+ }
+ return target.install(resolvedTarget, buildResults);
};
diff --git a/spec/unit/run.spec.js b/spec/unit/run.spec.js
index 5bd4e01..5445544 100644
--- a/spec/unit/run.spec.js
+++ b/spec/unit/run.spec.js
@@ -77,7 +77,7 @@ describe('run', () => {
it('should fail with the error message if --packageType=bundle setting is used', () => {
targetSpyObj.resolve.and.resolveTo(resolvedTarget);
return expectAsync(run.run({ argv: ['--packageType=bundle'] }))
- .toBeRejectedWith(jasmine.stringMatching(/Package type "bundle" is not supported/));
+ .toBeRejectedWithError(/Package type "bundle" is not supported/);
});
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org