Skip to content

Commit

Permalink
feat(android): emit build hook during module build before launching t…
Browse files Browse the repository at this point in the history
…est app
  • Loading branch information
sgtcoolguy committed Oct 15, 2020
1 parent 141bb61 commit 403d7e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
20 changes: 5 additions & 15 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,7 @@ AndroidBuilder.prototype.run = async function run(logger, config, cli, finished)
Builder.prototype.run.apply(this, arguments);

// Notify plugins that we're about to begin.
await new Promise((resolve) => {
cli.emit('build.pre.construct', this, resolve);
});
await new Promise(resolve => cli.emit('build.pre.construct', this, resolve));

// Post build anlytics.
await this.doAnalytics();
Expand Down Expand Up @@ -1545,13 +1543,9 @@ AndroidBuilder.prototype.run = async function run(logger, config, cli, finished)
await this.generateAppProject();

// Build the app.
await new Promise((resolve) => {
cli.emit('build.pre.build', this, resolve);
});
await new Promise(resolve => cli.emit('build.pre.build', this, resolve));
await this.buildAppProject();
await new Promise((resolve) => {
cli.emit('build.post.build', this, resolve);
});
await new Promise(resolve => cli.emit('build.post.build', this, resolve));

// Write Titanium build settings to file. Used to determine if next build can be incremental or not.
await this.writeBuildManifest();
Expand All @@ -1563,12 +1557,8 @@ AndroidBuilder.prototype.run = async function run(logger, config, cli, finished)
}

// Notify plugins that the build is done.
await new Promise((resolve) => {
cli.emit('build.post.compile', this, resolve);
});
await new Promise((resolve) => {
cli.emit('build.finalize', this, resolve);
});
await new Promise(resolve => cli.emit('build.post.compile', this, resolve));
await new Promise(resolve => cli.emit('build.finalize', this, resolve));
} catch (err) {
// Failed to build app. Print the error message and stack trace (if possible), then exit out.
// Note: "err" can be whatever type (including undefined) that was passed into Promise.reject().
Expand Down
16 changes: 10 additions & 6 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,19 @@ AndroidModuleBuilder.prototype.run = async function run(logger, config, cli, fin

// Build the library and output it to "dist" directory.
await this.buildModuleProject();
await this.packageZip();

// Run the built module via "example" project.
await this.runModule();

// Notify plugins that the build is done.
await new Promise((resolve) => {
cli.emit('build.module.post.compile', this, resolve);
});

await this.packageZip();

await new Promise((resolve) => {
cli.emit('build.module.finalize', this, resolve);
});

// Run the built module via "example" project.
await this.runModule(cli);
} catch (err) {
// Failed to build module. Print the error message and stack trace (if possible).
// Note: "err" can be whatever type (including undefined) that was passed into Promise.reject().
Expand Down Expand Up @@ -801,7 +802,7 @@ AndroidModuleBuilder.prototype.packageZip = async function () {
dest.finalize();
};

AndroidModuleBuilder.prototype.runModule = async function () {
AndroidModuleBuilder.prototype.runModule = async function (cli) {
// Do not run built module in an app if given command line argument "--build-only".
if (this.buildOnly) {
return;
Expand Down Expand Up @@ -901,6 +902,9 @@ AndroidModuleBuilder.prototype.runModule = async function () {
const zip = new AdmZip(this.moduleZipPath);
zip.extractAllTo(tmpProjectDir, true);

// Emit hook so modules can also alter project before launch
await new Promise(resolve => cli.emit('create.module.app.finalize', [ this, tmpProjectDir ], resolve));

// Run the temp app.
this.logger.debug(__('Running example project...', tmpDir.cyan));
const buildArgs = [ process.argv[1], 'build', '-p', 'android', '-d', tmpProjectDir ];
Expand Down

0 comments on commit 403d7e2

Please sign in to comment.