From 84f1b85356c58bfe8c8f56c127fa5a0e42aa10fb Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 30 Jun 2023 20:09:36 +0200 Subject: [PATCH] Attempt to fix build.js --- .github/workflows/ci.yml | 2 +- README.md | 2 +- build.js | 56 ++++++++++++++++++++++++++++------------ docs/installation.md | 2 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcc04d6..9201c06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: path: releases/* - name: Test build script for users - run: ./build.js + run: node ./build.js bundle: name: Bundle artifacts diff --git a/README.md b/README.md index 68f6976..244d5b1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ You can obtain a pre-compiled Rolens binary for macOS or installer for Windows f ### Compiling from source -If you have Node.js installed, just download the source from GitHub, and run `./build.js`. The install script will check that dependencies are present and build Rolens for you. +If you have Node.js installed, just download the source from GitHub, and run `node ./build.js`. The install script will check that dependencies are present and build Rolens for you. If you want to build it yourself, please refer to the [advanced build process documentation](https://garraflavatra.github.io/rolens/development/advanced-build/) for detailed compilation instructions. diff --git a/build.js b/build.js index 766ca7a..39d3664 100755 --- a/build.js +++ b/build.js @@ -52,32 +52,43 @@ function isNullish(val) { // Check that Go ^1.18 is installed. -const goMinorVersion = /go1\.([0-9][0-9])/.exec( - execSync('go version').toString() -)?.pop(); +try { + const goMinorVersion = /go1\.([0-9][0-9])/.exec( + execSync('go version').toString() + )?.pop(); - -if (isNullish(goMinorVersion) || (parseInt(goMinorVersion) < 18)) { + if (isNullish(goMinorVersion) || (parseInt(goMinorVersion) < 18)) { + throw new Error(); + } +} catch { missingDependencies.push({ name: 'Go ^1.18 ^16', url: 'https://go.dev/doc/install' }); } // Check that Node.js ^16 is installed. -const nodeMajorVersion = /v([0-9]{1,2})\.[0-9]{1,3}\.[0-9]{1,3}/.exec( - execSync('node --version').toString() -)?.pop(); +try { + const nodeMajorVersion = /v([0-9]{1,2})\.[0-9]{1,3}\.[0-9]{1,3}/.exec( + execSync('node --version').toString() + )?.pop(); -if (isNullish(nodeMajorVersion) || (parseInt(nodeMajorVersion) < 16)) { + if (isNullish(nodeMajorVersion) || (parseInt(nodeMajorVersion) < 16)) { + throw new Error(); + } +} catch { missingDependencies.push({ name: 'Node.js ^16', url: 'https://go.dev/doc/install' }); } // Check that Wails is installed. -const wailsMinorVersion = /v2\.([0-9])\.[0-9]/.exec( - execSync('wails version').toString() -)?.pop(); +try { + const wailsMinorVersion = /v2\.([0-9])\.[0-9]/.exec( + execSync('wails version').toString() + )?.pop(); -if (isNullish(wailsMinorVersion) || (parseInt(wailsMinorVersion) < 3)) { + if (isNullish(wailsMinorVersion) || (parseInt(wailsMinorVersion) < 3)) { + throw new Error(); + } +} catch { missingDependencies.push({ name: 'Wails ^2.3', command: 'go install github.com/wailsapp/wails/v2/cmd/wails@latest', @@ -88,9 +99,18 @@ if (isNullish(wailsMinorVersion) || (parseInt(wailsMinorVersion) < 3)) { // Check that NSIS is installed on Windows. if (isWindows) { - const nsisInstalled = /v3\.([0-9][0-9])/.test(execSync('makensis.exe /VERSION').toString()); - if (!nsisInstalled) { - missingDependencies.push({ name: 'Nullsoft Install System ^3', url: 'https://nsis.sourceforge.io/Download' }); + try { + const nsisInstalled = /v3\.([0-9][0-9])/.test(execSync('makensis.exe /VERSION').toString()); + if (!nsisInstalled) { + throw new Error(); + } + } catch { + missingDependencies.push({ + name: 'Nullsoft Install System ^3', + command: 'choco install nsis', + url: 'https://nsis.sourceforge.io/Download', + comment: 'Note: you should add makensis.exe to your path:\n setx /M PATH "%PATH%;C:\\Program Files (x86)\\NSIS\\Bin"' + }); } } @@ -112,6 +132,10 @@ if (missingDependencies.length > 0) { console.log(' Visit the following page for more information:'); console.log(` ${dependency.url}`); } + + if (dependency.comment) { + console.log(` ${dependency.comment}`); + } } process.exit(1); diff --git a/docs/installation.md b/docs/installation.md index 996c97e..ecb4e06 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -23,7 +23,7 @@ If you use a Linux-based OS, please continue reading. Rolens is free and open-source software, which means that you can compile it from source on your own machine by cloning [the repository](https://github.com/garraflavatra/rolens). -If you have Node.js installed, just download the source from GitHub, and run `./build.js`. The install script will check that dependencies are present and build Rolens for you. If you want to build it yourself, please continue reading. +If you have Node.js installed, just download the source from GitHub, and run `node ./build.js`. The install script will check that dependencies are present and build Rolens for you. If you want to build it yourself, please continue reading. ## Advanced build