Remove filepp.pl as preprocessor and switch to our own Prepro.js, a simple preprocesssor for JavaScript that speaks JavaScript, written in JavaScript, allowing preprocessing to either happen at build time or compile time.

This commit is contained in:
Jürg Lehni 2011-07-26 10:09:31 +01:00
parent a0a426982f
commit 8eaeb7fb5e
9 changed files with 168 additions and 2995 deletions

View file

@ -35,5 +35,5 @@ then
mkdir ../dist/ mkdir ../dist/
fi fi
./preprocess.sh $MODE ../src/paper.js ../dist/paper.js "-DBROWSER" ./preprocess.sh $MODE ../src/paper.js ../dist/paper.js '{ "browser": true }'
#./preprocess.sh $MODE ../src/paper.js ../dist/paper-server.js "-DSERVER" #./preprocess.sh $MODE ../src/paper.js ../dist/paper-server.js '{ "server": true }'

File diff suppressed because it is too large Load diff

97
build/prepro.js Executable file
View file

@ -0,0 +1,97 @@
#! /usr/bin/env node
/*
* Paper.js
*
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
* based on Scriptographer.org and designed to be largely API compatible.
* http://paperjs.org/
* http://scriptographer.org/
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* Prepro.js - A simple preprocesssor for JavaScript that speaks JavaScript,
* written in JavaScript, allowing preprocessing to either happen at build time
* or compile time. Very useful for libraries that are built for distribution,
* but can be also compiled from seperate sources directly for development,
* supporting build time switches.
*/
// Require libs
var fs = require('fs'),
path = require('path');
// Parse arguments
var args = process.argv.slice(2),
options = {},
files = [];
while (args.length > 0) {
var arg = args.shift();
switch (arg) {
case '-d':
// Definitions are provided as JSON and supposed to be object literals
var def = JSON.parse(args.shift());
// Merge new definitions into options object.
for (var key in def)
options[key] = def[key];
break;
default:
files.push(arg);
}
}
// Preprocessing
var code = [];
function include(base, file) {
// Compose a pathname from base and file, which is specified relatively,
// and normalize the new path, to get rid of ..
file = path.normalize(path.join(base, file));
var content = fs.readFileSync(file).toString();
content.split(/\r\n|\n|\r/mg).forEach(function(line) {
// See if our line starts with the preprocess prefix.
var match = line.match(/^\s*\/\*#\*\/\s*(.*)$/);
if (match) {
// Check if the preprocessing line is an include statement, and if
// so, handle it straight away
line = match[1];
if (match = line.match(/^include\(['"]([^;]*)['"]\);?$/)) {
// Pass on the dirname of the current file as the new base
include(path.dirname(file), match[1]);
} else {
// Any other preprocessing code is simply added, for later
// evaluation.
code.push(line);
}
} else {
// Perhaps we need to replace some values? Supported formats are:
// /*#=*/ options.NAME (outside comments)
// *#=* options.NAME (inside comments)
line = line.replace(/\/?\*#=\*\/?\s*options\.([\w]*)/g,
function(all, name) {
return options[name];
}
);
// No add a statement that when evaluated writes out this code line
code.push('console.log(' + JSON.stringify(line) + ');');
}
});
}
// Include all files. Everything else happens from there, through include()
files.forEach(function(file) {
include(path.resolve(), file);
});
// Evaluate the resulting code: Calls puts() and writes the result to stdout.
eval(code.join('\n'));

View file

@ -35,8 +35,8 @@
VERSION=0.2 VERSION=0.2
DATE=$(git log -1 --pretty=format:%ad) DATE=$(git log -1 --pretty=format:%ad)
KEYWORD="//#" COMMAND="./prepro.js -d '{ \"version\": $VERSION, \"date\": \"$DATE\" }' -d '$4' $2"
COMMAND="./filepp.pl -kc $KEYWORD $4 -DVERSION=$VERSION -DDATE='$DATE' $2" echo $COMMAND
case $1 in case $1 in
stripped) stripped)

View file

@ -42,7 +42,7 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
* *
* @type Number * @type Number
*/ */
version: VERSION, version: /*#=*/ options.version,
/** /**
* The currently active project. * The currently active project.

View file

@ -19,7 +19,7 @@
* @namespace * @namespace
*/ */
var PaperScript = this.PaperScript = new function() { var PaperScript = this.PaperScript = new function() {
//#include "../../lib/parse-js-min.js" /*#*/ include('../../lib/parse-js-min.js');
// Math Operators // Math Operators
@ -153,7 +153,7 @@ var PaperScript = this.PaperScript = new function() {
* @return {Object} The result of the code evaluation. * @return {Object} The result of the code evaluation.
*/ */
function evaluate(code, scope) { function evaluate(code, scope) {
//#ifdef BROWSER /*#*/ if (options.browser) {
// See if it's a script tag or a string // See if it's a script tag or a string
if (typeof code !== 'string') { if (typeof code !== 'string') {
// If a canvas id is provided, create a project for it now, // If a canvas id is provided, create a project for it now,
@ -171,7 +171,7 @@ var PaperScript = this.PaperScript = new function() {
code = code.innerHTML; code = code.innerHTML;
} }
} }
//#endif // BROWSER /*#*/ } // options.browser
// Set currently active scope. // Set currently active scope.
paper = scope; paper = scope;
var view = scope.view, var view = scope.view,
@ -224,7 +224,7 @@ var PaperScript = this.PaperScript = new function() {
return res; return res;
} }
//#ifdef BROWSER /*#*/ if (options.browser) {
// Code borrowed from Coffee Script: // Code borrowed from Coffee Script:
function request(url, scope) { function request(url, scope) {
var xhr = new (window.ActiveXObject || XMLHttpRequest)( var xhr = new (window.ActiveXObject || XMLHttpRequest)(
@ -287,14 +287,14 @@ var PaperScript = this.PaperScript = new function() {
hasAttribute: handleAttribute('has') hasAttribute: handleAttribute('has')
}; };
//#else // !BROWSER /*#*/ } else { // !options.browser
return { return {
compile: compile, compile: compile,
evaluate: evaluate evaluate: evaluate
}; };
//#endif // !BROWSER /*#*/ } // !options.browser
}; };
// Export load directly: // Export load directly:

View file

@ -35,11 +35,11 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
if (object.getContext) { if (object.getContext) {
this.setCanvas(object); this.setCanvas(object);
} else { } else {
//#ifdef BROWSER /*#*/ if (options.browser) {
// If it's a string, get the element with this id first. // If it's a string, get the element with this id first.
if (typeof object === 'string') if (typeof object === 'string')
object = document.getElementById(object); object = document.getElementById(object);
//#endif // BROWSER /*#*/ } // options.browser
this.setImage(object); this.setImage(object);
} }
this._matrix = new Matrix(); this._matrix = new Matrix();

View file

@ -1,5 +1,5 @@
/*! /*!
* Paper.js vVERSION * Paper.js v*#=* options.version
* *
* This file is part of Paper.js, a JavaScript Vector Graphics Library, * This file is part of Paper.js, a JavaScript Vector Graphics Library,
* based on Scriptographer.org and designed to be largely API compatible. * based on Scriptographer.org and designed to be largely API compatible.
@ -13,7 +13,7 @@
* *
* All rights reserved. * All rights reserved.
* *
* Date: DATE * Date: *#=* options.date
* *
*** ***
* *
@ -134,78 +134,78 @@
var paper = new function() { var paper = new function() {
// Inline Bootstrap core (the Base class) inside the paper scope first: // Inline Bootstrap core (the Base class) inside the paper scope first:
//#include "../lib/bootstrap.js" /*#*/ include('../lib/bootstrap.js');
//#include "core/Base.js" /*#*/ include('core/Base.js');
//#include "core/PaperScope.js" /*#*/ include('core/PaperScope.js');
// Include Paper classes, which are later injected into PaperScope by setting // Include Paper classes, which are later injected into PaperScope by setting
// them on the 'this' object, e.g.: // them on the 'this' object, e.g.:
// var Point = this.Point = Base.extend(...); // var Point = this.Point = Base.extend(...);
//#include "basic/Point.js" /*#*/ include('basic/Point.js');
//#include "basic/Size.js" /*#*/ include('basic/Size.js');
//#include "basic/Rectangle.js" /*#*/ include('basic/Rectangle.js');
//#include "basic/Matrix.js" /*#*/ include('basic/Matrix.js');
//#include "basic/Line.js" /*#*/ include('basic/Line.js');
//#include "project/Project.js" /*#*/ include('project/Project.js');
//#include "project/Symbol.js" /*#*/ include('project/Symbol.js');
//#include "item/ChangeFlag.js" /*#*/ include('item/ChangeFlag.js');
//#include "item/Item.js" /*#*/ include('item/Item.js');
//#include "item/Group.js" /*#*/ include('item/Group.js');
//#include "item/Layer.js" /*#*/ include('item/Layer.js');
//#include "item/PlacedItem.js" /*#*/ include('item/PlacedItem.js');
//#include "item/Raster.js" /*#*/ include('item/Raster.js');
//#include "item/PlacedSymbol.js" /*#*/ include('item/PlacedSymbol.js');
//#include "item/HitResult.js" /*#*/ include('item/HitResult.js');
//#include "path/Segment.js" /*#*/ include('path/Segment.js');
//#include "path/SegmentPoint.js" /*#*/ include('path/SegmentPoint.js');
//#include "path/SelectionState.js" /*#*/ include('path/SelectionState.js');
//#include "path/Curve.js" /*#*/ include('path/Curve.js');
//#include "path/CurveLocation.js" /*#*/ include('path/CurveLocation.js');
//#include "path/PathItem.js" /*#*/ include('path/PathItem.js');
//#include "path/Path.js" /*#*/ include('path/Path.js');
//#include "path/Path.Constructors.js" /*#*/ include('path/Path.Constructors.js');
//#include "path/CompoundPath.js" /*#*/ include('path/CompoundPath.js');
//#include "path/PathFlattener.js" /*#*/ include('path/PathFlattener.js');
//#include "path/PathFitter.js" /*#*/ include('path/PathFitter.js');
//#include "text/TextItem.js" /*#*/ include('text/TextItem.js');
//#include "text/PointText.js" /*#*/ include('text/PointText.js');
//#include "style/Style.js" /*#*/ include('style/Style.js');
//#include "style/PathStyle.js" /*#*/ include('style/PathStyle.js');
//#include "style/ParagraphStyle.js" /*#*/ include('style/ParagraphStyle.js');
//#include "style/CharacterStyle.js" /*#*/ include('style/CharacterStyle.js');
//#include "color/Color.js" /*#*/ include('color/Color.js');
//#include "color/GradientColor.js" /*#*/ include('color/GradientColor.js');
//#include "color/Gradient.js" /*#*/ include('color/Gradient.js');
//#include "color/GradientStop.js" /*#*/ include('color/GradientStop.js');
//#ifdef BROWSER /*#*/ if (options.browser) {
//#include "browser/DomElement.js" /*#*/ include('browser/DomElement.js');
//#include "browser/DomEvent.js" /*#*/ include('browser/DomEvent.js');
//#include "ui/View.js" /*#*/ include('ui/View.js');
//#include "ui/Event.js" /*#*/ include('ui/Event.js');
//#include "ui/KeyEvent.js" /*#*/ include('ui/KeyEvent.js');
//#include "ui/Key.js" /*#*/ include('ui/Key.js');
//#include "tool/ToolEvent.js" /*#*/ include('tool/ToolEvent.js');
//#include "tool/Tool.js" /*#*/ include('tool/Tool.js');
//#endif // BROWSER /*#*/ } // options.browser
//#include "util/CanvasProvider.js" /*#*/ include('util/CanvasProvider.js');
//#include "util/Numerical.js" /*#*/ include('util/Numerical.js');
//#include "util/BlendMode.js" /*#*/ include('util/BlendMode.js');
//#include "core/PaperScript.js" /*#*/ include('core/PaperScript.js');
// Iterate over all proced Base classes and set the _name property of their // Iterate over all proced Base classes and set the _name property of their
// constructors to the key under which they are stored. This is a simple hack // constructors to the key under which they are stored. This is a simple hack

View file

@ -37,15 +37,15 @@ var CanvasProvider = {
} }
return canvas; return canvas;
} else { } else {
//#ifdef BROWSER /*#*/ if (options.browser) {
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = size.width; canvas.width = size.width;
canvas.height = size.height; canvas.height = size.height;
return canvas; return canvas;
//#else // !BROWSER /*#*/ } else { // !options.browser
// Only rhino-canvas for now: // Only rhino-canvas for now:
return new Image(size.width, size.height); return new Image(size.width, size.height);
//#endif // !BROWSER /*#*/ } // !options.browser
} }
}, },