diff --git a/package.json b/package.json index 62d36717e5..ad7d944930 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ "tests/" ], "scripts": { - "build:clients": "./scripts/multiplexer.sh ./scripts/builds/clients.sh ${0:-all} ${1:-all}", + "build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}", "build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yaml}", "build": "yarn build:specs && yarn build:clients", "clean": "rm -rf **/dist **/build **/node_modules", - "cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix", - "cts:test": "./scripts/multiplexer.sh ./scripts/runCTS.sh ${0:-javascript} all", + "cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh ${2:-nonverbose} yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix", + "cts:test": "./scripts/multiplexer.sh ${1:-nonverbose} ./scripts/runCTS.sh ${0:-javascript} all", "docker:build": "./scripts/docker/build.sh", "docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation", "docker:mount": "./scripts/docker/mount.sh", @@ -20,8 +20,8 @@ "docker": "docker exec dev yarn $*", "lint": "eslint --ext=ts .", "post:generate": "./scripts/post-gen/global.sh", - "generate": "./scripts/multiplexer.sh ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate", - "playground": "./scripts/multiplexer.sh ./scripts/playground.sh ${0:-javascript} ${1:-search}", + "generate": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate", + "playground": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/playground.sh ${0:-javascript} ${1:-search}", "specs:format": "yarn prettier --write specs", "specs:lint": "eslint --ext=yml specs/ .github/" }, diff --git a/scripts/builds/clients.sh b/scripts/builds/clients.sh index 1d9d3c1bf7..aabb944e43 100755 --- a/scripts/builds/clients.sh +++ b/scripts/builds/clients.sh @@ -19,16 +19,19 @@ build_client(){ if [[ $lang == 'javascript' ]]; then yarn workspace $package build elif [[ $lang == 'java' ]]; then - set +e - - log=$(mvn clean install -f clients/$package/pom.xml) - - if [[ $? != 0 ]]; then - echo "$log" - exit 1 + CMD="mvn clean install -f clients/$package/pom.xml" + if [[ $VERBOSE == "true" ]]; then + $CMD + else + set +e + log=$($CMD) + + if [[ $? != 0 ]]; then + echo "$log" + exit 1 + fi + set -e fi - - set -e fi } diff --git a/scripts/generate.sh b/scripts/generate.sh index 6468568931..13267a04aa 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -22,18 +22,20 @@ run_pre_gen() { } generate_client() { - set +e - echo "> Generating code for $generator..." - - log=$(yarn openapi-generator-cli generate --generator-key "$generator") - - if [[ $? != 0 ]]; then - echo "$log" - exit 1 + CMD="yarn openapi-generator-cli generate --generator-key $generator" + if [[ $VERBOSE == "true" ]]; then + $CMD + else + set +e + log=$($CMD) + + if [[ $? != 0 ]]; then + echo "$log" + exit 1 + fi + set -e fi - - set -e } # Run the post generation script if it exists. diff --git a/scripts/multiplexer.sh b/scripts/multiplexer.sh index 2f1ef9aae4..dc4315d29b 100755 --- a/scripts/multiplexer.sh +++ b/scripts/multiplexer.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Call this script with multiplexer.sh +# Call this script with multiplexer.sh # to run the cmd for all the required lang-client combination if [[ ! $CI ]] && [[ ! $DOCKER ]]; then @@ -15,10 +15,15 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" # Move to the root (easier to locate other scripts) cd ${DIR}/.. -CMD=${@:1:$#-2} # all arguments but the last 2 +CMD=${@:2:$#-3} # all arguments but the last 2 and first one LANGUAGE=${@: -2:1} # before last argument CLIENT=${@: -1} # last argument +if [[ $1 == "verbose" ]]; then + export VERBOSE=true + echo "Verbose mode" +fi + if [[ $CMD == "./scripts/playground.sh" ]] && ([[ $LANGUAGE == "all" ]] || [[ $CLIENT == "all" ]]); then echo "You cannot use 'all' when running the playground, please specify the language and client" diff --git a/scripts/post-gen/global.sh b/scripts/post-gen/global.sh index 99e62dcde7..90f28574f4 100755 --- a/scripts/post-gen/global.sh +++ b/scripts/post-gen/global.sh @@ -11,18 +11,20 @@ if [[ ! $DOCKER ]]; then fi format_specs() { - set +e - echo "> Formatting specs..." - - log=$(yarn specs:format) - - if [[ $? != 0 ]]; then - echo "$log" - exit 1 + CMD="yarn specs:format" + if [[ $VERBOSE == "true" ]]; then + $CMD + else + set +e + log=$($CMD) + + if [[ $? != 0 ]]; then + echo "$log" + exit 1 + fi + set -e fi - - set -e } format_specs diff --git a/scripts/post-gen/java.sh b/scripts/post-gen/java.sh index 13f1afb8d5..9751f8f2b5 100755 --- a/scripts/post-gen/java.sh +++ b/scripts/post-gen/java.sh @@ -15,8 +15,6 @@ find "$CLIENT" -type f -name "*.java" | xargs sed -i -e 's~= {}~= new Object()~g echo "package com.algolia.model;public class OneOfintegerstring {}" > $CLIENT/algoliasearch-core/com/algolia/model/OneOfintegerstring.java format_client() { - set +e - echo "> Formatting $GENERATOR..." # Download the formatter if not present and run it @@ -35,14 +33,19 @@ format_client() { --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ -jar dist/$javaFormatter -r - log=$(yarn prettier --write $CLIENT/**/*.java) - - if [[ $? != 0 ]]; then - echo "$log" - exit 1 + CMD="yarn prettier --write $CLIENT/**/*.java" + if [[ $VERBOSE == "true" ]]; then + $CMD + else + set +e + log=$($CMD) + + if [[ $? != 0 ]]; then + echo "$log" + exit 1 + fi + set -e fi - - set -e } format_client diff --git a/scripts/post-gen/javascript.sh b/scripts/post-gen/javascript.sh index b3403697a1..1f27a99b6f 100755 --- a/scripts/post-gen/javascript.sh +++ b/scripts/post-gen/javascript.sh @@ -9,24 +9,25 @@ mkdir -p $CLIENT/utils cp -R clients/algoliasearch-client-javascript/utils/ $CLIENT/ lint_client() { - set +e - echo "> Linting ${GENERATOR}..." - - log=$(eslint --ext=ts ${CLIENT} --fix) - - if [[ $? != 0 ]]; then - # jsdoc/require-hyphen-before-param-description fails to lint more than - # 6 parameters, we re-run the script if failed to lint the rest - eslint --ext=ts ${CLIENT} --fix + CMD="yarn eslint --ext=ts ${CLIENT} --fix" + if [[ $VERBOSE == "true" ]]; then + $CMD + else + set +e + log=$($CMD) if [[ $? != 0 ]]; then - exit 1 + # jsdoc/require-hyphen-before-param-description fails to lint more than + # 6 parameters, we re-run the script if failed to lint the rest + $CMD + + if [[ $? != 0 ]]; then + exit 1 + fi fi + set -e fi - - set -e - } lint_client