nwts-tools v0.3.6
NW.ts-Tools
A simple toolkit for running, compiling, patching and packaging NW.js apps.
Usage
# Add NW.ts-Tools as a dependency.
npm i -D nwts-toolsYou should also have nw installed as a dependency or devDependency.
patch-codecs
Replaces the FFmpeg library originally included with NW.js. Credits to nwjs-ffmpeg-prebuilt for the prebuilt binaries. Use this patch only for free and open-source projects. Licensing restrictions apply for closed-source software.
More information: FFmpeg License and Legal Considerations.
# Run from your project's root directory:
npx nwts-patch-codecspackage
This script downloads a fresh copy from nw (the same version as you specified in your package.json minus -sdk) and packages it alongside your already built application.
# Run from your project's root directory:
npx nwts-package
# Or, modified by environment variables:
PACKAGE_TYPE=zip NWJS_FFMPEG=PATCH NWJS_VERSION=0.55.0-sdk npx nwts-packageEnvironment variables used by these scripts are enumerated inside types/env.d.ts.
compile
This script runs nwjc on every Javascript file inside the directory specified in the BUILD_DIRECTORY variable, creating a .bin file for each one of them and replacing the original script's contents with the corresponding call to nw.Window.get().evalNWBin(). Read more here: Protect JavaScript Source Code.
# Run from your project's root directory:
BUILD_DIRECTORY=build npx nwts-compilerun
Used mainly for builing the application, launching it and attaching the debugger in one step.
npx nwts-runTyped Node.js built-in modules
In NW.js you can import Node.js built-in modules with the nw.require() function, whose return type is any. Here is provided a collection of typed exports from Node.js builtin modules. Some examples:
import util from "nwts-tools/node/util";
import fs from "nwts-tools/node/fs";
import child_process, { promises } from "nwts-tools/node/child_process";
import http from "nwts-tools/node/http";
import os from "nwts-tools/node/os";
import path from "nwts-tools/node/path";Dependencies
Windows
Powershell
MacOS and Linux
zip, required fornwts-packagewhenPACKAGE_TYPEis set tozip.unzip, required fornwts-patch-codecsand fornwts-packagewhenNWJS_FFMPEGis set toPATCH.
Check out these starter templates that take full advantage of NW.ts-Tools features:
NW.ts-Tools Vanilla Starter NW.ts-Tools Solid Starter NW.ts-Tools React Starter NW.ts-Tools Gatsby Starter