From a01c9aa6b1dbe87dec624b9e07ebab456bdd8fb4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 25 Nov 2016 12:57:09 -0400 Subject: [PATCH] refactor: improve and unify dependencies.sh script across UNIX targets (#894) - Unify both `linux/dependencies.sh` and `darwin/dependencies.sh` in `unix/dependencies.sh` - Add `-f` (force) option to `unix/dependencies.sh` - Add `-p` (production) option to `unix/dependencies.sh` - Allow passing a target type to `unix/dependencies.sh` Signed-off-by: Juan Cruz Viotti --- scripts/build/darwin.sh | 5 +- scripts/build/linux.sh | 5 +- scripts/darwin/dependencies.sh | 82 ------------------------- scripts/linux/dependencies.sh | 82 ------------------------- scripts/unix/dependencies.sh | 108 +++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 167 deletions(-) delete mode 100755 scripts/darwin/dependencies.sh delete mode 100755 scripts/linux/dependencies.sh create mode 100755 scripts/unix/dependencies.sh diff --git a/scripts/build/darwin.sh b/scripts/build/darwin.sh index f660e8ff..5385996c 100755 --- a/scripts/build/darwin.sh +++ b/scripts/build/darwin.sh @@ -45,7 +45,10 @@ APPLICATION_COPYRIGHT=`node -e "console.log(require('./package.json').copyright) APPLICATION_VERSION=`node -e "console.log(require('./package.json').version)"` if [ "$COMMAND" == "install" ] || [ "$COMMAND" == "all" ]; then - ./scripts/darwin/dependencies.sh -r x64 -e $ELECTRON_VERSION + ./scripts/unix/dependencies.sh \ + -r x64 \ + -v "$ELECTRON_VERSION" \ + -t electron fi if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then diff --git a/scripts/build/linux.sh b/scripts/build/linux.sh index 892b379f..69dacb21 100755 --- a/scripts/build/linux.sh +++ b/scripts/build/linux.sh @@ -57,9 +57,10 @@ APPLICATION_DESCRIPTION=`node -e "console.log(require('./package.json').descript APPLICATION_VERSION=`node -e "console.log(require('./package.json').version)"` if [ "$COMMAND" == "install" ] || [ "$COMMAND" == "all" ]; then - ./scripts/linux/dependencies.sh \ + ./scripts/unix/dependencies.sh \ -r "$ARCH" \ - -e "$ELECTRON_VERSION" + -v "$ELECTRON_VERSION" \ + -t electron fi if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then diff --git a/scripts/darwin/dependencies.sh b/scripts/darwin/dependencies.sh deleted file mode 100755 index 7af56869..00000000 --- a/scripts/darwin/dependencies.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -### -# Copyright 2016 resin.io -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -### - -set -u -set -e - -OS=$(uname) -if [[ "$OS" != "Darwin" ]]; then - echo "This script is only meant to be run in OS X" 1>&2 - exit 1 -fi - -if ! command -v npm 2>/dev/null 1>&2; then - echo "Dependency missing: npm" 1>&2 - exit 1 -fi - -if ! command -v bower 2>/dev/null 1>&2; then - echo "Dependency missing: bower" 1>&2 - exit 1 -fi - -if ! command -v python 2>/dev/null 1>&2; then - echo "Dependency missing: python" 1>&2 - exit 1 -fi - -function usage() { - echo "Usage: $0" - echo "" - echo "Options" - echo "" - echo " -r " - echo " -e " - exit 0 -} - -ARGV_ARCHITECTURE="" -ARGV_ELECTRON_VERSION="" - -while getopts ":r:e:" option; do - case $option in - r) ARGV_ARCHITECTURE=$OPTARG ;; - e) ARGV_ELECTRON_VERSION=$OPTARG ;; - *) usage ;; - esac -done - -if [ -z "$ARGV_ARCHITECTURE" ] || [ -z "$ARGV_ELECTRON_VERSION" ]; then - usage -fi - -# Ensure native addons are compiled with the correct headers -# See https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md -export npm_config_disturl=https://atom.io/download/atom-shell -export npm_config_runtime=electron -export npm_config_target=$ARGV_ELECTRON_VERSION - -if [ "$ARGV_ARCHITECTURE" == "x86" ]; then - export npm_config_arch=ia32 -else - export npm_config_arch=$ARGV_ARCHITECTURE -fi - -rm -rf node_modules bower_components -npm install --build-from-source -bower install --production diff --git a/scripts/linux/dependencies.sh b/scripts/linux/dependencies.sh deleted file mode 100755 index 76964223..00000000 --- a/scripts/linux/dependencies.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -### -# Copyright 2016 resin.io -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -### - -set -u -set -e - -OS=$(uname) -if [[ "$OS" != "Linux" ]]; then - echo "This script is only meant to be run in GNU/Linux" 1>&2 - exit 1 -fi - -if ! command -v npm 2>/dev/null 1>&2; then - echo "Dependency missing: npm" 1>&2 - exit 1 -fi - -if ! command -v bower 2>/dev/null 1>&2; then - echo "Dependency missing: bower" 1>&2 - exit 1 -fi - -if ! command -v python 2>/dev/null 1>&2; then - echo "Dependency missing: python" 1>&2 - exit 1 -fi - -function usage() { - echo "Usage: $0" - echo "" - echo "Options" - echo "" - echo " -r " - echo " -e " - exit 0 -} - -ARGV_ARCHITECTURE="" -ARGV_ELECTRON_VERSION="" - -while getopts ":r:e:" option; do - case $option in - r) ARGV_ARCHITECTURE=$OPTARG ;; - e) ARGV_ELECTRON_VERSION=$OPTARG ;; - *) usage ;; - esac -done - -if [ -z "$ARGV_ARCHITECTURE" ] || [ -z "$ARGV_ELECTRON_VERSION" ]; then - usage -fi - -# Ensure native addons are compiled with the correct headers -# See https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md -export npm_config_disturl=https://atom.io/download/atom-shell -export npm_config_target=$ARGV_ELECTRON_VERSION -export npm_config_runtime=electron - -if [ "$ARGV_ARCHITECTURE" == "x86" ]; then - export npm_config_arch=ia32 -else - export npm_config_arch=$ARGV_ARCHITECTURE -fi - -rm -rf node_modules bower_components -npm install --build-from-source -bower install --production --allow-root diff --git a/scripts/unix/dependencies.sh b/scripts/unix/dependencies.sh new file mode 100755 index 00000000..e3d2cbda --- /dev/null +++ b/scripts/unix/dependencies.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +### +# Copyright 2016 resin.io +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +### + +set -u +set -e + +if ! command -v npm 2>/dev/null 1>&2; then + echo "Dependency missing: npm" 1>&2 + exit 1 +fi + +if ! command -v bower 2>/dev/null 1>&2; then + echo "Dependency missing: bower" 1>&2 + exit 1 +fi + +if ! command -v python 2>/dev/null 1>&2; then + echo "Dependency missing: python" 1>&2 + exit 1 +fi + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -r " + echo " -v " + echo " -t " + echo " -f force install" + echo " -p production install" + exit 0 +} + +ARGV_ARCHITECTURE="" +ARGV_TARGET_VERSION="" +ARGV_TARGET_PLATFORM="" +ARGV_FORCE=false +ARGV_PRODUCTION=false + +while getopts ":r:v:t:fp" option; do + case $option in + r) ARGV_ARCHITECTURE=$OPTARG ;; + v) ARGV_TARGET_VERSION=$OPTARG ;; + t) ARGV_TARGET_PLATFORM=$OPTARG ;; + f) ARGV_FORCE=true ;; + p) ARGV_PRODUCTION=true ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_ARCHITECTURE" ] \ + || [ -z "$ARGV_TARGET_VERSION" ] \ + || [ -z "$ARGV_TARGET_PLATFORM" ] +then + usage +fi + +if [ "$ARGV_TARGET_PLATFORM" == "electron" ]; then + + # Ensure native addons are compiled with the correct headers + # See https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md + export npm_config_disturl=https://atom.io/download/atom-shell + export npm_config_runtime=electron + +fi + +export npm_config_target=$ARGV_TARGET_VERSION + +if [ "$ARGV_ARCHITECTURE" == "x86" ]; then + export npm_config_arch=ia32 +else + export npm_config_arch=$ARGV_ARCHITECTURE +fi + +rm -rf node_modules + +NPM_INSTALL_OPTS="--build-from-source" + +if [ "$ARGV_FORCE" == "true" ]; then + NPM_INSTALL_OPTS="$NPM_INSTALL_OPTS --force" +fi + +if [ "$ARGV_PRODUCTION" == "true" ]; then + NPM_INSTALL_OPTS="$NPM_INSTALL_OPTS --production" +fi + +npm install $NPM_INSTALL_OPTS + +if [ "$ARGV_TARGET_PLATFORM" == "electron" ]; then + rm -rf bower_components + bower install --production --allow-root +fi