From f55fa10b6b8c2d081d14d0294b4e4619ab38d572 Mon Sep 17 00:00:00 2001 From: Kristian Dupont Date: Mon, 14 Aug 2017 10:30:03 +0200 Subject: [PATCH] Add environment-check script (#1199) * Add environment-check script * Check version without using semver module --- package.json | 3 +- scripts/check-environment.js | 59 ++++++++++++++++++++++++++++++++++++ scripts/test.sh | 8 +++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 scripts/check-environment.js diff --git a/package.json b/package.json index d76d89a5..76005f1a 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "win-revert-symlinks": "npm run isWin -s && npm run alias:win:apply && git checkout-symlinks && npm run alias:win:revert || echo .", "prereact-tests-android": "npm run isWin -s && npm run win-fix-symlinks || echo . ", "react-tests-android": "node scripts/react-tests-android.js || npm run postreact-tests-android", - "postreact-tests-android": "npm run win-revert-symlinks" + "postreact-tests-android": "npm run win-revert-symlinks", + "check-environment": "node scripts/check-environment.js" }, "dependencies": { "extract-zip": "^1.6.0", diff --git a/scripts/check-environment.js b/scripts/check-environment.js new file mode 100644 index 00000000..b41a4cfa --- /dev/null +++ b/scripts/check-environment.js @@ -0,0 +1,59 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const exec = require('child_process').exec; + +console.log('Checking setup...'); + +function successLog(msg) { + console.log(` \x1b[32m✓\x1b[0m ${msg}`); +} + +function validateEnvPath(envKey) { + if (process.env.hasOwnProperty(envKey)) { + const resolvedPath = path.resolve(process.env[envKey]); + if (process.env[envKey].indexOf('~') !== -1 || resolvedPath !== process.env[envKey]) { + console.error(`The ${envKey} environment variable is set to ${process.env[envKey]}.`) + console.error('Since gyp doesn\'t expand user- and relative paths, this path will not work. Please use a fully resolved path'); + process.exit(-1); + } + + successLog(`${envKey} set to ${process.env[envKey]}`); + } else { + successLog(`${envKey} not set, downloading binaries`); + } +} + +exec('npm --version', (err, stdout) => { + const verRegex = /^(\d+\.)?(\d+\.)?(\*|\d+)$/; + const npmVer = stdout.trim(); + if (!verRegex.test(npmVer)) { + console.error(`npm --version returned '${npmVer}. Is Node installed?`); + process.exit(-1); + } + + const matches = verRegex.exec(npmVer); + const majorVer = +matches[1]; + + if (majorVer >= 5) { + console.error(`Installed version of npm (${npmVer}) which uses symbolic links for local packages.`); + console.error('This is currently incompatible with our tests. Please use npm version 4 or less'); + process.exit(-1); + } + + successLog(`npm version is ${npmVer}`); + + const objectStoreDir = path.join(__dirname, '..', 'src', 'object-store'); + if (fs.existsSync(objectStoreDir)) { + successLog('Object store submodule is checked out'); + } else { + console.error('Object store folder not found. Did you remember to pull submodules?') + } + + validateEnvPath('REALM_CORE_PREFIX'); + validateEnvPath('REALM_SYNC_PREFIX'); + + // TODO: Check ANDROID_NDK and SDK for Android, and XCode for iOS. + +}); diff --git a/scripts/test.sh b/scripts/test.sh index f8925bdf..fb2bf8d2 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -243,6 +243,9 @@ fi rm -rf ~/.yarn-cache/npm-realm-* case "$TARGET" in +"check-environment") + npm run check-environment + ;; "eslint") [[ $CONFIGURATION == 'Debug' ]] && exit 0 npm run eslint @@ -268,6 +271,7 @@ case "$TARGET" in stop_server ;; "react-tests") + npm run check-environment download_server start_server pushd tests/react-test-app @@ -280,6 +284,7 @@ case "$TARGET" in stop_server ;; "react-example") + npm run check-environment pushd examples/ReactExample npm install @@ -290,6 +295,7 @@ case "$TARGET" in xctest ReactExample ;; "react-tests-android") + npm run check-environment if [ "$(uname)" = 'Darwin' ]; then download_server start_server @@ -335,6 +341,7 @@ case "$TARGET" in ;; "node") + npm run check-environment if [ "$(uname)" = 'Darwin' ]; then download_server start_server @@ -395,6 +402,7 @@ case "$TARGET" in fi ;; "test-runners") + npm run check-environment # Create a fake realm module that points to the source root so that test-runner tests can require('realm') npm install --build-from-source npm run test-runners