build-example 3.83 KB
Newer Older
1
#!/usr/bin/env bash
2
# Make sure the current directory is the location of this script to simplify matters
3
cd "$(dirname "$(readlink -f "$0")")" || { echo "Error: Failed to cd to script directory" >&2; exit 1; };
4 5 6
################
### Settings ###
################
7

8 9 10 11
# The name of this project
project_name="micro-lanterns";

# The path to the lantern build engine git submodule
Starbeamrainbowlabs's avatar
Starbeamrainbowlabs committed
12
lantern_path=".";
13 14 15 16 17 18

###
# Custom Settings
###

# Put any custom settings here.
Starbeamrainbowlabs's avatar
Starbeamrainbowlabs committed
19
build_output_folder="./dist";
20 21 22

###############################################################################

23
# Check out the lantern git submodule if needed
24
if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi
Starbeamrainbowlabs's avatar
Starbeamrainbowlabs committed
25

26
#shellcheck disable=SC1090
27
source "${lantern_path}/lantern.sh";
28 29 30 31

if [[ "$#" -lt 1 ]]; then
	echo -e "${FBLE}${project_name}${RS} build script";
	echo -e "    by Starbeamrainbowlabs";
32
	# shellcheck disable=SC2154
33 34 35 36 37 38 39
	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";
Starbeamrainbowlabs's avatar
Starbeamrainbowlabs committed
40
	echo -e "    ${CACTION}testing${RS}          - Test task";
41 42 43 44 45 46 47 48 49 50 51 52
	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

###############################################################################

53
task_setup() {
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	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;
}

72
task_testing() {
Starbeamrainbowlabs's avatar
Starbeamrainbowlabs committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
	task_begin "Task A";
	
	check_command msbuild true optional;
	
	task_end $?;
	
	
	task_begin "Task B";
	
	execute uname -a;
	execute node --version;
	execute php --version;
	execute echo -e "Testing --!\"$%^&*()";
	
	task_end $?;
}

90
task_dev-server() {
91 92 93 94 95 96 97 98
	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;
}

99
task_dev-server-stop() {
100 101 102 103 104 105 106 107
	task_begin "Stopping development server";
	
	kill "$(cat /tmp/micro-lantern-dev-server.pid)";
	rm /tmp/micro-lantern-dev-server.pid;
	
	task_end $?;
}

108
task_main() {
109 110 111 112 113 114 115 116 117 118 119
	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 $?;
}

120
task_js() {
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
	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
}

138
task_sprites() {
139 140 141 142
	# Build SpritePacker if required
	if [ ! -f "./tools/SpritePacker/SpritePacker-CLI/bin/Debug/SpritePackerCLI.exe" ]; then
		task_begin "Building SpritePacker";
		
143
		cd tools/SpritePacker || { echo "Error: Failed to cd into tools/SpritePacker"; echo 1; };
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
		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;
}

###############################################################################

162
tasks_run "$@";