diff --git a/.npmrc b/.npmrc index d766053c..f5e2b726 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,2 @@ ;enforces that the user is `npm install`ing with the correct node version -;only works with `npm install` on older versions of npm - prefer `npm run setup` engine-strict=true diff --git a/README.md b/README.md index a3616876..7cc20699 100644 --- a/README.md +++ b/README.md @@ -33,20 +33,15 @@ The system comprises the following components: ## Code Prerequisites In order to build and run the code, you need the following installed: - - [Node](https://nodejs.org/) + - [Node](https://nodejs.org/); latest LTS - [Wine](https://www.winehq.org/download), if you would like to generate binaries for Windows. -To make sure you have the proper requirements to start working, run: -```sh -bash ./scripts/check_requirements/main.sh -``` +> 💡 NOTE: if you have `nvm` installed, run `nvm use` to switch to the correct node version! -> 💡 NOTE: if you have `nvm` installed, you can run `nvm use` instead! - -Finally, you can install dependencies with: +Install dependencies with: ```sh -npm ci +npm install ``` This project uses [NPM workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces/). diff --git a/package.json b/package.json index e769eee5..88e7b5d9 100644 --- a/package.json +++ b/package.json @@ -20,16 +20,16 @@ "actions": "find . -name '*_action.sh' | sed -E 's:./src/(.*)_action.sh:\\1:' | grep -v 'scripts/do_action'", "clean": "rm -rf src/*/node_modules/ build/ node_modules/ src/server_manager/install_scripts/do_install_script.ts src/server_manager/install_scripts/gcp_install_script.ts third_party/shellcheck/download/", "do": "bash ./scripts/do_action.sh", - "lint": "npm run shellcheck && npm run tslint", - "shellcheck": "bash ./scripts/check_shell.sh", - "tslint": "npx tslint 'src/**/*.ts' -e '**/node_modules/**'" + "lint": "npm run lint:sh && npm run lint:ts", + "lint:sh": "bash ./scripts/shellcheck.sh", + "lint:ts": "npx tslint 'src/**/*.ts' -e '**/node_modules/**'" }, "workspaces": [ "src/*" ], "husky": { "hooks": { - "pre-commit": "bash ./scripts/check_requirements/main.sh -j && npm run lint && npx git-clang-format && npx pretty-quick --staged --pattern '**/*.html'" + "pre-commit": "npm run lint && npx git-clang-format && npx pretty-quick --staged --pattern '**/*.html'" } } } diff --git a/scripts/check_requirements/javascript.sh b/scripts/check_requirements/javascript.sh deleted file mode 100644 index 523b2d3e..00000000 --- a/scripts/check_requirements/javascript.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -eu -# -# Copyright 2021 The Outline Authors -# -# 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. - -# This script intended to run at the repository root. - -source ./scripts/check_requirements/library.sh - -# params - locator -# the locator is the literal prefix string of the key -# in the package.json we're looking for -# for example: -# locate_package_json_key " \"node\": \"" -# => >=16.0.0 -function locate_package_json_key { - LOCATOR=$1 - - TEMP="$(grep "${LOCATOR}" package.json)" - TEMP=${TEMP#${LOCATOR}} - TEMP=${TEMP%\",} # json key could end with a comma or be the end of the list - TEMP=${TEMP%\"} # (e.g. no comma) - - echo "${TEMP}" -} - -# check node version -LOCAL_NODE_VERSION="$(node --version)" - -NODE_PACKAGE_JSON_LOCATOR=" \"node\": \"" -NODE_TARGET_VERSION_AND_COMPARATOR="$( - locate_package_json_key \ - "${NODE_PACKAGE_JSON_LOCATOR}" -)" - -check_resource_version Node \ - "${LOCAL_NODE_VERSION#v}" \ - "$(split_comparator "${NODE_TARGET_VERSION_AND_COMPARATOR}")" \ - "$(split_version "${NODE_TARGET_VERSION_AND_COMPARATOR}")" - -# check npm version -LOCAL_NPM_VERSION="$(npm --version)" - -NPM_PACKAGE_JSON_LOCATOR=" \"npm\": \"" -NPM_TARGET_VERSION_AND_COMPARATOR="$( - locate_package_json_key \ - "${NPM_PACKAGE_JSON_LOCATOR}" -)" - -check_resource_version NPM \ - "${LOCAL_NPM_VERSION}" \ - "$(split_comparator "${NPM_TARGET_VERSION_AND_COMPARATOR}")" \ - "$(split_version "${NPM_TARGET_VERSION_AND_COMPARATOR}")" diff --git a/scripts/check_requirements/library.sh b/scripts/check_requirements/library.sh deleted file mode 100644 index 96d3e082..00000000 --- a/scripts/check_requirements/library.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash -eu -# -# Copyright 2021 The Outline Authors -# -# 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. - -# This script contains functions intended to be used across `reqcheck` - -# params - left version, right version -# version numbers are period-delimited -# echoes -1 if the left version is less, 1 if it's greater, 0 if the two are exactly equal. -# for example: -# get_version_comparator 1.2.4 1.2.4 -# => 0 -# get_version_comparator 1.2.4 1.2.5 -# => -1 -# get_version_comparator 1.2.4 1.0.6 -# => 1 -function get_version_comparator { - IFS='.' read -r -a LEFT_ARRAY <<< "${1}" - IFS='.' read -r -a RIGHT_ARRAY <<< "${2}" - - for INDEX in "${!LEFT_ARRAY[@]}" - do - if [[ "${LEFT_ARRAY[INDEX]}" -lt "${RIGHT_ARRAY[INDEX]}" ]]; then - echo "-1" - return - elif [[ "${LEFT_ARRAY[INDEX]}" -gt "${RIGHT_ARRAY[INDEX]}" ]]; then - echo "1" - return - fi - done - - echo "0" -} - -# params - left version, target comparator, right version -# version numbers are period-delimited, target comparator is a string containing =, <, > -# echos 1 if the left version passes the comparison, 0 if it does not -# for example: -# does_version_pass 1.2.4 <= 1.2.4 -# => 1 -# does_version_pass 1.2.4 >= 1.2.5 -# => 0 -function does_version_pass { - LEFT_VERSION=$1 - COMPARISON=$2 - RIGHT_VERSION=$3 - - case "$(get_version_comparator "${LEFT_VERSION}" "${RIGHT_VERSION}")" in - "1") - if [[ "${COMPARISON}" == *">"* ]]; then - echo "1" - return - fi - return;; - "0") - if [[ "${COMPARISON}" == *"="* ]]; then - echo "1" - return - fi - ;; - "-1") - if [[ "${COMPARISON}" == *"<"* ]]; then - echo "1" - return - fi - ;; - esac - - echo "0" -} - -# params - resource name, resource version, target comparator, target version -# version numbers are period-delimited, target comparator is a string containing =, <, > -# non-zero exit if the check doesn't pass -function check_resource_version { - RESOURCE_NAME=$1 - RESOURCE_VERSION=$2 - TARGET_COMPARATOR=$3 - TARGET_VERSION=$4 - - COMPARISON_RESULT="$( - does_version_pass \ - "${RESOURCE_VERSION}" \ - "${TARGET_COMPARATOR}" \ - "${TARGET_VERSION}" - )" - - if [[ "${COMPARISON_RESULT}" == "0" ]]; then - cat < -# for example: -# split_version >=12.0.0 -# => 12.0.0 -function split_version { - VERSION_AND_COMPARATOR=$1 - - VERSION="${VERSION_AND_COMPARATOR/=/}" - VERSION="${VERSION//}" - - echo "${VERSION}" -} - -# params - version and comparator, together -# version numbers are period-delimited, target comparator is a string containing =, <, > -# for example: -# split_comparator >=12.0.0 -# => >= -function split_comparator { - VERSION_AND_COMPARATOR=$1 - - VERSION="$(split_version "${VERSION_AND_COMPARATOR}")" - - echo "${VERSION_AND_COMPARATOR%${VERSION}}" -} \ No newline at end of file diff --git a/scripts/check_requirements/main.sh b/scripts/check_requirements/main.sh deleted file mode 100644 index fa5f3bf6..00000000 --- a/scripts/check_requirements/main.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -eu -# -# Copyright 2021 The Outline Authors -# -# 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. - -# This script intended to run at the repository root. - -while getopts "j" OPTION; do - case "${OPTION}" in - "j") - bash ./scripts/check_requirements/javascript.sh - ;; - *) - ;; - esac -done - -echo "All requirements met!" \ No newline at end of file diff --git a/scripts/check_shell.sh b/scripts/shellcheck.sh similarity index 100% rename from scripts/check_shell.sh rename to scripts/shellcheck.sh