Skip to content

Commit 7a5e513

Browse files
authored
chore: make the script verbose with 'verbose' at the end of a command (#86)
1 parent 88f1c09 commit 7a5e513

File tree

7 files changed

+74
-58
lines changed

7 files changed

+74
-58
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
"tests/"
88
],
99
"scripts": {
10-
"build:clients": "./scripts/multiplexer.sh ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
10+
"build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
1111
"build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yaml}",
1212
"build": "yarn build:specs && yarn build:clients",
1313
"clean": "rm -rf **/dist **/build **/node_modules",
14-
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix",
15-
"cts:test": "./scripts/multiplexer.sh ./scripts/runCTS.sh ${0:-javascript} all",
14+
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh ${2:-nonverbose} yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix",
15+
"cts:test": "./scripts/multiplexer.sh ${1:-nonverbose} ./scripts/runCTS.sh ${0:-javascript} all",
1616
"docker:build": "./scripts/docker/build.sh",
1717
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
1818
"docker:mount": "./scripts/docker/mount.sh",
1919
"docker:setup": "yarn docker:clean && yarn docker:build && yarn docker:mount",
2020
"docker": "docker exec dev yarn $*",
2121
"lint": "eslint --ext=ts .",
2222
"post:generate": "./scripts/post-gen/global.sh",
23-
"generate": "./scripts/multiplexer.sh ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate",
24-
"playground": "./scripts/multiplexer.sh ./scripts/playground.sh ${0:-javascript} ${1:-search}",
23+
"generate": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/generate.sh ${0:-all} ${1:-all} && yarn post:generate",
24+
"playground": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/playground.sh ${0:-javascript} ${1:-search}",
2525
"specs:format": "yarn prettier --write specs",
2626
"specs:lint": "eslint --ext=yml specs/ .github/"
2727
},

scripts/builds/clients.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ build_client(){
1919
if [[ $lang == 'javascript' ]]; then
2020
yarn workspace $package build
2121
elif [[ $lang == 'java' ]]; then
22-
set +e
23-
24-
log=$(mvn clean install -f clients/$package/pom.xml)
25-
26-
if [[ $? != 0 ]]; then
27-
echo "$log"
28-
exit 1
22+
CMD="mvn clean install -f clients/$package/pom.xml"
23+
if [[ $VERBOSE == "true" ]]; then
24+
$CMD
25+
else
26+
set +e
27+
log=$($CMD)
28+
29+
if [[ $? != 0 ]]; then
30+
echo "$log"
31+
exit 1
32+
fi
33+
set -e
2934
fi
30-
31-
set -e
3235
fi
3336
}
3437

scripts/generate.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@ run_pre_gen() {
2222
}
2323

2424
generate_client() {
25-
set +e
26-
2725
echo "> Generating code for $generator..."
28-
29-
log=$(yarn openapi-generator-cli generate --generator-key "$generator")
30-
31-
if [[ $? != 0 ]]; then
32-
echo "$log"
33-
exit 1
26+
CMD="yarn openapi-generator-cli generate --generator-key $generator"
27+
if [[ $VERBOSE == "true" ]]; then
28+
$CMD
29+
else
30+
set +e
31+
log=$($CMD)
32+
33+
if [[ $? != 0 ]]; then
34+
echo "$log"
35+
exit 1
36+
fi
37+
set -e
3438
fi
35-
36-
set -e
3739
}
3840

3941
# Run the post generation script if it exists.

scripts/multiplexer.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Call this script with multiplexer.sh <cmd> <lang | all> <client | all>
2+
# Call this script with multiplexer.sh <verbose | nonverbose> <cmd (can be as long as you want)> <lang | all> <client | all>
33
# to run the cmd for all the required lang-client combination
44

55
if [[ ! $CI ]] && [[ ! $DOCKER ]]; then
@@ -15,10 +15,15 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
1515
# Move to the root (easier to locate other scripts)
1616
cd ${DIR}/..
1717

18-
CMD=${@:1:$#-2} # all arguments but the last 2
18+
CMD=${@:2:$#-3} # all arguments but the last 2 and first one
1919
LANGUAGE=${@: -2:1} # before last argument
2020
CLIENT=${@: -1} # last argument
2121

22+
if [[ $1 == "verbose" ]]; then
23+
export VERBOSE=true
24+
echo "Verbose mode"
25+
fi
26+
2227
if [[ $CMD == "./scripts/playground.sh" ]] && ([[ $LANGUAGE == "all" ]] || [[ $CLIENT == "all" ]]); then
2328
echo "You cannot use 'all' when running the playground, please specify the language and client"
2429

scripts/post-gen/global.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ if [[ ! $DOCKER ]]; then
1111
fi
1212

1313
format_specs() {
14-
set +e
15-
1614
echo "> Formatting specs..."
17-
18-
log=$(yarn specs:format)
19-
20-
if [[ $? != 0 ]]; then
21-
echo "$log"
22-
exit 1
15+
CMD="yarn specs:format"
16+
if [[ $VERBOSE == "true" ]]; then
17+
$CMD
18+
else
19+
set +e
20+
log=$($CMD)
21+
22+
if [[ $? != 0 ]]; then
23+
echo "$log"
24+
exit 1
25+
fi
26+
set -e
2327
fi
24-
25-
set -e
2628
}
2729

2830
format_specs

scripts/post-gen/java.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ find "$CLIENT" -type f -name "*.java" | xargs sed -i -e 's~= {}~= new Object()~g
1515
echo "package com.algolia.model;public class OneOfintegerstring {}" > $CLIENT/algoliasearch-core/com/algolia/model/OneOfintegerstring.java
1616

1717
format_client() {
18-
set +e
19-
2018
echo "> Formatting $GENERATOR..."
2119

2220
# Download the formatter if not present and run it
@@ -35,14 +33,19 @@ format_client() {
3533
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
3634
-jar dist/$javaFormatter -r
3735

38-
log=$(yarn prettier --write $CLIENT/**/*.java)
39-
40-
if [[ $? != 0 ]]; then
41-
echo "$log"
42-
exit 1
36+
CMD="yarn prettier --write $CLIENT/**/*.java"
37+
if [[ $VERBOSE == "true" ]]; then
38+
$CMD
39+
else
40+
set +e
41+
log=$($CMD)
42+
43+
if [[ $? != 0 ]]; then
44+
echo "$log"
45+
exit 1
46+
fi
47+
set -e
4348
fi
44-
45-
set -e
4649
}
4750

4851
format_client

scripts/post-gen/javascript.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ mkdir -p $CLIENT/utils
99
cp -R clients/algoliasearch-client-javascript/utils/ $CLIENT/
1010

1111
lint_client() {
12-
set +e
13-
1412
echo "> Linting ${GENERATOR}..."
15-
16-
log=$(eslint --ext=ts ${CLIENT} --fix)
17-
18-
if [[ $? != 0 ]]; then
19-
# jsdoc/require-hyphen-before-param-description fails to lint more than
20-
# 6 parameters, we re-run the script if failed to lint the rest
21-
eslint --ext=ts ${CLIENT} --fix
13+
CMD="yarn eslint --ext=ts ${CLIENT} --fix"
14+
if [[ $VERBOSE == "true" ]]; then
15+
$CMD
16+
else
17+
set +e
18+
log=$($CMD)
2219

2320
if [[ $? != 0 ]]; then
24-
exit 1
21+
# jsdoc/require-hyphen-before-param-description fails to lint more than
22+
# 6 parameters, we re-run the script if failed to lint the rest
23+
$CMD
24+
25+
if [[ $? != 0 ]]; then
26+
exit 1
27+
fi
2528
fi
29+
set -e
2630
fi
27-
28-
set -e
29-
3031
}
3132

3233
lint_client

0 commit comments

Comments
 (0)