paper.js/build/preprocess.sh

45 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
2011-06-25 16:34:59 -04:00
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
2011-03-06 19:50:44 -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
# 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
# are preserved or stripped and whitespaces are compressed.
#
# Usage:
2013-02-28 20:41:02 -05:00
# preprocess.sh MODE SOURCE ARGUMENTS DESTINATION
#
# MODE:
2014-08-16 13:24:54 -04:00
# commented Preprocessed, still formated and commented
# stripped Preprocessed, formated but without comments
# Get the date from the git log:
DATE=$(git log -1 --pretty=format:%ad)
# Load __options from options.js and convert it to escaped JSON, to be passed on
# to prepro:
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));
"))
# Build the prepo.js command out of it, passing on version and date as defines:
COMMAND="../node_modules/.bin/prepro -o $OPTIONS -o '{ \"date\": \"$DATE\" }' $3 $2"
# Flags to pass to prepro
if [ $1 = "stripped" ]; then FLAGS="-c"; else FLAGS=""; fi
eval "$COMMAND $FLAGS" > $4
# Now convert 4 spaces to tabs, to shave of some bytes (quite a few KB actually)
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