From 62665899c65c6f6e067db8e21dc77ce84ba0c053 Mon Sep 17 00:00:00 2001 From: Runo Saduwa Date: Fri, 13 Mar 2020 19:48:17 +0100 Subject: [PATCH] Tools: Added build tools detection script (#2661) * finished writing first script version * added preinstall script * removed white space and platform if statements * remove error log * removed install function * corrected commands * changed ls to list --- build_tools_check.js | 27 +++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 28 insertions(+) create mode 100644 build_tools_check.js diff --git a/build_tools_check.js b/build_tools_check.js new file mode 100644 index 000000000..3cf21a793 --- /dev/null +++ b/build_tools_check.js @@ -0,0 +1,27 @@ +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + +const verifyBuildToolInstallation = async (tool, checkCommand, installCommand) => { + try { + const { stdout } = await exec(checkCommand); + console.log(`${tool} is Installed: ${stdout}`); + } catch (error) { + console.warn(`WARNING: This development tool is not installed: "${tool}". Please install it using your package manager. For example: ${installCommand}`); + } +}; + +switch (process.platform) { +case 'win32': + verifyBuildToolInstallation('Windows Build Tools', 'npm list -g windows-build-tools', 'npm install --global windows-build-tools'); + break; +case 'darwin': + verifyBuildToolInstallation('CocoaPods', 'pod --version', 'sudo gem install cocoapods'); + verifyBuildToolInstallation('rsync', 'rsync --version', 'sudo port install rsync'); + break; +case 'linux': + verifyBuildToolInstallation('rsync', 'rsync --version', 'sudo apt-get install rsync'); + break; +default: + console.log('WARNING: Please ensure that you read the documentation to know the necessary build tools that must be installed in your system to successfullly build this project'); +} + diff --git a/package.json b/package.json index 5afd12c87..f277abf58 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "Joplin root package for linting", "scripts": { + "preinstall": "node build_tools_check.js", "linter": "./node_modules/.bin/eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx", "linter-ci": "./node_modules/.bin/eslint --ext .js --ext .jsx --ext .ts --ext .tsx", "watch": "gulp watch",