Latest version: 0.3.1
The default ports have changed to make room for x64 on osx and windows. See defaults
Support tested up to nwjs v0.25.3
node-nw-snapshot is a cross platform buildserver and client for compiling and testing v8 snapshots of node-webkit code. It's simple to get up and running, if you already have virtual or local machine's running the needed operating systems. It will compile snapshots for any node-webkit version above v0.4.2, and automatically download the specified version for compilation and testing - no more manual fixing of 3 seperate vm's when upgrading your app to a new node-webkit version.
Best of all, no more broken snapshots when deploying a new version of your app.
My application Circadio has an autoupdater that will automatically update the application when i publish a new version. I need to protect my source code, so i use snapshots. I distribute Circadio for Windows, OS X and Linux which means i need some kind of server running on all the platforms for generating the snapshots for "one button deploys". Until now, that server has been extremely minimal and basically just consisted of an exec call and a simple http server.
I started noticing that on almost every deploy, one of my distributions would fail. After looking over my buildscripts, application code and distribution server i couldn't find the source of the problem. What worried me even more, was that on 4 consecutive deploys of the same code, the distribution that failed to run was totally random. The first time it would be the Windows distribution, the next it would be the linux32 distribution, and so on. Sometimes everything just worked.
I finally traced the source of the problem to the snapshot. It seems that nwsnapshot will sometimes fail silently and generate a snapshot that will cause node-webkit to crash on launch. With no way to prevent this from happening, i set out to create node-nw-snapshot.
When the server receives a build command, it will download the specified node-webkit version as needed and inject a small test function (9 LOC) into your snapshot code. The package.json file of your app will be modified to use the generated snapshot. After that, the app will be launched with an automatically generated ID and the function will test for this id, before executing a callback to the snapshot server.
Since the function is located inside the snapshotted code, the app won't make a request to the server if the snapshot is broken. That means you can be 100% certain that the snapshot you get back will run.
Note: 3 things can happen when launching the app.
In the last case there's a timeout of 10s before the process is terminated and the snapshot is deemed broken.
Since the code you will be snapshotting is probably propriatary (if not, why snapshot?) you probably don't want to pass your code across the web. node-nw-snapshot uses insecure sockets (based on Axon) to communicate between clients and servers, and your code will be transferred in plain text (for now). You will probably want to keep your servers on the local network (i use VirtualBox). Besides this concern there is no reason your servers couldn't be located remotely.
npm install nw-snapshot
npm start nw-snapshot
in your buildscript:
SnapshotClient = Client;var client = "0.9.2" appSource snapshotSource;// Connect to tcp://127.0.0.1:3001client;
appSource should be either a
Buffer of, or the path to, your application zip (app.nw) without the code for the snapshot.
snapshotSource is the js file that you want to compile into a snapshot.
In your app's main .html file insert this snippet at the bottom of
Start by cloning the repository:
git clone https://github.com/miklschmidt/node-nw-snapshot.gitcd node-nw-snapshotnpm install -g gulpnpm install
The tests use a minimally modified version of the frameless-window example from the official node-webkit example applications.
Want to test the ratio at which nwsnapshot will fail?
On OSX with v0.8.1, nwsnapshot will produce a broken snapshot ~40 out of 100 runs.
If you're starting the server with
node server.js or similar you can provide commandline arguments to override the http port, the socket port, and the platform architecture to compile for.
node server.js --arch ia32 --httpport 1234 --sockport 4321 node server.js --arch x64 node server.js --sockport 4321
If you're using
npm start to start the server, you can override the default socket port by doing:
npm config set nw-snapshot:sockport 1234
and the http port:
npm config set nw-snapshot:httpport 4321
and the platform architecture to compile for:
npm config set nw-snapshot:arch ia32
timeout: 10000ms # Time to wait before killing the node-webkit process and fail/try again
node-nw-snapshot comes with a downloader for downloading and extracting a specific version of node-webkit. You can use this class in your buildscript for automatically running your app in the version of you choosing. Here's an example using gulp:
var exec = exec;var NodeWebkitDownloader = Downloader;var gulp = ;var gutil = ;gulp;
Now from the command line you can do:
gulp run --nw 0.8.2
And magic will happen!