#!/usr/bin/env bash project_name=micro-lanterns; build_output_folder="dist/"; ############################################################################### source $(dirname $0)/lantern.sh if [[ "$#" -lt 1 ]]; then echo -e "${FBLE}${project_name}${RS} build script"; echo -e " by Starbeamrainbowlabs"; echo -e "${LC}Powered by the lantern build engine, v${version}${RS}"; echo -e ""; echo -e "${CSECTION}Usage${RS}"; echo -e " ./build ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ..."; echo -e ""; echo -e "${CSECTION}Available actions${RS}"; echo -e " ${CACTION}setup${RS} - Perform initial setup"; echo -e " ${CACTION}main${RS} - Perform a regular build"; echo -e " ${CACTION}sprites${RS} - Build the spritesheet"; echo -e " ${CACTION}js${RS} - Build the javascript"; echo -e " ${CACTION}dev-server${RS} - Start a development server"; echo -e " ${CACTION}dev-server-stop${RS} - Stop the currently running development server"; echo -e ""; exit 1; fi ############################################################################### function task_setup { task_begin "Setting up"; check_command git true; check_command msbuild true; check_command node true; check_command npm true; subtask_begin "Creating build output directory"; mkdir -p "${build_output_folder}"; subtask_end $?; subtask_begin "Initialising submodules"; git submodule update --init; subtask_end $?; task_end 0; } function task_dev-server { task_begin "Starting development server"; php -S [::1]:40482 -t "${build_output_folder}" & exit_code=$?; echo $! >/tmp/micro-lantern-dev-server.pid; task_end $?; # Should be 0 unless php died for some reason sleep 1; } function task_dev-server-stop { task_begin "Stopping development server"; kill "$(cat /tmp/micro-lantern-dev-server.pid)"; rm /tmp/micro-lantern-dev-server.pid; task_end $?; } function task_main { run_task js; task_begin "Copying html"; cp index.html "${build_output_folder}"; task_end $?; task_begin "Copying css"; cp theme.css "${build_output_folder}"; task_end $?; } function task_js { task_begin "Validating scripts"; scripts/validate.sh task_end $?; task_begin "Running webpack"; node_modules/webpack/bin/webpack.js --config webpack.config.js exit_code=$?; task_end ${exit_code}; if [[ "${exit_code}" -ne 0 ]]; then exit 1; fi } function task_sprites { # Build SpritePacker if required if [ ! -f "./tools/SpritePacker/SpritePacker-CLI/bin/Debug/SpritePackerCLI.exe" ]; then task_begin "Building SpritePacker"; cd tools/SpritePacker; msbuild; exit_code=$?; task_end $exit_code; if [[ "${exit_code}" -ne 0 ]]; then exit ${exit_code}; fi fi task_begin "Building Sprites"; echo -e "Not implemented yet"; task_end 0; } ############################################################################### tasks_run $@;