| #!/bin/bash -eu |
| |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| set -e |
| |
| # Check if --force flag is provided |
| FORCE_BUILD=false |
| if [[ "$@" == *"--force"* ]]; then |
| FORCE_BUILD=true |
| fi |
| |
| # Function to check if a file is newer than another |
| is_newer_than() { |
| # Returns 0 (true) if $1 is newer than $2, 1 (false) otherwise |
| if [ ! -f "$2" ]; then |
| return 0 # If target doesn't exist, we need to build |
| fi |
| if [ ! -f "$1" ]; then |
| return 1 # If source doesn't exist, we can't build (will error later) |
| fi |
| [ "$1" -nt "$2" ] |
| } |
| |
| # Build SQL docs |
| if [ "$FORCE_BUILD" = true ]; then |
| ./script/build-sql-docs --force |
| else |
| ./script/build-sql-docs |
| fi |
| |
| # Get version from package.json |
| VERSION=$(node -e "console.log(require('./package.json').version)") |
| CONSOLE_OUTPUT="public/web-console-$VERSION.js" |
| |
| BUILD_CONSOLE=false |
| |
| if [ "$FORCE_BUILD" = true ] || [ ! -f "$CONSOLE_OUTPUT" ]; then |
| BUILD_CONSOLE=true |
| else |
| # Check if any config file is newer than output |
| CONFIG_FILES=("package.json" "package-lock.json" "webpack.config.mjs" "tsconfig.json") |
| for config_file in "${CONFIG_FILES[@]}"; do |
| if is_newer_than "$config_file" "$CONSOLE_OUTPUT"; then |
| BUILD_CONSOLE=true |
| break |
| fi |
| done |
| |
| # Check if any source file is newer than output |
| if [ "$BUILD_CONSOLE" = false ]; then |
| # Find the newest source file |
| NEWEST_SOURCE=$(find src lib -name "*.ts" -o -name "*.tsx" | xargs ls -t 2>/dev/null | head -1) |
| if [ -n "$NEWEST_SOURCE" ] && is_newer_than "$NEWEST_SOURCE" "$CONSOLE_OUTPUT"; then |
| BUILD_CONSOLE=true |
| fi |
| fi |
| fi |
| |
| if [ "$BUILD_CONSOLE" = true ]; then |
| echo "Webpacking everything..." |
| NODE_ENV=production ./node_modules/.bin/webpack -c webpack.config.mjs --mode=production |
| echo "Web console build finished." |
| else |
| echo "Web console is up to date, skipping webpack..." |
| fi |