evshiron / nwjs-builder

https://www.npmjs.com/package/nwjs-builder
76 stars 12 forks source link

Programmatically use nwjs-builder #17

Closed orther closed 8 years ago

orther commented 8 years ago

I was using nw-builder from my gulp task to build my nw.js app but am using nwjs-builder now that I am using nw.js@0.14.5. It would be nice if this module could be imported and used programmatically like nw-builder allows.

Here is an example if how I was using nw-builder in a gulp task (gulp-tasks/build-app.js):

const nwBuilder = require('nw-builder');

module.exports = function (gulp, plugins, config) {
    const srcDir = config.build.bundle.dir;
    const destDir = config.build.app.dir;
    const iconsDir = config.assets.icons.dir;

    return function(cb) {
        const nw = new nwBuilder({
            files: [
                `${srcDir}/**/**`,
                './node_modules/auto-launch/**/**',
            ],
            version: '0.14.4',
            buildDir: destDir,
            platforms: ['osx64', 'win32'],
            macIcns: `${iconsDir}/main.icns`,
            winIco: `${iconsDir}/main.ico`,
        });

        nw.build(cb);
    };
};

I have looked through the source of this probject but it doesn't seem like this is supported. For the time being I am just using exec to call the nwb command in another process which is not ideal (one problem I have with this method is that the nwb command doesn't seem to return exit codes to indicated errors).

Any information or advice for using this within a build tools programmatically would be greatly appreciated. Thanks for building this utility!

evshiron commented 8 years ago

Glad to hear that. The feature is added in 6ea4966, and README is updated too. However the example test has failed, indicating that if you use this as a module, you might need some flags like --harmony-destructuring to make it works, though node.js 6.x should works. See also #18.

orther commented 8 years ago

Sweet! I am now using those changes. I am having errors when I set the mac icns but I will create an issue for that.

FYI for anyone wanting to use this module with gulp (or other build tools) I had to add the following code toward the top of my gulpfile.babel.js to get it to work:

// required for nwjs-builder module
require("babel-polyfill");
require("babel-register")({
    ignore: /node_modules\/(?!nwjs-builder|nwjs-download)/,
});
evshiron commented 8 years ago

Thanks for the code snippet, close now as it has been solved.

orther commented 8 years ago

This is great. I really appreciate your steady work on this.