Skip to content

chore: make the script verbose with 'verbose' at the end of a command #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"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",
Expand All @@ -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/"
},
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
13 changes: 9 additions & 4 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,9 +15,14 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
# Move to the root (easier to locate other scripts)
cd ${DIR}/..

CMD=$1
LANGUAGE=$2
CLIENT=$3
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