Skip to content

Commit efd020f

Browse files
fix: add back nwbuild function
1 parent 4e44894 commit efd020f

File tree

6 files changed

+66
-36
lines changed

6 files changed

+66
-36
lines changed

.github/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [3.8.5] - 2022-09-20
11+
12+
### Added
13+
14+
- `nwbuild` function which accidently got removed.
15+
16+
### Changed
17+
18+
- Update usage docs for `nwbuild`
19+
1020
## [3.8.4] - 2022-09-20
1121

1222
### Changed

bin/nwbuild.cjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const yargs = require("yargs/yargs");
44
const { hideBin } = require("yargs/helpers");
55

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

99
const cli = yargs(hideBin(process.argv))
@@ -139,14 +139,8 @@ const cli = yargs(hideBin(process.argv))
139139
})
140140
.parse();
141141

142-
const nw = new NwBuilder({
142+
nwbuild({
143143
...cli,
144144
currentPlatform: detectCurrentPlatform(process),
145145
files: cli._,
146146
});
147-
148-
if (cli.mode === "build") {
149-
nw.build();
150-
} else {
151-
nw.run();
152-
}

docs/getting-started.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,29 @@ This should give an error:
3434
[ ERROR ] package.json not found
3535
```
3636

37-
## Write your first application:
37+
## Write your first NW.js application
3838

39-
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).
39+
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.
40+
41+
```json
42+
"name":"nw-demo"
43+
"version":"0.1.0"
44+
"main":"./index.html"
45+
```
46+
47+
Here's an example on how to use a JavaScript file as the entry point:
48+
49+
```json
50+
"name":"nw-demo"
51+
"version":"0.1.0"
52+
"main":"./main.js"
53+
```
54+
55+
```javascript
56+
nw.Window.open("./index.html", {}, () => {});
57+
```
58+
59+
More information can be found in the [API reference](http://docs.nwjs.io/en/latest/References/App/)
4060

4161
## Run your first application
4262

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

5474
nwbuild({
55-
files: "./path/to/nw/app"
56-
})
57-
.then(() => { ... })
58-
.catch(() => { ... })
59-
.finally(() => { ... })
75+
files: "./path/to/nw/app",
76+
mode: "run",
77+
});
6078
```
6179

6280
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.
@@ -75,17 +93,16 @@ Module usage:
7593
const { nwbuild } = require("nw-builder");
7694

7795
nwbuild({
78-
files: "./path/to/nw/app/dir/**/*.*"
79-
mode: "build"
80-
})
81-
.then(() => { ... })
82-
.catch(() => { ... })
83-
.finally(() => { ... })
96+
files: "./path/to/nw/app/dir/**/*.*",
97+
flavor: "normal",
98+
platforms: ["win32", "linux64"],
99+
mode: "build",
100+
});
84101
```
85102

86103
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.
87104

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

90107
## Tips
91108

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

114-
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.
131+
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.
115132

116133
`run.js`
117134

lib/index.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,21 @@ NwBuilder.prototype.preparePlatformFiles = function (
10351035
return true;
10361036
};
10371037

1038+
const nwbuild = (options) => {
1039+
let nw = new NwBuilder(options);
1040+
1041+
if (options.mode === "build") {
1042+
nw.build();
1043+
return 0;
1044+
} if (options.mode === "run") {
1045+
nw.run();
1046+
return 0;
1047+
} else {
1048+
console.error("[ WARN ] Invalid mode option.");
1049+
return 1;
1050+
}
1051+
};
1052+
10381053
module.exports = NwBuilder;
1054+
exports = module.exports;
1055+
exports.nwbuild = nwbuild;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nw-builder",
3-
"version": "3.8.4",
3+
"version": "3.8.5",
44
"description": "Build NW.js desktop applications for Mac, Windows and Linux.",
55
"keywords": [
66
"NW.js",
@@ -22,7 +22,7 @@
2222
"test": "npm run test:unit && tape './test/*.cjs'",
2323
"test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
2424
"demo": "cd ./test/demo && npm run start",
25-
"demo:cli": "nwbuild ./** --mode=build --platforms=linux32, linux64 --version=0.67.1",
25+
"demo:cli": "nwbuild ./** --mode=build --platforms=linux32,linux64 --version=0.67.1",
2626
"build": "esbuild src/index.js --bundle --minify --platform=node --outfile=./dist/index.cjs"
2727
},
2828
"devDependencies": {

test/demo/index.cjs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
const NwBuilder = require("../../lib/index.cjs");
1+
const { nwbuild } = require("../../lib/index.cjs");
22

3-
const nw = new NwBuilder({
3+
nwbuild({
44
files: "./**",
55
version: "0.67.1",
66
platforms: ["linux64"],
7+
mode: "build",
78
});
8-
9-
// Replace `build` with `run` to run the application instead
10-
nw.build()
11-
.then((msg) => {
12-
console.log(msg);
13-
})
14-
.catch((error) => {
15-
console.log(error);
16-
});

0 commit comments

Comments
 (0)