Skip to content

Commit

Permalink
get specific release info (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra authored Nov 16, 2022
1 parent d30754d commit 16eb002
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 55 deletions.
33 changes: 18 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nw-builder",
"version": "4.0.0-rc.8",
"version": "4.0.0",
"description": "Build NW.js desktop applications for Mac, Windows and Linux.",
"keywords": [
"NW.js",
Expand All @@ -25,9 +25,7 @@
"format": "prettier --write \"**/*.{js,md}\"",
"lint": "eslint ./src",
"docs": "jsdoc ./src/nwbuild.js -d docs",
"demo:run": "cd ./test/demo && node run.js",
"demo:bld": "cd ./test/demo && node bld.js",
"demo:cli": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build"
"demo": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build"
},
"devDependencies": {
"eslint": "^8.25.0",
Expand Down
13 changes: 6 additions & 7 deletions src/bld/osxCfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "node:fs/promises";

import plist from "plist";

const setOsxConfig = async (pkg, outDir) => {
const setOsxConfig = async (pkg, outDir, releaseInfo) => {
// Rename CFBundleDisplayName in Contents/Info.plist
let contents_info_plist_path = `${outDir}/nwjs.app/Contents/Info.plist`;
let contents_info_plist_json = plist.parse(
Expand All @@ -15,17 +15,16 @@ const setOsxConfig = async (pkg, outDir) => {
// Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings

// Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
let chromium_version = "107.0.5304.88";
let helper_app_path_alerts = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Alerts).app`;
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Alerts).app`;
let helper_app_path_gpu = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (GPU).app`;
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (GPU).app`;
let helper_app_path_plugin = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Plugin).app`;
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Plugin).app`;
let helper_app_path_renderer = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper (Renderer).app`;
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Renderer).app`;
let helper_app_path = (name = "nwjs") =>
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${chromium_version}/Helpers/${name} Helper.app`;
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper.app`;
await fs.rename(helper_app_path_alerts(), helper_app_path_alerts(pkg.name));
await fs.rename(helper_app_path_gpu(), helper_app_path_gpu(pkg.name));
await fs.rename(helper_app_path_plugin(), helper_app_path_plugin(pkg.name));
Expand Down
4 changes: 2 additions & 2 deletions src/bld/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setLinuxConfig } from "./linuxCfg.js";
import { setOsxConfig } from "./osxCfg.js";
import { setWinConfig } from "./winCfg.js";

const packager = async (srcDir, nwDir, outDir, platform, zip) => {
const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
fs.rmSync(outDir, { force: true, recursive: true });
fs.cpSync(nwDir, outDir, { recursive: true });
fs.cpSync(
Expand Down Expand Up @@ -33,7 +33,7 @@ const packager = async (srcDir, nwDir, outDir, platform, zip) => {
setWinConfig(pkg, outDir);
break;
case "osx":
setOsxConfig(pkg, outDir);
setOsxConfig(pkg, outDir, releaseInfo);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers";

import nwbuild from "./nwbuild.js";
import { nwbuild } from "./nwbuild.js";

const cli = yargs(hideBin(process.argv))
.version(false)
Expand Down
21 changes: 21 additions & 0 deletions src/get/getManifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import https from "node:https";

export const getManifest = (manifestUrl) => {
let chunks = undefined;

return new Promise((resolve, reject) => {
https.get(manifestUrl, (res) => {
res.on("data", (chunk) => {
chunks += chunk;
});

res.on("error", (e) => {
reject(e);
});

res.on("end", () => {
resolve(chunks);
});
});
});
};
21 changes: 21 additions & 0 deletions src/get/getReleaseInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from "node:fs/promises";

import { getManifest } from "./getManifest.js";

export const getReleaseInfo = async (version, cacheDir, manifestUrl) => {
let releaseData = undefined;
try {
await fs.access(`${cacheDir}/manifest.json`);
console.log(`[ INFO ] Manifest file already exists locally under ${cacheDir}`)
} catch(e) {
console.log(`[ ERROR ] Manifest file does not exist locally`);
console.log(`[ INFO ] Downloading latest manifest file under ${cacheDir}`);
const data = await getManifest(manifestUrl);
await fs.writeFile(`${cacheDir}/manifest.json`, data.slice(9));
} finally {
let manifestData = await fs.readFile(`${cacheDir}/manifest.json`);
let manifestJson = JSON.parse(manifestData);
releaseData = manifestJson.versions.find(release => release.version === `v${version}`);
}
return releaseData;
};
7 changes: 5 additions & 2 deletions src/nwbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import { decompress } from "./get/decompress.js";
import { develop } from "./run/develop.js";
import { download } from "./get/download.js";
import { getReleaseInfo } from "./get/getReleaseInfo.js";
import { remove } from "./get/remove.js";
import { packager } from "./bld/package.js";

Expand Down Expand Up @@ -32,7 +33,7 @@ const nwbuild = async ({
outDir,
// flags
downloadUrl = "https://dl.nwjs.io",
// manifestUrl = "https://nwjs.io/versions",
manifestUrl = "https://nwjs.io/versions",
noCache = false,
zip = false,
run = false,
Expand Down Expand Up @@ -60,6 +61,8 @@ const nwbuild = async ({
outDir = pkgData.nwbuild.outDir ?? outDir;
}
}

let releaseInfo = await getReleaseInfo(version, cacheDir, manifestUrl);
let nwDir = `${cacheDir}/nwjs${
flavour === "sdk" ? "-sdk" : ""
}-v${version}-${platform}-${arch}`;
Expand All @@ -82,7 +85,7 @@ const nwbuild = async ({
if (run === true) {
await develop(srcDir, nwDir, platform);
} else {
await packager(srcDir, nwDir, outDir, platform, zip);
await packager(srcDir, nwDir, outDir, platform, zip, releaseInfo);
}
};

Expand Down
11 changes: 0 additions & 11 deletions test/demo/bld.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/demo/nwapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"platform": "osx",
"arch": "x64",
"outDir": "./build",
"run": true
"run": false
}
}
12 changes: 0 additions & 12 deletions test/demo/run.js

This file was deleted.

0 comments on commit 16eb002

Please sign in to comment.