Code Monkey home page Code Monkey logo

nwjs-builder's Introduction

nwjs-builder Travis CI AppVeyor NPM Version NPM Downloads

A command line utility for building nw.js applications, compatible with nwjs/nw-builder, and maybe better.

Tested to work for node.js 0.10/0.11/4.0/4.1/5.0/6.0 on Windows, Linux and Mac OS X.

NPM

I would now recommend using evshiron/nwjs-builder-phoenix.

Features

  • Use http://nwjs.io/versions.json (powered by evshiron/nwjs-download)
  • Use ECMAScript 6
  • Support
    • All major versions (listed in versions.json)
    • All platforms (win32, linux, darwin)
    • All flavors (normal, sdk, nacl, macappstore)
  • Advanced options
    • Build with ffmpeg prebuilt
    • Build without packaging
    • Reinstall node modules for production
    • Replace icon, name, description and etc.
    • ...
  • Actively maintained

Install

$ npm install nwjs-builder -g

The npm install evshiron/nwjs-builder method is deprecated, which will no longer work because there is no prebuilt stuff in the repo, and .npmignore will simply ignore ./src/, resulting in an empty installation.

Usage

# Commands adapted from nwjs-download.

# List versions.
$ nwb list

# Show latest version.
$ nwb latest

# Show stable version.
$ nwb stable

# Show caches.
$ nwb caches

# Commands compatible with nw-builder.

$ nwb nwbuild -h

  Usage: nwbuild [options] [PATH_OR_ARGS...]

  Options:

    -h, --help                                output usage information
    -v,--version <VERSION>                    The nw.js version, eg. 0.8.4, defaults to the stable version.
    -p,--platforms <PLATFORMS>                Platforms to build, comma-sperated, eg. win32,win64,osx32,osx64,linux32,linux64, defaults to the current platform.
    -r,--run                                  Runs nw.js at PATH for the current platform.
    -o,--output-dir <DIR_OUTPUT>              The output directory, defaults to PATH's parent.
    -i,--include <DIR_SRC>:<GLOB>[:DIR_DEST]  Include extra files matching GLOB from DIR_SRC to DIR_BUILD/DIR_DEST.
    -m,--mirror <URL_MIRROR>                  Where the binaries are downloaded from, defaults to http://dl.nwjs.io.
    --output-name <NAME_OUTPUT>               Specify a template for output naming, defaults to {name}-{target}.
    --executable-name <NAME_EXECUTABLE>       Specify the name for the final executable, defaults to manifest.name.
    --output-format <DIR|ZIP>                 Specify the output format, defaults to DIR.
    --with-ffmpeg                             Fetch nwjs-ffmpeg-prebuilt to support .mp3 etc.
    --side-by-side                            Build application with side by side packaging.
    --production                              Reinstall dependencies for production purpose.
    --win-ico <WIN_ICO>                       Specify .ico for Windows build.
    --mac-icns <MAC_ICNS>                     Specify .icns for Mac OS X build.
    --detached                                For "--run", NWB exits after launching nw.js.

# Launch application.
$ nwb nwbuild -v 0.14.4-sdk -r ./build/

# Launch application with arguments.
$ nwb nwbuild -v 0.14.4-sdk -r ./build/ -a bbb

# Launch application with arguments and remote debugging enabled.
$ nwb nwbuild -v 0.14.4-sdk -r -- --remote-debugging-port=9222 ./build/ -a bbb

# Build application for win32,osx64.
$ nwb nwbuild -v 0.14.4-sdk -p win32,osx64 ./build/

# Build application for win32,osx64, with custom icons and without packaging.
$ nwb nwbuild -v 0.14.4-sdk -p win32 --win-ico app.ico --mac-icns app.icns --side-by-side ./build/

Use As Module

nwjs-builder is able to work as a node.js module as well. The solution is somewhat tricky, but it works definitely.

const NWB = require('nwjs-builder');
NWB.commands.nwbuild(path, options, callback);

The above code snippet directly calls the underneath command handler, and the options is a fake commander.js command object (as all we need are the options). A test named test-module.js is provided as a reference.

Manifest Options

The following manifest options are used to modify executable information, powered by atom/node-rcedit.

{
    // Normal package.json properties.
    "name": "nwb-test",
    "version": "0.0.1",
    "description": "nwb-test",
    // Additional options.
    "nwjsBuilder": {
        // Optionally overwrite `name`, `version` and `description`.
        "productName": "",
        "productVersion": "",
        "fileDescription": "",
        // Other options.
        // For Windows.
        "copyright": "",
        "internalName": "",
        "fileVersion": "",
        "comments": "",
        "companyName": "",
        "legalTrademarks": "",
        "originalFilename": "",
        "privateBuild": "",
        "specialBuild": "",
        // For Mac OS X.
        "bundleIdentifier": ""
    }
}

Development

I am still learning about how to form a modern node.js module well. As a result, the project structure might change from time to time.

While new features are added, some existing features might break too.

If anything doesn't work properly, feel free to open issues and provide enough information so that things can be quickly fixed.

PRs and issues are always appreciated.

For feature requests:

nwjs-builder is aimed at running/packaging nw.js applications, and is designed to work with a directory that is well-prepared to be packaged.

I will usually refuse requests for a feature which is achievable by other popular node.js modules, and you can use build.sh, Makefile, gulp or grunt to organize your building pipeline. I don't want to add an option just to proxy it to another module.

Platform-specified and configuration-rich features like making .dmg (Mac OS X only), .exe or .deb will usually be refused too. I don't want to learn how to integrate something I will rarely use and decide to leave it to you :)

See also:

Mirrors

There are some mirrors available on the Internet, which are supported with --mirror option:

License

MIT.

nwjs-builder's People

Contributors

evshiron avatar fengmk2 avatar stackmagic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nwjs-builder's Issues

ICON missing in .exe when compiling from MAC to WIN

Hi! Thanks for your work! Works like a charm!
Now I am trying to compile my project using a script in npm (npm run prodWIN) like this:
"scripts": {
"prodWIN": "nwb nwbuild -p win64 -o ./../build/ --side-by-side --output-format ZIP --win-ico ./img/Icon1024.ico",
}
And compile great! But in my .exe file, when I run in Windows, doesn't have the icon. Only appears in the Title Bar, at the left side of the name. Do you know why? Will I have to use ResourceHacker manually?
Thanks for your time

Cannot build without side-by-side

Win 10, Node 4.4, nwjs 0.14.5, nwjs-builder 1.6.0

Can't open my app if I use --side-by-side to build it. Getting a checksum error when using 7zip to unzip the .exe binary. Any idea why that could be?

readme fix :)


# List versions.
$ nwd list

# Show latest version.
$ nwd latest

# Show stable version.
$ nwd stable

# Show caches.
$ nwd caches

$ nwb nwbuild -h


nwd -> nwb, please.

use displayName as binary output name

currently, npm spec says that "name" property in package.json should be lowercase (https://docs.npmjs.com/files/package.json), but since this is used as the binary filename, our final output ends up as "name.exe" or "name.app" instead of "Name.exe" or "Name.app".

Ideally the binary would use the "displayName" property, which is case sensitive (this was the behaviour of the now deprecated nw-builder)

Generated exe starts slowly on Windows

When I package my app (without the "side-by-side" option), startup of the generated app can take one to two minutes (only tested on Windows 10). This happens every time, not just on the first launch.

When I package it with side-by-side, the app launches instantly. Here's the command I'm using:

nwb nwbuild --with-ffmpeg -p win64 --output-name myapp -o build --executable-name myapp --win-ico app.ico

Executable for Linux and Windows

Looks like #!/usr/bin/env node --harmony-destructuring --harmony-rest-parameters doesn't work on Ubuntu, but does work on Mac OS X. What about Windows?

CI Failure

Currently I am messing around in the develop branch, adding tests for combined applications.
Travis CI has moved to container-based worker during the tests, so there is no more sudo and .travis.yml needs some fixes to work (fixed in develop branch though). But it's strange to see "error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory", while nwbuild -r works.
AppVeyor has been working well so far. But as I have mentioned in #9, it's expected to see some timeouts when testing combined applications for node.js 4.0.0 and before.

Travis CI Failure

No idea how it fails to build now. Earlier builds became failed after I restarted the job.

Refactor?

At first, I want to do some cleaning in the build binary procedures.
Currently the procedure is just too long and sharing too many variables, along with the limited destructuring support from node.js 4.x/5.x (destructuring can't be used without a let/const/var keyword, and same variable name can't be let twice), it brings some pain to me.
Anyway, supporting for node.js 4.x/5.x is a must. I have been thinking about workarounds to overcome this issue.
In the next refactor, I will bind an object to the generator, which is used to store constants, and every variable in the generator will be declared with var. This should help developers distinguish the purpose of the many variables.

Exclude folder files

It is possible to exclude files from the primary folder (like README, etc)?...

Including node_modules (or other folders/files) in built app.

I need to include a node module in the built app and I am not sure if this is supported with nwjs-builder. The specific module I need to include is auto-launch.

Does anyone have a suggestion(s) for handling this situation when using nwjs-builder? I suppose I could manually copy over the ./node_modules/auto-launch into my srcDir before running nwjs-builder build command.


For reference I solved this with nw-builder using an array in the files param like so:

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

This essentially this copied the ./node_modules/auto-launch folder into app.nw.

Support for node.js 0.10/0.11

I was trying to modify the source to provide support for node.js 0.10/0.11, but I failed because babel-plugin-transform-runtime didn't extend String.prototype and as a result String.endsWith threw an Error and crashed.
As it's outlined on babel's documentation, I am not going to make a feature request but decide to make something like babel-plugin-insert-polyfill to automatically require babel-polyfill at the beginning of the generated files.

Excluding files

Is there a way to exclude files from the final bundle? There are many things that are bloating my package, like test files and documentation and such.

Programmatically use nwjs-builder

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 [email protected]. 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!

Travis CI Build Failed

I have added a test/test-module.js, which uses in progress features like destructuring (--harmony-destructuring will fix, but it also prevent node.js 6.x from launching), and the Windows build process on Linux requires a usable wine. That's why the Travis CI build failed.
Any ideas about how to fix this?

AppVeyor Failure

Due to EPERM when cleaning up the temporary files before exiting.

Reading and writing files

I have an nw app that reads and writes files to "./file"
The reading and writing seems to be working ok, but when I close and open the aplication it doesn't read the last modification of the file.
What can be done?
(I have only tested on windows x64 and it didn't work).
I would like a solution that works on all platforms.
Thank you

Fatal error: Unable to load file

OS: Windows 10
Node: v5.1.0
npm: 3.3.12

Nick@DESKTOP-78VVOH6 MINGW64 /f/Code/stryve-app/build (v0.3.0-beta)
$ nwb nwbuild -v 0.14.4-sdk -p win32,win64 --win-ico ./favicon.ico  ../
{ version: 'v0.14.4',
  flavor: 'sdk',
  targets: [ [ 'win', 'x86' ], [ 'win', 'x64' ] ],
  path: '../' }
0: Read package.json
1: Prepare build directory at stryve-app-win-ia32
2: Copy binary from C:\Users\Nick\.nwjs-builder\caches\binary-nwjs-sdk-v0.14.4-win-ia32
3: Make working directory
4: Compress application
5: Combine executable at stryve-app-win-ia32\nw.exe
6: Edit Windows executable
Fatal error: Unable to load file

I run all my code from a secondary drive (F:) as opposed to C:. Would that make any difference?

Also worthy to note that the below worked

Nick@DESKTOP-78VVOH6 MINGW64 /f/Code/stryve-app/build (v0.3.0-beta)
$ nwb nwbuild -v 0.14.4-sdk -p win32,win64 --win-ico ../favicon.ico --side-by-side ../
{ version: 'v0.14.4',
  flavor: 'sdk',
  targets: [ [ 'win', 'x86' ], [ 'win', 'x64' ] ],
  path: '../' }
0: Read package.json
1: Prepare build directory at stryve-app-win-ia32
2: Copy binary from C:\Users\Nick\.nwjs-builder\caches\binary-nwjs-sdk-v0.14.4-win-ia32
3: Make working directory
4: Copy application from C:\Users\Nick\AppData\Local\Temp\d-116418-4108-1cltum8
5: Edit Windows executable
6: Rename application to stryve-app.exe
7: Done
win-ia32 build: F:\Code\stryve-app\build\stryve-app-win-ia32.

0: Read package.json
1: Prepare build directory at stryve-app-win-x64
2: Copy binary from C:\Users\Nick\.nwjs-builder\caches\binary-nwjs-sdk-v0.14.4-win-x64
3: Make working directory
4: Copy application from C:\Users\Nick\AppData\Local\Temp\d-116418-4108-1u5ct2z
5: Edit Windows executable
6: Rename application to stryve-app.exe
7: Done
win-x64 build: F:\Code\stryve-app\build\stryve-app-win-x64.

Windows icon does not scale correctly

When my app is exported using the win-ico option the resulting executable has an icon that does not scale. This means that it appears pixelated when set as a desktop icon, pinned to the Windows 10 start screen or simply zoomed into in the File Explorer.

Using Resource Hacker I can see that an icon group with different sizes has been generated; it just does not seem to be using them correctly.

Can`t build for v0.12.3

In folder with my project I try to do :

MacBook-Air-Vitaliy:change_ip scorpio$ nwb nwbuild -v 0.12.3-sdk -p win32,osx64 ./build/
ERROR_VERSION_NOT_FOUND
version: 0.12.3-sdk
versions: [ 'v0.15.1',
'v0.14.6',
'v0.15.0',
'v0.15.0-rc2',
'v0.14.5',
'v0.14.4',
'v0.15.0-rc1',
'v0.15.0-beta2',
'v0.14.3',
'v0.15.0-beta1',
'v0.14.2',
'v0.14.1',
'v0.14.0',
'v0.13.4',
'v0.14.0-rc3',
'v0.13.3',
'v0.14.0-rc2',
'v0.14.0-rc1',
'v0.13.2',
'v0.13.1',
'v0.13.0',
'v0.13.0-rc4',
'v0.13.0-rc3',
'v0.13.0-rc2',
'v0.13.0-rc1',
'v0.13.0-beta7',
'v0.13.0-beta6',
'v0.13.0-beta5',
'v0.13.0-beta4',
'v0.13.0-beta3',
'v0.13.0-beta2',
'v0.13.0-beta1',
'v0.12.3' ]
MacBook-Air-Vitaliy:change_ip scorpio$

or

MacBook-Air-Vitaliy:change_ip scorpio$ nwb nwbuild -v 0.13.1-sdk -p win32,osx64
{ version: 'v0.13.1',
flavor: 'sdk',
targets: [ [ 'win', 'x86' ], [ 'osx', 'x64' ] ],
path: '.' }
0: Read package.json
1: Prepare build directory at changeaddress-win-ia32
2: Copy binary from /Users/scorpio/.nwjs-builder/caches/binary-nwjs-sdk-v0.13.1-win-ia32
3: Edit Windows executable
{ [Error: spawn wine ENOENT]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn wine',
path: 'wine',
spawnargs:
[ '/usr/local/lib/node_modules/nwjs-builder/node_modules/rcedit/bin/rcedit.exe',
'changeaddress-win-ia32/nw.exe',
'--set-version-string',
'ProductName',
'tst',
'--set-version-string',
'FileDescription',
'none',
'--set-product-version',
'0.0.1' ] }
MacBook-Air-Vitaliy:change_ip scorpio$

Where is mistake?

Win64 production build : I keep having the default "blank" nwjs page

Hello,

I'm on mac and using a VM to build for windows.

When I run nwb nwbuild -v 0.16.1 --production -p win64 -o bin-test4 ./ and start the .exe generated I get the blank nodewebkit screen (the one with the glowing effect like when you start nwjs(or nw.exe on windows without an actual app)). Same result without --production.

When I run nwb nwbuild -v 0.16.1 -p win64 -r bin-test4 ./ the app runs OK.

Is this a know issue ? What am I missing ?

The same command works on mac (with -p osx64 of course).

It seems the production build does not include the source files (html and stuff like that) and therefore we get the blank nwjs page. But with the -r flag it works. Hmm. No idea. Please help.

"AssertionError: undefined == true"

I get this error when trying to package my app:

λ nwb nwbuild -v 0.18.2-sdk -o "windows" -p win32 --side-by-side .
{ version: 'v0.18.2',
  flavor: 'sdk',
  targets: [ [ 'win', 'x86' ] ],
  path: '.' }
0: Read package.json
1: Prepare build directory at windows\app-win-ia32
2: Copy binary from C:\Users\miparnisari\.nwjs-builder\caches\binary-nwjs-sdk-v0.18.2-win-ia32
3: Edit Windows executable

C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\node_modules\regenerator-runtime\runtime.js:522
        throw exception;
        ^
 AssertionError: undefined == true
    at Object._callee2$ (C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\lib\build\win32.js:210:25)
    at tryCatch (C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\node_modules\regenerator-runtime\runtime.js:62:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\node_modules\regenerator-runtime\runtime.js:336:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\node_modules\regenerator-runtime\runtime.js:95:21)
    at Immediate._onImmediate (C:\Users\miparnisari\AppData\Roaming\npm\node_modules\nwjs-builder\node_modules\node-async-flow\lib\index.js:15:22)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

[Feature Request] Zipping Platform Build Option

Would be great if the build process included an option for outputting a zipped version of the build, as opposed to a large build folder.

I have implemented this in my build.js script, but seems like it should be something included in this package as an option.

Somthing like this:

$ nwb nwbuild -h

  Usage: nwbuild [options] [PATH_OR_ARGS...]

  Options:
    -z,--zip                                  Outputs a zipped version of each platform build

Missing .desktop launch file in Linux builds

For both the 32 and 64 Linux builds, there is no .desktop file that is necessary to launch the application.

You can read the specs for a .desktop file here

Below is the example I have used in my application

Filename: launcher.desktop

[Desktop Entry]
Version={version}
Name={name}
Comment={description}
Exec=bash -c '_PWD="$PWD"; cd "`echo $0 | sed s/launcher.desktop$//`"; ./{name} run; cd "_PWD"' %k
Icon=needs_to_be_the_absolute_file_path_to_your_app/my-logo.png
Terminal=false
Type=Application
Categories=Utility;Application;

I found the Exec command which works great, but not sure how to populate the Icon path since it needs to be the absolute path to the project. However, once the files are extracted we wont know where this path is. Perhaps you can come up with a solution.

Also note that the .desktop file needs to have execution permissions, but I don't this can be done when packing the zip. At least from from my own testing I wasn't able save the file permission after zipping the directory.

Manifest Options

Predicting final name, version, description and etc. simply from package.json might not content every situation. An optional manifest property collection should help.
I am thinking about adding a nwjsBuilder property in the package.json, which contains:

{
    "copyright": "",
    "internalName": "",
    "fileVersion": "",
    "comments": "",
    "companyName": "",
    "legalTrademarks": "",
    "originalFilename": "",
    "privateBuild": "",
    "specialBuild": ""
}

Every property is optional and if it's omitted, nothing is modified (no longer use the original properties except name, version and description).
Most of the properties above are Windows build only, Mac OS X build may take advantage of them too.

Build is showing default NW.js window

Hi,

When I try to build from Linux to Windows I get the default NW.js window (Tried 32 and 64 bits versions) :
capture

My package.json seems correct as it runs well if I launch the app manually using the nw.js binary.

Thanks for you help 😄.

Extract & use already downloaded nw.js

Greetings, in the some situations I've download the nw.js using some app due low connection speed.
Can you include feature "Extact and cache already downloaded nw.js builds from path"?

e.g. download what I needmanually, put them to some "/cache/downloaded/" and run "nwd cache invalidate"

Exclude specified files and sub-directories

Similar to #33, it is possible to exclude particular files and sub-directories from being exported?

For instance my app has a docs folder and a README file - both of which do not need to be included in the output packages.

Name, Description, Company, etc.

Right now, nwjs-builder uses the default nwjs/Chromium copyright, original filename, product name, etc. I need to use Resource Hacker to rewrite those values to my own product. Ideally I wouldn't have to do that. Any plans to add that?

image

On a separate note, any idea why I need to use side-by-side packaging now? In older versions of nwjs (0.12) I was able to build just fine using grunt-nw-builder and it would package my js/html into the nw.exe. However that doesn't work in 0.14.5 and your nwjs-builder. My app only loads if side-by-side is enabled. Could it be a path issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.