Skip to content

Commit

Permalink
rename bash scripts and minified files for gamejs & application
Browse files Browse the repository at this point in the history
all bash scripts in /bin and renamed, also copied lots of better shell
patterns from ringojs scripts (e.g. now they can actually be symlinked into /usr/bin/ and still work :| )

renamed all scripts and output files to better match common minification scripts `app.min.js` and `gamejs.min.js`

`gamejs.min.js` now put into gamejs home instead of deep into skeleton

remove api/doc - must be rendered by user
  • Loading branch information
oberhamsi committed Jan 21, 2012
1 parent 17fc18a commit 3f9721e
Show file tree
Hide file tree
Showing 42 changed files with 215 additions and 16,011 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
examples/skeleton/public/gamejs-wrapped.js
gamejs.min.js
docs/api/*
18 changes: 10 additions & 8 deletions README.md
Expand Up @@ -16,7 +16,9 @@ Usage
If you downloaded the git version, you will have to build the GameJs JavaScript
file. Go to the GameJs directory and execute this in a unix shell or in `git bash`:

$ ./wrap-gamejs.sh
$ ./bin/minify-gamejs.sh

This should create a `gamejs.min.js` file in the GameJs home directory.

See the `examples/skeleton/` directory for a minimal GameJs app. We recommend
you also use this as the scaffolding if you want to create a new game yourself.
Expand All @@ -29,12 +31,12 @@ Bundle your application for production
======================================

To wrap your own game's JavaScript files into one single file, use
`./wrap-directory ./path-to-your-app/javascript/`. You can also add a second argument
`./bin/minify-app.sh ./path-to-your-app/javascript/`. You can also add a second argument
`compress` to optionally minify the resulting JS file.

This will produce one file `gjs-app-wrapped.js` holding all GameJs modules as
well as your application code. You can then remove the `<script>` lines loading
yabble & gamejs-wrapped and should instead only load the `gjs-app-wrapped.js` file.
This will produce one file `app.min.js` holding all GameJs modules as
well as your application code. You can then remove all `<script>` lines except
the one loading the `app.min.js` file.

More Help
===========
Expand All @@ -50,11 +52,11 @@ GameJs Development
=====================================

In production, an application uses a bundled JavaScript file which contains all
GameJs modules (usually called `gamejs-wrapped.js`). This is what all the examples
GameJs modules (usually called `gamejs.min.js`). This is what all the examples
do.

Thus if you modify the files below `./lib` your changes won't show up in the
examples unless you re-bundle the files with the `./wrap-gamejs.sh` command
examples unless you re-bundle the files with the `./bin/minify-gamejs.sh` command

Unit Tests
--------------
Expand All @@ -67,4 +69,4 @@ JsDoc
For the JavaScript documentation system, RingoJs must be installed on your system.
This bash file will take care of rewriting the documentation into `docs/api/`:

$ ./create-jsdoc.sh
$ ./bin/create-jsdoc.sh
44 changes: 44 additions & 0 deletions bin/create-jsdoc.sh
@@ -0,0 +1,44 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Creates the API documentation for GameJs.
#
# REQUIRES RingoJs on path.
#
# Environment Variables
#
# GAMEJS_HOME (Optional) Ringo installation directory
# -----------------------------------------------------------------------------
# Many thanks to the RingoJs bash file writers.

#
# find_ringo_home - mostly an emulation of GNU's `readlink -f`
#
function find_gamejs_home() {
# save original working directory
ORIG_PWD="$(pwd -P)"

# walk the links! we cd into the dir of the target binary, read the link,
# make this link our new target, and start over. we stop as soon as the
# target is no link anymore.
T="$1"
while true; do
cd "$(dirname "$T")"
T="$(basename "$T")"
if [ ! -L "$T" ]; then break; fi
T="$(readlink "$T")"
done

# the final target is in bin/, change to parent and echo as home
cd ..
echo "$(pwd -P)"

# restore original working directory
cd "$ORIG_PWD"
}

if [ -z "$GAMEJS_HOME" ]; then
GAMEJS_HOME="$(find_gamejs_home "$0")"
fi

rm -rf ${GAMEJS_HOME}/docs/api/
ringo-doc -q --file-urls --source ${GAMEJS_HOME}/lib/ --directory ${GAMEJS_HOME}/docs/api/ --name 'GameJs API'
77 changes: 77 additions & 0 deletions bin/minify-app.sh
@@ -0,0 +1,77 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Wraps a game into one JavaScript file for efficient deployment.
# Optional argument `compress`:
#
# $ ./bin/minify-app.sh /path/to/game/javascript/ [compress]
#
# REQUIRES RingoJs on path.
#
# Environment Variables
#
# GAMEJS_HOME (Optional) Ringo installation directory
# JAVA_HOME (Optional) JDK installation directory
# -----------------------------------------------------------------------------
# Many thanks to the RingoJs bash file writers.

#
# find_ringo_home - mostly an emulation of GNU's `readlink -f`
#
function find_gamejs_home() {
# save original working directory
ORIG_PWD="$(pwd -P)"

# walk the links! we cd into the dir of the target binary, read the link,
# make this link our new target, and start over. we stop as soon as the
# target is no link anymore.
T="$1"
while true; do
cd "$(dirname "$T")"
T="$(basename "$T")"
if [ ! -L "$T" ]; then break; fi
T="$(readlink "$T")"
done

# the final target is in bin/, change to parent and echo as home
cd ..
echo "$(pwd -P)"

# restore original working directory
cd "$ORIG_PWD"
}

if [ -z "$GAMEJS_HOME" ]; then
GAMEJS_HOME="$(find_gamejs_home "$0")"
fi

if [ -z "$JAVA_HOME" ] ; then
java_cmd='java'
else
if [ "$OSTYPE" == 'cygwin' ]; then
java_cmd="`cygpath -u "$JAVA_HOME"`/bin/java"
else
java_cmd="$JAVA_HOME/bin/java"
fi
fi

if [[ -z "$1" ]] ; then
echo "Usage: $0 /path/to/game/javascript/ [compress]"
echo "Creates app.min.js in the first argument directory."
exit
fi

TEMP_WORKING=`mktemp --directory`
WRAPPED_FILE=$1/app.min.js
EXEC_YABBLER="${java_cmd} -jar ${GAMEJS_HOME}/utils/rhino/js.jar ${GAMEJS_HOME}/utils/yabbler/yabbler.js"
EXEC_CLOSURE="cat"
if [ "$2" = "compress" ] ; then
EXEC_CLOSURE="${java_cmd} -jar ${GAMEJS_HOME}/utils/closure-compiler/compiler.jar --jscomp_warning=internetExplorerChecks"
fi


rm -f ${WRAPPED_FILE}
${EXEC_YABBLER} -i $1 -o ${TEMP_WORKING}
${EXEC_YABBLER} -i ${GAMEJS_HOME}/lib/ -o ${TEMP_WORKING}
cat ${GAMEJS_HOME}/examples/skeleton/public/yabble.js | ${EXEC_CLOSURE} > ${WRAPPED_FILE}
find ${TEMP_WORKING} -type f -exec cat {} \; | ${EXEC_CLOSURE} >> ${WRAPPED_FILE}
rm -rf ${TEMP_WORKING}
65 changes: 65 additions & 0 deletions bin/minify-gamejs.sh
@@ -0,0 +1,65 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Create wrapped GameJs file.
#
# Environment Variables
#
# GAMEJS_HOME (Optional) Ringo installation directory
# JAVA_HOME (Optional) JDK installation directory
# -----------------------------------------------------------------------------
# Many thanks to the RingoJs bash file writers.

#
# find_ringo_home - mostly an emulation of GNU's `readlink -f`
#
function find_gamejs_home() {
# save original working directory
ORIG_PWD="$(pwd -P)"

# walk the links! we cd into the dir of the target binary, read the link,
# make this link our new target, and start over. we stop as soon as the
# target is no link anymore.
T="$1"
while true; do
cd "$(dirname "$T")"
T="$(basename "$T")"
if [ ! -L "$T" ]; then break; fi
T="$(readlink "$T")"
done

# the final target is in bin/, change to parent and echo as home
cd ..
echo "$(pwd -P)"

# restore original working directory
cd "$ORIG_PWD"
}

if [ -z "$GAMEJS_HOME" ]; then
GAMEJS_HOME="$(find_gamejs_home "$0")"
fi

if [ -z "$JAVA_HOME" ] ; then
java_cmd='java'
else
if [ "$OSTYPE" == 'cygwin' ]; then
java_cmd="`cygpath -u "$JAVA_HOME"`/bin/java"
else
java_cmd="$JAVA_HOME/bin/java"
fi
fi

TEMP_WORKING=`mktemp --directory`
EXEC_YABBLER="${java_cmd} -jar ${GAMEJS_HOME}/utils/rhino/js.jar ${GAMEJS_HOME}/utils/yabbler/yabbler.js"
EXEC_CLOSURE="cat"
OUTPUT_FILE="${GAMEJS_HOME}/gamejs.min.js"
OUTPUT_FILE_SKELETON="${GAMEJS_HOME}/examples/skeleton/public/gamejs.min.js"
if [ "$1" = "compress" ] ; then
EXEC_CLOSURE="${java_cmd} -jar ${GAMEJS_HOME}/utils/closure-compiler/compiler.jar --jscomp_warning=internetExplorerChecks"
fi

${EXEC_YABBLER} -i ${GAMEJS_HOME}/lib/ -o ${TEMP_WORKING}
find ${TEMP_WORKING} -type f -exec cat {} \; | ${EXEC_CLOSURE} > ${OUTPUT_FILE}
cp ${OUTPUT_FILE} ${OUTPUT_FILE_SKELETON}
rm -rf ${TEMP_WORKING}
echo "Wrote ${OUTPUT_FILE}"
8 changes: 0 additions & 8 deletions create-jsdoc.sh

This file was deleted.

0 comments on commit 3f9721e

Please sign in to comment.