Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

OJET Build not waiting for After Build hook to complete

ZacDDec 12 2018 — edited Apr 12 2020

Hello,

I am using JET 5.1 and I've been toying around with adding Google's Workbox to my application.  I want to run some commands after the normal build process has completed, but before the whole process is done.  I've added my code to the /scripts/hooks/after_build.js file and the code is getting executed.  However, the overall build process is not waiting for my code to complete before considering the whole process complete.  This can be seen with ojet build, but it's even more obvious with the ojet serve command because the serving of the app is happening before my build hook completes, which causes incomplete files to get served (my process updates 1 file in the build output).  It seems like the Promise that is returned from the after_build.js hook is being ignored and not waited for.

Here's my after_build.js code:

module.exports = function (configObj) {

    return new Promise((resolve, reject) => {

        console.log("Running after_build hook.");

        //execute commandline command

        var child = require('child_process').exec('workbox injectManifest', function (error, stdout, stderr) {

            if (error !== null) {

                console.log('exec error: ' + error);

                reject('exec error: ' + error);

            } else {

                console.log('workbox manifest injection complete');

                resolve();

            }

        });

        console.log('childProcess.pid ' + child.pid);

    });

};

An example output from my build command is:

$ ojet build web

Cleaning staging path.

Running before_build hook.

Copy files to staging directory.

Copy finished.

Copy library files to staging directory.

Copy finished.

Optimizing svg into SVG sprites.

Svg optimisation task finished.

Compiling sass.

Sass compile finished.

Task index.html cdn bundle injection finished.

Running theme injection task.

Task index.html theme path injection finished.

Running theme copy task.

Theme copy task finished.

Running injection tasks.

Task main.js paths injection finished.

Running after_build hook.

childProcess.pid 11448

Build finished.

workbox manifest injection complete

Notice how the "Build finished." line is printing before my final completion output is printed?  When I tried doing a serve it was even more obvious

$ ojet serve web

Build: true

BuildType: dev

Destination: undefined

Destination target: undefined

Livereload: true

Livereload port: 35729

Platform: web

Port: 8000

Theme: alta

Theme platform: web

Theme version: 5.0.0

Building app.

Cleaning staging path.

Running before_build hook.

Copy files to staging directory.

Copy finished.

Copy library files to staging directory.

Copy finished.

Optimizing svg into SVG sprites.

Svg optimisation task finished.

Compiling sass.

Sass compile finished.

Task index.html cdn bundle injection finished.

Running theme injection task.

Task index.html theme path injection finished.

Running theme copy task.

Theme copy task finished.

Running injection tasks.

Task main.js paths injection finished.

Running after_build hook.

childProcess.pid 1676

Running before_serve hook.

[xmldom warning]        attribute "async" missed value!! "async" instead2!!

@#[line:37,col:9]

[xmldom warning]        attribute "data-oj-context" missed value!! "data-oj-context" instead!!

@#[line:163,col:13]

[xmldom warning]        attribute "data-oj-context" missed value!! "data-oj-context" instead!!

@#[line:232,col:9]

[xmldom warning]        attribute "data-oj-context" missed value!! "data-oj-context" instead2!!

@#[line:255,col:21]

[xmldom warning]        attribute "autofocus" missed value!! "autofocus" instead2!!

@#[line:255,col:21]

[xmldom warning]        attribute "data-oj-context" missed value!! "data-oj-context" instead!!

@#[line:272,col:9]

Starting web server.

Connecting to http://localhost:8000

Starting watcher.

Running after_serve hook.

Server ready: http://localhost:8000

Listening on port 35729.

Watching files.

Watcher: sass is ready.

Watcher: sourceFiles is ready.

Watcher: themes is ready.

workbox manifest injection complete

Any thoughts on this?

This post has been answered by ZacD on Dec 17 2018
Jump to Answer
Comments
Post Details
Added on Dec 12 2018
12 comments
1,337 views