mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: Add .editorconfig, shfmt, shellcheck and subshell dir changes (#1649)
This commit is contained in:
+32
-28
@@ -8,39 +8,43 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
|
||||
# The logic below depends on the exact version being correct :(
|
||||
go run github.com/kyleconroy/sqlc/cmd/sqlc@v1.13.0 generate
|
||||
(
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
first=true
|
||||
for fi in queries/*.sql.go; do
|
||||
# Find the last line from the imports section and add 1.
|
||||
cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1)
|
||||
cut=$((cut + 1))
|
||||
# The logic below depends on the exact version being correct :(
|
||||
go run github.com/kyleconroy/sqlc/cmd/sqlc@v1.13.0 generate
|
||||
|
||||
# Copy the header from the first file only, ignoring the source comment.
|
||||
if $first; then
|
||||
head -n 6 < "$fi" | grep -v "source" > queries.sql.go
|
||||
first=false
|
||||
fi
|
||||
first=true
|
||||
for fi in queries/*.sql.go; do
|
||||
# Find the last line from the imports section and add 1.
|
||||
cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1)
|
||||
cut=$((cut + 1))
|
||||
|
||||
# Append the file past the imports section into queries.sql.go.
|
||||
tail -n "+$cut" < "$fi" >> queries.sql.go
|
||||
done
|
||||
# Copy the header from the first file only, ignoring the source comment.
|
||||
if $first; then
|
||||
head -n 6 <"$fi" | grep -v "source" >queries.sql.go
|
||||
first=false
|
||||
fi
|
||||
|
||||
# Move the files we want.
|
||||
mv queries/querier.go .
|
||||
mv queries/models.go .
|
||||
# Append the file past the imports section into queries.sql.go.
|
||||
tail -n "+$cut" <"$fi" >>queries.sql.go
|
||||
done
|
||||
|
||||
# Remove temporary go files.
|
||||
rm -f queries/*.go
|
||||
# Move the files we want.
|
||||
mv queries/querier.go .
|
||||
mv queries/models.go .
|
||||
|
||||
# Fix struct/interface names.
|
||||
gofmt -w -r 'Querier -> querier' -- *.go
|
||||
gofmt -w -r 'Queries -> sqlQuerier' -- *.go
|
||||
# Remove temporary go files.
|
||||
rm -f queries/*.go
|
||||
|
||||
# Ensure correct imports exist. Modules must all be downloaded so we get correct
|
||||
# suggestions.
|
||||
go mod download
|
||||
goimports -w queries.sql.go
|
||||
# Fix struct/interface names.
|
||||
gofmt -w -r 'Querier -> querier' -- *.go
|
||||
gofmt -w -r 'Queries -> sqlQuerier' -- *.go
|
||||
|
||||
# Ensure correct imports exist. Modules must all be downloaded so we get correct
|
||||
# suggestions.
|
||||
go mod download
|
||||
goimports -w queries.sql.go
|
||||
)
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
(
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# if migration name is an empty string exit
|
||||
[[ -z "${*}" ]] && (echo "Must provide a migration name" && exit 1)
|
||||
# if migration name is an empty string exit
|
||||
[[ -z "${*}" ]] && (echo "Must provide a migration name" && exit 1)
|
||||
|
||||
# " " && "-" -> "_"
|
||||
title="$(echo "${@}" | tr "[:upper:]" "[:lower:]" | sed -E -e "s/( |-)/_/g")"
|
||||
# " " && "-" -> "_"
|
||||
title="$(echo "${@}" | tr "[:upper:]" "[:lower:]" | sed -E -e "s/( |-)/_/g")"
|
||||
|
||||
migrate create -ext sql -dir . -seq "$title"
|
||||
migrate create -ext sql -dir . -seq "$title"
|
||||
|
||||
echo "Run \"make gen\" to generate models."
|
||||
echo "Run \"make gen\" to generate models."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user