Skip to content

Commit 15b94c0

Browse files
fix: create cacheDir and outDir before getting release info (#772)
1 parent b6d5612 commit 15b94c0

File tree

9 files changed

+47
-35
lines changed

9 files changed

+47
-35
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Fixes: #
33
- [ ] Format
44
- [ ] Lint
55
- [ ] Test
6+
- [ ] Docs
67
- [ ] Add name to AUTHORS (first time contributors)
78
- [ ] Update CHANGELOG
9+
- [ ] Version bump
810

911
### Description

CHANGELOG-4.md

Lines changed: 11 additions & 1 deletion
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+
## [4.0.8] - 2023-01-15
11+
12+
### Added
13+
14+
- Flag to check if specific `nw` release is cached. [#772](https://github.com/nwutils/nw-builder/pull/772)
15+
16+
### Changed
17+
18+
- Create `cacheDir`, `outDir` before getting release info. [#772](https://github.com/nwutils/nw-builder/pull/772)
19+
1020
## [4.0.7] - 2023-01-14
1121

1222
### Changed
@@ -87,4 +97,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8797

8898
- MacOS support. [#685](https://github.com/nwutils/nw-builder/pull/685)
8999

90-
- Check for `nwbuild` object in `package.json`. [#684](https://github.com/nwutils/nw-builder/pull/684)
100+
- Check for `nwbuild` object in `package.json`. [#684](https://github.com/nwutils/nw-builder/pull/684)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nw-builder",
3-
"version": "4.0.7",
3+
"version": "4.0.8",
44
"description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
55
"keywords": [
66
"NW.js",

src/get/getReleaseInfo.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const getReleaseInfo = async (version, cacheDir, manifestUrl) => {
3434
releaseData = manifest.versions.find(
3535
(release) => release.version === `v${version}`,
3636
);
37-
38-
releaseData.version = version;
3937
}
4038
return releaseData;
4139
};

src/nwbuild.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,54 +80,55 @@ import { log } from "./log.js";
8080
const nwbuild = async (options) => {
8181
let nwDir = "";
8282
let cached;
83+
let nwCached;
8384
let built;
8485
let releaseInfo = {};
8586

8687
notify();
8788

8889
try {
89-
9090
const { opts, files, nwPkg } = await getOptions(options);
9191
options = opts;
9292

93-
// Parse options, set required values to undefined and flags with default values unless specified by user
93+
// Parse options
9494
options = await parse(options, nwPkg);
9595

96-
// Validate options.version here
97-
// We need to do this to get the version specific release info
96+
// Create cacheDir if it does not exist
97+
cached = await isCached(options.cacheDir);
98+
if (cached === false) {
99+
await mkdir(options.cacheDir, { recursive: true });
100+
}
101+
102+
// Create outDir if it does not exist
103+
built = await isCached(options.outDir);
104+
if (built === false) {
105+
await mkdir(options.outDir, { recursive: true });
106+
}
107+
108+
// Validate options.version to get the version specific release info
98109
releaseInfo = await getReleaseInfo(
99110
options.version,
100111
options.cacheDir,
101112
options.manifestUrl,
102113
);
103-
options.version = releaseInfo.version;
114+
// Remove leading "v" from version string
115+
options.version = releaseInfo.version.slice(1);
104116

105-
validate(options, releaseInfo);
117+
await validate(options, releaseInfo);
106118

107119
// Variable to store nwDir file path
108120
nwDir = `${options.cacheDir}/nwjs${
109121
options.flavor === "sdk" ? "-sdk" : ""
110122
}-v${options.version}-${options.platform}-${options.arch}`;
111123

112-
// Create cacheDir if it does not exist
113-
cached = await isCached(nwDir);
114-
if (cached === false) {
115-
await mkdir(nwDir, { recursive: true });
116-
}
117-
118-
// Create outDir if it does not exist
119-
built = await isCached(options.outDir);
120-
if (built === false) {
121-
await mkdir(options.outDir, { recursive: true });
122-
}
123-
124+
nwCached = await isCached(nwDir);
124125
// Remove cached NW binary
125-
if (options.cache === false && cached === true) {
126+
if (options.cache === false && nwCached === true) {
126127
log.debug("Remove cached NW binary");
127128
await rm(nwDir, { force: true, recursive: true });
128129
}
129130
// Download relevant NW.js binaries
130-
if (cached === false) {
131+
if (nwCached === false) {
131132
log.debug("Download relevant NW.js binaries");
132133
await download(
133134
options.version,

src/util/cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { access, constants } from "node:fs/promises";
33
/**
44
* Check if NW binaries are cached
55
*
6-
* @param {string} nwDir Path to cached NW binaries
7-
* @return {Promise<boolean>} Boolean value to denote if cache exists or not
6+
* @param {string} nwDir Path to cached NW binaries
7+
* @return {boolean} Boolean value to denote if cache exists or not
88
*/
99
export const isCached = async (nwDir) => {
1010
let exists = true;

src/util/notify.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { createRequire } from 'node:module';
1+
import { createRequire } from "node:module";
22
const require = createRequire(import.meta.url);
33

44
import updateNotifier from "update-notifier";
55

6-
76
/**
87
* Notify the user if there is a new version of the package available.
9-
*
10-
* @return {Promise<void>}
11-
*/
8+
*
9+
* @return {Promise<void>}
10+
*/
1211
export const notify = async () => {
1312
const packageJson = require("../../package.json");
1413
updateNotifier({ pkg: packageJson }).notify();

src/util/validate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { readdir } from "node:fs/promises";
33
/**
44
* Validate options
55
*
6-
* @param {object} options Options
7-
* @param {object} releaseInfo Version specific NW release info
8-
* @return {undefined} True if options are valid. False otherwise
6+
* @param {object} options Options
7+
* @param {object} releaseInfo Version specific NW release info
8+
* @return {Promise<undefined>} True if options are valid. False otherwise
99
*/
1010
export const validate = async (options, releaseInfo) => {
1111
if (options.srcDir === "") {

test/e2e/cli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { exec } from "child_process";
22

3-
exec("nwbuild ./nwapp/**/* ./node_modules/**/* --mode=build --version=latest --flavour=normal --platform=win --arch=x64 --outDir=./build");
3+
exec(
4+
"nwbuild ./nwapp/**/* ./node_modules/**/* --mode=build --version=latest --flavour=normal --platform=win --arch=x64 --outDir=./build",
5+
);

0 commit comments

Comments
 (0)