A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
desktop: make builds work on windows
Abdullah Attaa8470c9fead8
diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 18e50e3e1..505556eae 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -42,7 +42,6 @@"build": "tsc","bundle": "esbuild electron=./src/main.ts ./src/preload.ts --external:electron --external:fsevents --minify --bundle --outdir=./build --platform=node --tsconfig=tsconfig.json --define:MAC_APP_STORE=false --define:RELEASE=true","bundle:mas": "esbuild electron=./src/main.ts ./src/preload.ts --minify --external:electron --external:fsevents --bundle --outdir=./build --platform=node --tsconfig=tsconfig.json --define:MAC_APP_STORE=true --define:RELEASE=true",- "builder": "./node_modules/.bin/electron-builder","postinstall": "patch-package"},"author": {@@ -55,6 +54,7 @@"productName": "Notesnook","copyright": "Copyright © 2023 Streetwriters (Private) Limited","artifactName": "notesnook_${os}_${arch}.${ext}",+ "npmRebuild": false,"files": ["!*.chunk.js.map","!*.chunk.js.LICENSE.txt",diff --git a/apps/desktop/scripts/build.mjs b/apps/desktop/scripts/build.mjsindex c8a1db566..4f89eaf63 100644--- a/apps/desktop/scripts/build.mjs+++ b/apps/desktop/scripts/build.mjs@@ -19,27 +19,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import path from "path";import fs from "fs/promises";-import { $, argv, os } from "zx";--$.env = process.env;--const sodiumNativePrebuildPath = path.join(- `node_modules`,- `@notesnook`,- `crypto`,- `node_modules`,- `@notesnook`,- `sodium`,- `node_modules`,- `sodium-native`,- `prebuilds`,- `${os.platform()}-x64`-);+import { existsSync } from "fs";+import { argv, os } from "zx";+import * as childProcess from "child_process";++const sodiumNativePrebuildPath = (arch) =>+ path.join(+ `node_modules`,+ `@notesnook`,+ `crypto`,+ `node_modules`,+ `@notesnook`,+ `sodium`,+ `node_modules`,+ `sodium-native`,+ `prebuilds`,+ `${os.platform()}-${arch}`+ );if (argv.rebuild) {await fs.rm("./build/", { force: true, recursive: true });- await $`cd ../web/ && npm run build:desktop`;+ await exec(+ `cd ${path.resolve(+ path.join(__dirname, "..", "web")+ )} && npm run build:desktop`+ );await fs.cp(path.join("..", "web", "build"), "build", {recursive: true,@@ -48,25 +53,62 @@ if (argv.rebuild) {}if (argv.variant === "mas") {- await $`npm run bundle:mas`;+ await exec(`npm run bundle:mas`);} else {- await $`npm run bundle`;+ await exec(`npm run bundle`);}-await $`tsc`;-await $`npm rebuild`;+await exec(`npx tsc`);-await fs.cp(- sodiumNativePrebuildPath,- path.join("build", "prebuilds", `${process.platform}-x64`),- {- recursive: true,- force: true- }-);+if (existsSync(sodiumNativePrebuildPath("x64"))) {+ console.log("copying sodium-native-x64");+ await fs.cp(+ sodiumNativePrebuildPath("x64"),+ path.join("build", "prebuilds", `${process.platform}-x64`),+ {+ recursive: true,+ force: true+ }+ );+}++if (existsSync(sodiumNativePrebuildPath("ia32"))) {+ console.log("copying sodium-native-ia32");+ await fs.cp(+ sodiumNativePrebuildPath("ia32"),+ path.join("build", "prebuilds", `${process.platform}-ia32`),+ {+ recursive: true,+ force: true+ }+ );+}++if (existsSync(sodiumNativePrebuildPath("arm64"))) {+ console.log("copying sodium-native-arm64");+ await fs.cp(+ sodiumNativePrebuildPath("arm64"),+ path.join("build", "prebuilds", `${process.platform}-arm64`),+ {+ recursive: true,+ force: true+ }+ );+}if (argv.run) {- await $`npm run builder -- --linux AppImage:x64`;+ if (process.platform === "win32") {+ await exec(`npx electron-builder --win --x64`);+ // await exec(`.\\output\\notesnook_win_x64_portable.exe`);+ } else {+ await exec(`npx electron-builder --linux AppImage:x64`);+ // await exec(`./output/notesnook_linux_x86_64.AppImage`);+ }+}- await $`./output/notesnook_linux_x86_64.AppImage`;+async function exec(cmd) {+ return childProcess.execSync(cmd, {+ env: process.env,+ stdio: "inherit"+ });}diff --git a/apps/desktop/scripts/dev.ts b/apps/desktop/scripts/dev.tsindex d5d746843..4704b07a7 100644--- a/apps/desktop/scripts/dev.ts+++ b/apps/desktop/scripts/dev.ts@@ -57,7 +57,7 @@ async function main() {}await $`npm run bundle`;- await $`tsc`;+ await $`npx tsc`;if (first) {await fs.cp(sodiumNativePrebuildPath, "build/prebuilds", {diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.tsindex 620fd6c1e..7f63b0d21 100644--- a/apps/desktop/src/preload.ts+++ b/apps/desktop/src/preload.ts@@ -26,7 +26,7 @@ import { ipcRenderer } from "electron";declare global {var os: string;var electronTRPC: RendererGlobalElectronTRPC;- var NativeNNCrypto: new () => NNCrypto;+ var NativeNNCrypto: (new () => NNCrypto) | undefined;}console.log("HELLO", process);process.once("loaded", async () => {@@ -40,5 +40,10 @@ process.once("loaded", async () => {globalThis.electronTRPC = electronTRPC;});-globalThis.NativeNNCrypto = NNCrypto;+globalThis.NativeNNCrypto =+ process.platform === "win32" &&+ process.arch !== "x64" &&+ process.arch !== "ia32"+ ? undefined+ : NNCrypto;globalThis.os = MAC_APP_STORE ? "mas" : process.platform;