Skip to content

Commit

Permalink
chore: make the script verbose with 'verbose' at the end of a command (
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 14, 2022
1 parent 88f1c09 commit 7a5e513
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 58 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
"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",
"docker:setup": "yarn docker:clean && yarn docker:build && yarn docker:mount",
"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/"
},
Expand Down
21 changes: 12 additions & 9 deletions scripts/builds/clients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 12 additions & 10 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions scripts/multiplexer.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Call this script with multiplexer.sh <cmd> <lang | all> <client | all>
# Call this script with multiplexer.sh <verbose | nonverbose> <cmd (can be as long as you want)> <lang | all> <client | all>
# to run the cmd for all the required lang-client combination

if [[ ! $CI ]] && [[ ! $DOCKER ]]; then
Expand All @@ -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"

Expand Down
22 changes: 12 additions & 10 deletions scripts/post-gen/global.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 12 additions & 9 deletions scripts/post-gen/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
27 changes: 14 additions & 13 deletions scripts/post-gen/javascript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7a5e513

Please sign in to comment.