|  | @@ -0,0 +1,69 @@
 | 
	
		
			
				|  |  | +#!/bin/bash -e
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg() {
 | 
	
		
			
				|  |  | +    printf "\x1b[92m[..] $@\x1b[39m\n"
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +error() {
 | 
	
		
			
				|  |  | +    printf "\x1b[91m[..] $@\x1b[39m\n"
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "creating webassembly deploy artifact"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# install wasm-bindgen if we don't have it
 | 
	
		
			
				|  |  | +which wasm-bindgen >/dev/null 2>&1 || ( error 'wasm-bindgen not found: run cargo install `wasm-bindgen-cli`' ; exit 1 )
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +if [ -e ./stories.tar.gz ]; then
 | 
	
		
			
				|  |  | +    dbg "deleting ./stories.tar.gz"
 | 
	
		
			
				|  |  | +    rm ./stories.tar.gz
 | 
	
		
			
				|  |  | +fi
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "creating release build for wasm32"
 | 
	
		
			
				|  |  | +cargo build --release --target wasm32-unknown-unknown
 | 
	
		
			
				|  |  | +dbg "running wasm-bindgen"
 | 
	
		
			
				|  |  | +wasm-bindgen --no-typescript --target web \
 | 
	
		
			
				|  |  | +             --out-dir ./out/ \
 | 
	
		
			
				|  |  | +             --out-name "stories" \
 | 
	
		
			
				|  |  | +             ./target/wasm32-unknown-unknown/release/stories.wasm
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "assembling final artifact"
 | 
	
		
			
				|  |  | +TMP=$(mktemp -d)
 | 
	
		
			
				|  |  | +trap "rm -rf $TMP" EXIT
 | 
	
		
			
				|  |  | +DIR=$TMP/stories
 | 
	
		
			
				|  |  | +mkdir -p $DIR
 | 
	
		
			
				|  |  | +cp ./out/stories.js $DIR
 | 
	
		
			
				|  |  | +cp ./out/stories_bg.wasm $DIR
 | 
	
		
			
				|  |  | +cat >$DIR/index.html <<EOF
 | 
	
		
			
				|  |  | +<!doctype html>
 | 
	
		
			
				|  |  | +<html lang="en">
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  <body style="margin: 0px;">
 | 
	
		
			
				|  |  | +    <script type="module">
 | 
	
		
			
				|  |  | +     import init from './stories.js'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +     init().catch((error) => {
 | 
	
		
			
				|  |  | +       if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
 | 
	
		
			
				|  |  | +         throw error;
 | 
	
		
			
				|  |  | +       }
 | 
	
		
			
				|  |  | +     });
 | 
	
		
			
				|  |  | +    </script>
 | 
	
		
			
				|  |  | +  </body>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +</html>
 | 
	
		
			
				|  |  | +EOF
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "copying assets"
 | 
	
		
			
				|  |  | +mkdir -p $DIR/assets
 | 
	
		
			
				|  |  | +cp -r ./assets/* $DIR/assets/.
 | 
	
		
			
				|  |  | +dbg "removing asset sources"
 | 
	
		
			
				|  |  | +rm -f $DIR/assets/*.blend
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "creating tarball"
 | 
	
		
			
				|  |  | +(
 | 
	
		
			
				|  |  | +    cd $TMP
 | 
	
		
			
				|  |  | +    tar -cf stories.tar ./stories
 | 
	
		
			
				|  |  | +    gzip stories.tar
 | 
	
		
			
				|  |  | +)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +dbg "cleaning up..."
 | 
	
		
			
				|  |  | +cp $TMP/stories.tar.gz ./stories.tar.gz
 |