Build Scripts
Ready to Ship
In most of my projects you'll see a commit command that formats, compiles, tests, and vets the whole project. I run this command just before I commit to gain confidence that my changes are good enough. If any step fails then I must fix before I commit and push.
Testing shows the presence, not the absence of bugs.
Of course this does not guarantee an error free program or that the program will run at all. It merely increases our confidence that it will run with a low chance of error. If all is good you'll see the ASCII train I designed. Sadly, this is probably the limit of my artistic ability.
...oo000o.
00oo.
___ _________ _________ ______ __________ _________ oo.
-- | | | | | | | | | | _____ o
___ | | | Ready | | To | | Ship | | | |__D|____][_
-- |_______|%%|_______|%%|____|%%|________|%%|_______|%%|_~~~~++++~_}
@~~@~~@ @~~@~~@ @~~@ @~@~~@~@ @~~@~~@ @~~@~~~@~~@
Minimalist Node.js & Svelte Library
You'll usually want to compile your Svelte components to ensure they're good but since I always link and test my changes in a real application I've yet needed to do it. Compiling and testing will ensure your components function but won't tell you if they're styled correctly.
"scripts": {
"fmt": "prettier --plugin prettier-plugin-svelte --log-level warn --write .",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --passWithNoTests",
"commit": "npm run fmt && npm run test && cat ./scripts/ready-to-ship.txt"
}
Sveltekit
"scripts": {
"clean": "rm -rf .svelte-kit .vercel",
"fmt": "prettier --plugin prettier-plugin-svelte --log-level warn --write .",
"=======================================================1": "",
"jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --passWithNoTests",
"cypress-run": "cypress run --headless -b electron",
"cypress": "start-server-and-test \"vite preview --port 4000\" http://localhost:4000 \"npm run cypress-run\"",
"=======================================================2": "",
"build": "npm run fmt && vite build",
"dev": "npm run fmt && vite dev --port 3000",
"preview": "npm run build && vite preview --port 4000",
"test": "npm run jest && npm run cypress",
"commit": "npm run build && npm run test && cat ./scripts/ready-to-ship.txt",
"=======================================================3": "",
"auto-build": "vite build",
"auto-test": "npm run jest && npm run cypress"
}
./godo
#!/bin/bash
# Here be my ./godo scroll
# A build script for Go projects
# A bash script for local labor.
#
# Read with ease
# Adapt with haste
# Run with speed
# And reuse, nil waste
#
# Set forth to project root
# Save my script as ./godo
# Now ponder an EXE_NAME
# And name your MAIN_FILE.
#
# Once the quest is complete
# And the bounty is shared
# Open thy terminal and...
# ./godo
#
# - Paulio 2022-01-09
clear
set -e
tabs -2
EXE_NAME="my_program_name"
MAIN_FILE="cmd/main.go"
BUILD_DIR="build"
TEST_TIMEOUT="2s"
BUILD_FLAGS=""
#BUILD_FLAGS=-gcflags -m -ldflags "-s -w"
printUsage() {
println "Usage:"
println "\t" "./godo [help]" "\t" "Print usage"
println "\t" "./godo doc[s]" "\t" "Fire up documentation server"
println "\t" "./godo clean " "\t" "Clean Go caches and build folder"
println "\t" "./godo fmt " "\t" "fmt"
println "\t" "./godo test " "\t" "fmt -> build -> test -> vet"
println "\t" "./godo run " "\t" "fmt -> build -> test -> vet -> run"
}
println() {
for s in "$@"
do
printf "$s"
done
printf "\\n"
}
goDoc() {
doc_port=":6666"
println "Documentation..."
println "\t" "http://localhost${doc_port}/"
godoc -http=${doc_port}
}
clean() {
println "Cleaning..."
rm -r -f "$BUILD_DIR"
}
setup() {
println "Setup..."
mkdir -p "$BUILD_DIR"
}
goClean() {
println "Deep cleaning..."
go clean -cache -testcache
}
goBuild() {
println "Building..."
go build -o "$BUILD_DIR/$EXE_NAME" $BUILD_FLAGS $MAIN_FILE
}
goFmt() {
println "Formatting..."
go fmt ./...
}
goTest() {
println "Testing..."
go test ./... -timeout $TEST_TIMEOUT
}
goVet() {
println "Vetting..."
go vet ./...
}
goExe() {
println "Running..."
"$BUILD_DIR/$EXE_NAME" $@
}
if [[ "$1" == "" || "$1" == "help" ]]; then
printUsage
exit 0
fi
if [[ "$1" == "doc" || "$1" == "docs" ]]; then
goDoc
exit 0
fi
if [[ "$1" == "clean" ]]; then
clean
goClean
exit 0
fi
if [[ "$1" == "fmt" ]]; then
clean
goFmt
exit 0
fi
if [[ "$1" == "test" ]]; then
clean
setup
goBuild
goFmt
goTest
goVet
exit 0
fi
if [[ "$1" == "run" ]]; then
clean
setup
goBuild
goFmt
goTest
goVet
shift 1
goExe $@
println
exit 0
fi
println "I don't understand the option '$1'."
printUsage
exit 1