2013-05-30 18:47:47 -04:00
|
|
|
#!/bin/bash
|
2011-06-25 16:34:59 -04:00
|
|
|
|
2013-01-28 21:03:27 -05:00
|
|
|
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
# http://paperjs.org/
|
2011-03-06 19:50:44 -05:00
|
|
|
#
|
2015-12-27 12:09:25 -05:00
|
|
|
# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
|
2014-01-03 19:47:16 -05:00
|
|
|
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2011-03-06 19:50:44 -05:00
|
|
|
#
|
2011-07-01 06:17:45 -04:00
|
|
|
# Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
#
|
|
|
|
# All rights reserved.
|
2011-03-06 19:50:44 -05:00
|
|
|
|
2011-03-03 08:45:21 -05:00
|
|
|
# preprocess.sh
|
|
|
|
#
|
|
|
|
# A simple code preprocessing wrapper that uses a combination of cpp, jssrip.py
|
|
|
|
# and sed to preprocess JavaScript files containing C-style preprocess macros
|
2013-08-08 18:21:35 -04:00
|
|
|
# (#include, #ifdef, etc.). Three options offer control over whether comments
|
2011-03-03 08:45:21 -05:00
|
|
|
# are preserved or stripped and whitespaces are compressed.
|
|
|
|
#
|
|
|
|
# Usage:
|
2013-02-28 20:41:02 -05:00
|
|
|
# preprocess.sh MODE SOURCE ARGUMENTS DESTINATION
|
2011-03-03 08:45:21 -05:00
|
|
|
#
|
|
|
|
# MODE:
|
2014-08-16 13:24:54 -04:00
|
|
|
# commented Preprocessed, still formated and commented
|
|
|
|
# stripped Preprocessed, formated but without comments
|
2011-03-03 08:45:21 -05:00
|
|
|
|
2013-05-27 18:11:32 -04:00
|
|
|
# Get the date from the git log:
|
2011-07-24 14:41:13 -04:00
|
|
|
DATE=$(git log -1 --pretty=format:%ad)
|
2014-04-06 08:47:45 -04:00
|
|
|
# Load __options from options.js and convert it to escaped JSON, to be passed on
|
|
|
|
# to prepro:
|
2013-05-27 18:11:32 -04:00
|
|
|
OPTIONS=$(printf '%q' $(node -e "
|
2014-08-16 13:24:54 -04:00
|
|
|
eval(require('fs').readFileSync('../src/options.js', 'utf8'));
|
|
|
|
process.stdout.write(JSON.stringify(__options));
|
2013-05-27 18:11:32 -04:00
|
|
|
"))
|
|
|
|
# Build the prepo.js command out of it, passing on version and date as defines:
|
2014-08-16 12:49:35 -04:00
|
|
|
COMMAND="../node_modules/.bin/prepro -o $OPTIONS -o '{ \"date\": \"$DATE\" }' $3 $2"
|
2014-08-16 13:44:44 -04:00
|
|
|
# Flags to pass to prepro
|
|
|
|
if [ $1 = "stripped" ]; then FLAGS="-c"; else FLAGS=""; fi
|
2011-03-03 08:45:21 -05:00
|
|
|
|
2014-08-16 13:44:44 -04:00
|
|
|
eval "$COMMAND $FLAGS" > $4
|
|
|
|
# Now convert 4 spaces to tabs, to shave of some bytes (quite a few KB actually)
|
2014-08-25 07:04:35 -04:00
|
|
|
unexpand -t 4 -a $4 > "$4-tabs" && mv "$4-tabs" $4
|
|
|
|
# Remove trailing white-space on each line
|
|
|
|
perl -p -i -e "s/[ \t]*$//g" $4
|