Skip to content

Commit

Permalink
fix: create cacheDir and outDir before getting release info (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra authored Jan 15, 2023
1 parent b6d5612 commit 15b94c0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Fixes: #
- [ ] Format
- [ ] Lint
- [ ] Test
- [ ] Docs
- [ ] Add name to AUTHORS (first time contributors)
- [ ] Update CHANGELOG
- [ ] Version bump

### Description
12 changes: 11 additions & 1 deletion CHANGELOG-4.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]

## [4.0.8] - 2023-01-15

### Added

- Flag to check if specific `nw` release is cached. [#772](https://github.com/nwutils/nw-builder/pull/772)

### Changed

- Create `cacheDir`, `outDir` before getting release info. [#772](https://github.com/nwutils/nw-builder/pull/772)

## [4.0.7] - 2023-01-14

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

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

- Check for `nwbuild` object in `package.json`. [#684](https://github.com/nwutils/nw-builder/pull/684)
- Check for `nwbuild` object in `package.json`. [#684](https://github.com/nwutils/nw-builder/pull/684)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nw-builder",
"version": "4.0.7",
"version": "4.0.8",
"description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
"keywords": [
"NW.js",
Expand Down
2 changes: 0 additions & 2 deletions src/get/getReleaseInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const getReleaseInfo = async (version, cacheDir, manifestUrl) => {
releaseData = manifest.versions.find(
(release) => release.version === `v${version}`,
);

releaseData.version = version;
}
return releaseData;
};
41 changes: 21 additions & 20 deletions src/nwbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,54 +80,55 @@ import { log } from "./log.js";
const nwbuild = async (options) => {
let nwDir = "";
let cached;
let nwCached;
let built;
let releaseInfo = {};

notify();

try {

const { opts, files, nwPkg } = await getOptions(options);
options = opts;

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

// Validate options.version here
// We need to do this to get the version specific release info
// Create cacheDir if it does not exist
cached = await isCached(options.cacheDir);
if (cached === false) {
await mkdir(options.cacheDir, { recursive: true });
}

// Create outDir if it does not exist
built = await isCached(options.outDir);
if (built === false) {
await mkdir(options.outDir, { recursive: true });
}

// Validate options.version to get the version specific release info
releaseInfo = await getReleaseInfo(
options.version,
options.cacheDir,
options.manifestUrl,
);
options.version = releaseInfo.version;
// Remove leading "v" from version string
options.version = releaseInfo.version.slice(1);

validate(options, releaseInfo);
await validate(options, releaseInfo);

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

// Create cacheDir if it does not exist
cached = await isCached(nwDir);
if (cached === false) {
await mkdir(nwDir, { recursive: true });
}

// Create outDir if it does not exist
built = await isCached(options.outDir);
if (built === false) {
await mkdir(options.outDir, { recursive: true });
}

nwCached = await isCached(nwDir);
// Remove cached NW binary
if (options.cache === false && cached === true) {
if (options.cache === false && nwCached === true) {
log.debug("Remove cached NW binary");
await rm(nwDir, { force: true, recursive: true });
}
// Download relevant NW.js binaries
if (cached === false) {
if (nwCached === false) {
log.debug("Download relevant NW.js binaries");
await download(
options.version,
Expand Down
4 changes: 2 additions & 2 deletions src/util/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { access, constants } from "node:fs/promises";
/**
* Check if NW binaries are cached
*
* @param {string} nwDir Path to cached NW binaries
* @return {Promise<boolean>} Boolean value to denote if cache exists or not
* @param {string} nwDir Path to cached NW binaries
* @return {boolean} Boolean value to denote if cache exists or not
*/
export const isCached = async (nwDir) => {
let exists = true;
Expand Down
9 changes: 4 additions & 5 deletions src/util/notify.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createRequire } from 'node:module';
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);

import updateNotifier from "update-notifier";


/**
* Notify the user if there is a new version of the package available.
*
* @return {Promise<void>}
*/
*
* @return {Promise<void>}
*/
export const notify = async () => {
const packageJson = require("../../package.json");
updateNotifier({ pkg: packageJson }).notify();
Expand Down
6 changes: 3 additions & 3 deletions src/util/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { readdir } from "node:fs/promises";
/**
* Validate options
*
* @param {object} options Options
* @param {object} releaseInfo Version specific NW release info
* @return {undefined} True if options are valid. False otherwise
* @param {object} options Options
* @param {object} releaseInfo Version specific NW release info
* @return {Promise<undefined>} True if options are valid. False otherwise
*/
export const validate = async (options, releaseInfo) => {
if (options.srcDir === "") {
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { exec } from "child_process";

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

0 comments on commit 15b94c0

Please sign in to comment.