mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-02-17 00:49:47 +03:00
setup librejs license and cachebust service worker file
This commit is contained in:
parent
0126dc0e3a
commit
410232041b
4 changed files with 80 additions and 31 deletions
19
Makefile
19
Makefile
|
@ -1,12 +1,14 @@
|
|||
BUNDLE = static/cache/bundle
|
||||
OPENAPI = docs/openapi
|
||||
CLEAN_UP = $(BUNDLE) src/cache_buster_data.json assets
|
||||
|
||||
default: frontend ## Build app in debug mode
|
||||
cargo build
|
||||
|
||||
clean: ## Delete build artifacts
|
||||
@cargo clean
|
||||
@yarn cache clean
|
||||
@-rm ./src/cache_buster_data.json
|
||||
@-rm -rf ./static/cache/bundle
|
||||
@-rm -rf ./assets
|
||||
@-rm $(CLEAN_UP)
|
||||
|
||||
coverage: migrate ## Generate code coverage report in HTML format
|
||||
cargo tarpaulin -t 1200 --out Html
|
||||
|
@ -28,20 +30,23 @@ env: ## Setup development environtment
|
|||
cd docs/openapi && yarn install
|
||||
|
||||
frontend: env ## Build frontend
|
||||
cd docs/openapi/ && yarn build
|
||||
cd $(OPENAPI) && yarn build
|
||||
yarn install
|
||||
@-rm -rf $(BUNDLE)
|
||||
@-mkdir $(BUNDLE)
|
||||
yarn build
|
||||
@./scripts/librejs.sh
|
||||
@./scripts/cachebust.sh
|
||||
|
||||
frontend-test: ## Run frontend tests
|
||||
cd docs/openapi && yarn test
|
||||
cd $(OPENAPI)&& yarn test
|
||||
yarn test
|
||||
|
||||
lint: ## Lint codebase
|
||||
cargo fmt -v --all -- --emit files
|
||||
cargo clippy --workspace --tests --all-features
|
||||
yarn lint
|
||||
cd docs/openapi && yarn test
|
||||
cd $(OPENAPI)&& yarn test
|
||||
|
||||
migrate: ## Run database migrations
|
||||
cargo run --bin tests-migrate
|
||||
|
@ -53,8 +58,6 @@ run: frontend ## Run app in debug mode
|
|||
cargo run
|
||||
|
||||
test: frontend-test frontend ## Run all available tests
|
||||
echo 'static/' && tree static || true
|
||||
echo 'tree/' && tree assets || true
|
||||
cargo test --all-features --no-fail-fast
|
||||
|
||||
xml-test-coverage: migrate ## Generate code coverage report in XML format
|
||||
|
|
41
scripts/cachebust.sh
Executable file
41
scripts/cachebust.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
trap cleanup SIGINT SIGTERM ERR EXIT
|
||||
|
||||
readonly PROJECT_ROOT=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}")))
|
||||
source $PROJECT_ROOT/scripts/lib.sh
|
||||
|
||||
readonly DIST=$PROJECT_ROOT/static/cache/bundle/
|
||||
|
||||
|
||||
file_extension() {
|
||||
echo $1 | rev | tr
|
||||
}
|
||||
|
||||
cache_bust(){
|
||||
name=$(get_file_name $1)
|
||||
extension="${name##*.}"
|
||||
filename="${name%.*}"
|
||||
file_hash=$(sha256sum $1 | cut -d " " -f 1 | tr "[:lower:]" "[:upper:]")
|
||||
|
||||
msg "${GREEN}- Processing $name: $filename.$file_hash.$extension"
|
||||
|
||||
sed -i \
|
||||
"s/$name/assets\/bundle\/$filename.$file_hash.$extension/" \
|
||||
$(find $DIST -type f -a -name "*.js")
|
||||
}
|
||||
|
||||
setup_colors
|
||||
|
||||
msg "${BLUE}[*] Setting up files for cache busting"
|
||||
|
||||
for file in $(find $DIST -type f -a -name "*.js")
|
||||
do
|
||||
name=$(get_file_name $file)
|
||||
case $name in
|
||||
"bench.js")
|
||||
cache_bust $file
|
||||
;;
|
||||
esac
|
||||
done
|
22
scripts/lib.sh
Executable file
22
scripts/lib.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
cleanup() {
|
||||
trap - SIGINT SIGTERM ERR EXIT
|
||||
# script cleanup here
|
||||
}
|
||||
|
||||
setup_colors() {
|
||||
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
|
||||
NOCOLOR='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
|
||||
else
|
||||
NOCOLOR='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
|
||||
fi
|
||||
}
|
||||
|
||||
msg() {
|
||||
echo >&2 -e "${1-}"
|
||||
}
|
||||
|
||||
get_file_name() {
|
||||
basename -- $1
|
||||
}
|
|
@ -8,29 +8,10 @@ readonly DIST=$PROJECT_ROOT/static/cache/bundle/
|
|||
readonly SOURCE="// @source https://github.com/mCaptcha/mCaptcha"
|
||||
readonly LICENSE_END="// @license-end"
|
||||
|
||||
cleanup() {
|
||||
trap - SIGINT SIGTERM ERR EXIT
|
||||
# script cleanup here
|
||||
}
|
||||
|
||||
setup_colors() {
|
||||
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
|
||||
NOCOLOR='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
|
||||
else
|
||||
NOCOLOR='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
|
||||
fi
|
||||
}
|
||||
|
||||
msg() {
|
||||
echo >&2 -e "${1-}"
|
||||
}
|
||||
|
||||
get_file_name() {
|
||||
echo $file | rev | cut -d '/' -f 1 | rev
|
||||
}
|
||||
source $PROJECT_ROOT/scripts/lib.sh
|
||||
|
||||
print_license_msg() {
|
||||
msg "${GREEN}[*] Applying $1 on $(get_file_name $2)"
|
||||
msg "${GREEN}- Applying $1 on $(get_file_name $2)"
|
||||
}
|
||||
|
||||
apply_agpl() {
|
||||
|
@ -53,6 +34,8 @@ apply_apache() {
|
|||
|
||||
setup_colors
|
||||
|
||||
msg "${BLUE}[*] LibreJS processor running"
|
||||
|
||||
for file in $(find $DIST -type f -a -name "*.js")
|
||||
do
|
||||
contents=$(cat $file)
|
||||
|
@ -63,12 +46,12 @@ do
|
|||
"bundle.js")
|
||||
apply_agpl $file
|
||||
;;
|
||||
"verificationWidget.js")
|
||||
"verificationWidget.js" | "bench.js")
|
||||
apply_x11 $file
|
||||
apply_apache $file
|
||||
;;
|
||||
*)
|
||||
msg "${RED}[!] License not configured for $name. Applying default license"
|
||||
msg "${RED}- [!] License not configured for $name. Applying default license"
|
||||
apply_agpl $file
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Reference in a new issue