Skip to content

Commit

Permalink
fix: add back nwbuild function
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Sep 20, 2022
1 parent 4e44894 commit efd020f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 36 deletions.
10 changes: 10 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [3.8.5] - 2022-09-20

### Added

- `nwbuild` function which accidently got removed.

### Changed

- Update usage docs for `nwbuild`

## [3.8.4] - 2022-09-20

### Changed
Expand Down
10 changes: 2 additions & 8 deletions bin/nwbuild.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");

const NwBuilder = require("../lib/index.cjs");
const { nwbuild } = require("../lib/index.cjs");
const { Options, detectCurrentPlatform } = require("../dist/index.cjs");

const cli = yargs(hideBin(process.argv))
Expand Down Expand Up @@ -139,14 +139,8 @@ const cli = yargs(hideBin(process.argv))
})
.parse();

const nw = new NwBuilder({
nwbuild({
...cli,
currentPlatform: detectCurrentPlatform(process),
files: cli._,
});

if (cli.mode === "build") {
nw.build();
} else {
nw.run();
}
47 changes: 32 additions & 15 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,29 @@ This should give an error:
[ ERROR ] package.json not found
```

## Write your first application:
## Write your first NW.js application

To learn how to write your NW.js application, follow the steps given [here](https://ayushmxn.github.io/nw-repro/getting-started#write-your-first-nwjs-application).
Create a folder such as `nw` with a `package.json` explicitly for your NW app. This keeps your Node application config and NW application config seperate. The manifest should at the least have a `name` and `main` property. `main` points to the entry point of your NW.js application. This can be an HTML or JavaScript file.

```json
"name":"nw-demo"
"version":"0.1.0"
"main":"./index.html"
```

Here's an example on how to use a JavaScript file as the entry point:

```json
"name":"nw-demo"
"version":"0.1.0"
"main":"./main.js"
```

```javascript
nw.Window.open("./index.html", {}, () => {});
```

More information can be found in the [API reference](http://docs.nwjs.io/en/latest/References/App/)

## Run your first application

Expand All @@ -52,11 +72,9 @@ Module usage:
const { nwbuild } = require("nw-builder");

nwbuild({
files: "./path/to/nw/app"
})
.then(() => { ... })
.catch(() => { ... })
.finally(() => { ... })
files: "./path/to/nw/app",
mode: "run",
});
```

This is the minimum arguments required to run a NW.js application. It detects your current platform, downloads the required NW binary and runs it.
Expand All @@ -75,17 +93,16 @@ Module usage:
const { nwbuild } = require("nw-builder");

nwbuild({
files: "./path/to/nw/app/dir/**/*.*"
mode: "build"
})
.then(() => { ... })
.catch(() => { ... })
.finally(() => { ... })
files: "./path/to/nw/app/dir/**/*.*",
flavor: "normal",
platforms: ["win32", "linux64"],
mode: "build",
});
```

This is the minimum arguments required to build a NW.js application. It detects your current platform, downloads the required NW binary and builds for the current platform.

You can learn more about the configuration options in the [API reference](./api).
You can learn more about the configuration options in the [API reference](http://docs.nwjs.io/en/latest/References/App/).

## Tips

Expand All @@ -111,7 +128,7 @@ However this may not make sense if you have multiple scripts with multiple optio
}
```

You can even define your options in your project's `package.json` under the `nwbuild` property. This is ideal if you only have one NW.js run or build process. Note that the `package.json` options override the CLI and module.
You can even define your options in your project's `package.json` under the `nwbuild` property. This is ideal if you only have one NW.js run or build process. Note that the `package.json` options override the CLI and module options.

`run.js`

Expand Down
17 changes: 17 additions & 0 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,4 +1035,21 @@ NwBuilder.prototype.preparePlatformFiles = function (
return true;
};

const nwbuild = (options) => {
let nw = new NwBuilder(options);

if (options.mode === "build") {
nw.build();
return 0;
} if (options.mode === "run") {
nw.run();
return 0;
} else {
console.error("[ WARN ] Invalid mode option.");
return 1;
}
};

module.exports = NwBuilder;
exports = module.exports;
exports.nwbuild = nwbuild;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nw-builder",
"version": "3.8.4",
"version": "3.8.5",
"description": "Build NW.js desktop applications for Mac, Windows and Linux.",
"keywords": [
"NW.js",
Expand All @@ -22,7 +22,7 @@
"test": "npm run test:unit && tape './test/*.cjs'",
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"demo": "cd ./test/demo && npm run start",
"demo:cli": "nwbuild ./** --mode=build --platforms=linux32, linux64 --version=0.67.1",
"demo:cli": "nwbuild ./** --mode=build --platforms=linux32,linux64 --version=0.67.1",
"build": "esbuild src/index.js --bundle --minify --platform=node --outfile=./dist/index.cjs"
},
"devDependencies": {
Expand Down
14 changes: 3 additions & 11 deletions test/demo/index.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
const NwBuilder = require("../../lib/index.cjs");
const { nwbuild } = require("../../lib/index.cjs");

const nw = new NwBuilder({
nwbuild({
files: "./**",
version: "0.67.1",
platforms: ["linux64"],
mode: "build",
});

// Replace `build` with `run` to run the application instead
nw.build()
.then((msg) => {
console.log(msg);
})
.catch((error) => {
console.log(error);
});

0 comments on commit efd020f

Please sign in to comment.