This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
go
executable file
·147 lines (120 loc) · 3.04 KB
/
go
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
nixProfile="$HOME/.nix-profile/etc/profile.d/nix.sh"
source "$nixProfile"
#####################
## dev environment ##
#####################
function setup-nix {
if [ -x "$(command -v nix)" ]; then
echo "Nix is already installed."
echo "You may update it with the following commands:"
echo " $ nix-channel --update"
echo " $ nix-env -u"
else
function gpg_fake {
echo "Faking GPG verification"
true
}
if [ -x "$(command -v gpg2)" ]; then
gpg=gpg2
else
echo "WARNING!! GPG not installed, cannot verify authenticity of nix!"
echo "Press ^C to cancel, or any other key to continue."
read -n 1 -s
gpg=gpg_fake
fi
mkdir -p nixtmp
curl -o nixtmp/install-nix https://nixos.org/nix/install \
&& curl -o nixtmp/install-nix.sig https://nixos.org/nix/install.sig \
&& $gpg --recv-keys B541D55301270E0BCF15CA5D8170B4726D7198DE \
&& $gpg --verify nixtmp/install-nix.sig \
&& sh nixtmp/install-nix
rm -rf nixtmp
fi
}
#execute a shell with debugging enabled
function debug {
if [ $# -eq 0 ]
then
nix run -f nix/default.nix
else
nix run -f nix/default.nix -c "${@}"
fi
}
#execute a shell with debugging disabled
function run {
if [ $# -eq 0 ]
then
nix run -f nix/fast.nix
else
nix run -f nix/fast.nix -c "${@}"
fi
}
function grep {
run grep "${@}"
}
function sed {
run sed "${@}"
}
########################
## project management ##
########################
function init {
setup-nix
source "$nixProfile"
run composer install -n --prefer-dist
run yarn install
}
function version {
grep version composer.json | sed "s/^[^0-9]*\([0-9.]*\).*$/v\\1/g"
}
function tagged {
git tag --merged master | grep $(version) > /dev/null
}
function tag {
tagged || git tag $(version)
git push origin $(version)
}
#####################
## quality control ##
#####################
prettierFiles='**/*.{json,md,php,yml,yaml}'
function format-verify {
run yarn --silent prettier --list-different "$prettierFiles"
}
function format {
run yarn --silent prettier --write "$prettierFiles"
}
function strict-types {
local files="$(grep -rL 'declare(strict_types[ ]*=[ ]*1)' --include '*.php' "${@}" 2>/dev/null)"
local lineCount="$(echo "$files" | sed '/^$/d' | wc -l)"
if [ "0" -eq "$lineCount" ]
then
return 0
else
echo "The following files need 'declare(strict_types=1)'"
echo "$files"
return 1
fi
}
function lint {
run ./vendor/bin/psalm --threads=4 "${@}"
}
function test-debug {
debug ./vendor/bin/phpunit "${@}"
}
function test {
local project=$(pwd)/
set -o pipefail
run ./vendor/bin/phpunit "${@}" | sed "s:$project::g"
}
function check {
test \
&& lint \
&& format \
&& strict-types tests src
}
function jekyll {
run jekyll serve -s docs -d docs/_site
}
$1 ${@:2}