-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·79 lines (66 loc) · 1.55 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
TARGET=$1
if [ -z "$TARGET" ]; then
TARGET=/src
fi
cd $TARGET
# Python: autoflake, isort, black
echo "---"
echo "Formatting Python"
autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive . && \
isort . && \
black .
PYTHONRES=$?
# JSON: jq
echo "---"
echo "Formatting JSON"
find . -type f -name "*.json" | xargs --no-run-if-empty -n1 sh -c 'jq . "$0"' > /dev/null && \
find . -type f -name "*.json" | xargs --no-run-if-empty -n1 sh -c 'jq . "$0" > "$0".formatted && mv "$0".formatted "$0"'
JSONRES=$?
# Yaml: yamlfix
echo "---"
echo "Formatting YAML"
yamlfix .
YAMLRES=$?
# SQL
echo "---"
echo "Formatting SQL"
find . -type f -name "*.sql" |xargs --no-run-if-empty sed -Ei 's/[ ]/ /g' && \
find . -type f -name "*.sql" |xargs --no-run-if-empty sed -Ei 's/[ ]+$//'
SQLRES=$?
# PHP: Pint
echo "---"
echo "Formatting PHP"
/root/.composer/vendor/bin/pint --preset=psr12 .
PHPRES=$?
# JS: js-beautify
echo "---"
echo "Formatting JS"
find . -type f -name "*.js" | xargs --no-run-if-empty sh -c 'js-beautify -jkrn "$0"'
JSRES=$?
# CSS: css-beautify
echo "---"
echo "Formatting CSS"
find . -type f -name "*.css" | xargs --no-run-if-empty sh -c 'css-beautify -nr "$0"'
CSSRES=$?
if [ $PYTHONRES -ne 0 ]; then
exit $PYTHONRES
fi
if [ $JSONRES -ne 0 ]; then
exit $JSONRES
fi
if [ $YAMLRES -ne 0 ]; then
exit $YAMLRES
fi
if [ $SQLRES -ne 0 ]; then
exit $SQLRES
fi
if [ $PHPRES -ne 0 ]; then
exit $PHPRES
fi
if [ $JSRES -ne 0 ]; then
exit $JSRES
fi
if [ $CSSRES -ne 0 ]; then
exit $CSSRES
fi