diff --git a/build/preprocess.sh b/build/preprocess.sh index c89dd0c8..b76f8357 100755 --- a/build/preprocess.sh +++ b/build/preprocess.sh @@ -24,10 +24,19 @@ # commented Preprocessed, still formated and commented # stripped Preprocessed, formated but without comments -# Extract paper.js version from package.json -VERSION=$(node -e "process.stdout.write(require('../package.json').version)") +# Get the date from the git log: DATE=$(git log -1 --pretty=format:%ad) -COMMAND="./prepro.js -d '{ \"version\": \"$VERSION\", \"date\": \"$DATE\", \"parser\": \"acorn\", \"svg\": true, \"fatline\": false }' $3 $2" +# Extract the paper.js version from package.json: +VERSION=$(node -e " + process.stdout.write(require('../package.json').version) +") +# Load and evaluate the options from options.js, and convert it an escaped json: +OPTIONS=$(printf '%q' $(node -e " + 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="./prepro.js -d $OPTIONS -d '{ \"version\": \"$VERSION\", \"date\": \"$DATE\" }' $3 $2" case $1 in commented) diff --git a/src/load.js b/src/load.js index 97430850..73a5d453 100644 --- a/src/load.js +++ b/src/load.js @@ -14,17 +14,7 @@ // 'preprocess' it on the fly in the browser, avoiding the step of having to // manually preprocess it after each change. -// Define options for compile-time preprocessing. -var options = { - parser: 'acorn', - version: 'dev', - browser: true, - stats: true, - svg: true, - fatline: true, - debug: false -}; - // This folder is specified relatively to the lib folder from which prepro.js is // loaded, and which is referenced as the root. +include('../src/options.js'); include('../src/paper.js'); diff --git a/src/node/index.js b/src/node/index.js index d60cab5c..960365cb 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -18,14 +18,13 @@ var fs = require('fs'), jsdom = require('jsdom'), domToHtml = require('jsdom/lib/jsdom/browser/domtohtml').domToHtml; -var options = { - parser: 'acorn', - // Use 'dev' for on-the fly compilation of separate files ,but update after. - version: 'dev', - server: true, - svg: true, - fatline: false -}; +// Load the options from load.js, but evaluate into local scope: +eval(fs.readFileSync(path.resolve(__dirname, '../options.js'), 'utf8')); +// Change node.js specific settings. Use 'dev' version for on-the fly +// compilation of separate files, and set to correct value after. +options.version = 'dev'; +options.browser = false; +options.server = true; // Create a document and a window using jsdom, e.g. for exportSVG() var doc = jsdom.jsdom(""), diff --git a/src/options.js b/src/options.js new file mode 100644 index 00000000..20d1e802 --- /dev/null +++ b/src/options.js @@ -0,0 +1,24 @@ +/* + * Paper.js - The Swiss Army Knife of Vector Graphics Scripting. + * http://paperjs.org/ + * + * Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey + * http://lehni.org/ & http://jonathanpuckey.com/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * All rights reserved. + */ + +// Define default options for compile-time preprocessing. These are also used +// for building, but some values are overridden (e.g. version, stats). + +var options = { + parser: 'acorn', + version: 'dev', + browser: true, + stats: true, + svg: true, + fatline: false, + debug: false +};