From 3bfc64369124f342d8afbff29f374821ab3a6ce0 Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Tue, 29 Oct 2024 05:57:06 +0100 Subject: [PATCH] Added requirements script to ensure the current system can run Makerkit. (#78) 1. Check Node.js version is greater than 18.18.0 2. Check the current path doesn't include OneDrive. OneDrive causes issue with importing modules. --- package.json | 1 + tooling/scripts/package.json | 3 +- tooling/scripts/src/dev.mjs | 3 +- tooling/scripts/src/requirements.mjs | 48 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tooling/scripts/src/requirements.mjs diff --git a/package.json b/package.json index 53c165dd1..43705ae2b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "name": "MakerKit" }, "scripts": { + "preinstall": "pnpm run --filter scripts requirements", "postinstall": "manypkg fix", "build": "turbo build --cache-dir=.turbo", "clean": "git clean -xdf node_modules dist .next", diff --git a/tooling/scripts/package.json b/tooling/scripts/package.json index 86e9f3454..f838fe6d3 100644 --- a/tooling/scripts/package.json +++ b/tooling/scripts/package.json @@ -4,6 +4,7 @@ "version": "0.1.0", "scripts": { "dev": "node ./src/dev.mjs", - "checks": "node ./src/checks.mjs" + "checks": "node ./src/checks.mjs", + "requirements": "node ./src/requirements.mjs" } } diff --git a/tooling/scripts/src/dev.mjs b/tooling/scripts/src/dev.mjs index de3783246..3879b0a3e 100644 --- a/tooling/scripts/src/dev.mjs +++ b/tooling/scripts/src/dev.mjs @@ -1,2 +1,3 @@ import './version.mjs'; -import './license.mjs'; \ No newline at end of file +import './license.mjs'; +import './requirements.mjs'; \ No newline at end of file diff --git a/tooling/scripts/src/requirements.mjs b/tooling/scripts/src/requirements.mjs new file mode 100644 index 000000000..23292568b --- /dev/null +++ b/tooling/scripts/src/requirements.mjs @@ -0,0 +1,48 @@ +// check requirements to run Makerkit +void checkRequirements(); + +function checkRequirements() { + checkNodeVersion(); + checkPathNotOneDrive(); +} + +/** + * Checks if the current Node version is compatible with Makerkit. + * If the current Node version is not compatible, it exits the script with an error message. + */ +function checkNodeVersion() { + const requiredNodeVersion = '>=v18.18.0'; + const currentNodeVersion = process.versions.node; + const [major, minor] = currentNodeVersion.split('.').map(Number); + + if (major < 18 || (major === 18 && minor < 18)) { + console.error( + `\x1b[31m%s\x1b[0m`, + `You are running Node ${currentNodeVersion}. Makerkit requires Node ${requiredNodeVersion}.`, + ); + + process.exit(1); + } else { + console.log( + `\x1b[32m%s\x1b[0m`, + `You are running Node ${currentNodeVersion}.`, + ); + } +} + +/** + * Checks if the current working directory is not OneDrive. + * If the current working directory is OneDrive, it exits the script with an error message. + */ +function checkPathNotOneDrive() { + const path = process.cwd(); + + if (path.includes('OneDrive')) { + console.error( + `\x1b[31m%s\x1b[0m`, + `You are running Makerkit from OneDrive. Please move your project to a local folder.`, + ); + + process.exit(1); + } +}