Switch to NPM based PrePro and update README.MD accordingly.

This commit is contained in:
Jürg Lehni 2013-06-26 18:04:56 -07:00
parent a908556956
commit b5b269fd8f
9 changed files with 49 additions and 257 deletions

View file

@ -12,16 +12,8 @@ If you want to work with Paper.js, simply download the latest "stable" version f
**Get the source (for building):**
Git 1.6.5 and later:
git clone --recursive git://github.com/paperjs/paper.js.git
Git 1.6.4 and earlier:
git clone git://github.com/paperjs/paper.js.git
cd paper.js
git submodule update --init
**Get the source (for contributing):**
If you want to contribute to the project you will have to [make a fork](http://help.github.com/forking/). Then do this:
@ -58,9 +50,9 @@ You will then find the built library inside the `dist` folder, named `paper.js`.
stripped Formated but without comments (default)
compressed Uses UglifyJS to reduce file size
In order to build a compressed version of Paper.js, UglifyJS2 needs to be installed:
In order to build your own versions of Paper.js, both PrePro and UglifyJS need to be installed locally. Make sure you have Node.js and NPM installed and run this command the root folder:
npm install uglify-js
npm install
### Building the Documentation

View file

@ -30,6 +30,6 @@ then
mkdir ../dist/
fi
./preprocess.sh $MODE ../src/paper.js "-d '{ \"browser\": true }' -i '../src/constants.js'" ../dist/paper.js
./preprocess.sh $MODE ../src/paper.js "-d '{ \"browser\": true, \"paperscript\": false }' -i '../src/constants.js'" ../dist/paper-core.js
#./preprocess.sh $MODE ../src/paper.js "-d '{ \"node\": true }' -i '../src/constants.js'" ../dist/paper-node.js
./preprocess.sh $MODE ../src/paper.js "-o '{ \"browser\": true }' -i '../src/constants.js'" ../dist/paper.js
./preprocess.sh $MODE ../src/paper.js "-o '{ \"browser\": true, \"paperscript\": false }' -i '../src/constants.js'" ../dist/paper-core.js
#./preprocess.sh $MODE ../src/paper.js "-o '{ \"node\": true }' -i '../src/constants.js'" ../dist/paper-node.js

View file

@ -30,5 +30,5 @@ cd ..
if [ $MODE = "docs" ]
then
# Build paper.js library for documentation
./preprocess.sh stripped ../src/paper.js "-d '{ \"browser\": true }' -i '../src/constants.js'" ../dist/docs/resources/js/paper.js
./preprocess.sh stripped ../src/paper.js "-o '{ \"browser\": true }' -i '../src/constants.js'" ../dist/docs/resources/js/paper.js
fi

View file

@ -10,5 +10,5 @@
#
# All rights reserved.
uglifyjs ../lib/acorn.js -o ../lib/acorn-min.js -c -m -b ascii_only=true,beautify=false
uglifyjs ../lib/esprima.js -o ../lib/esprima-min.js -c -m -b ascii_only=true,beautify=false
../node_modules/.bin/uglifyjs ../lib/acorn.js -o ../lib/acorn-min.js -c -m -b ascii_only=true,beautify=false
../node_modules/.bin/uglifyjs ../lib/esprima.js -o ../lib/esprima-min.js -c -m -b ascii_only=true,beautify=false

View file

@ -10,5 +10,5 @@
#
# All rights reserved.
uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true -m -b ascii_only=true,beautify=false --comments /^!/
uglifyjs ../dist/paper-core.js -o ../dist/paper-core-min.js -c unsafe=true -m --comments /^!/
../node_modules/.bin/uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true -m -b ascii_only=true,beautify=false --comments /^!/
../node_modules/.bin/uglifyjs ../dist/paper-core.js -o ../dist/paper-core-min.js -c unsafe=true -m --comments /^!/

View file

@ -1,222 +0,0 @@
#! /usr/bin/env node
/*
* 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.
*/
/**
* 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.
*
* Arguments:
* -d DEFINE_JSON -- define a json containing defintions availabe to prepro
* -i INCLUDE_JS -- include a JS file containing definitinos availabe to prepro
* -c -- strip comments
*/
// Required libs
var fs = require('fs'),
path = require('path'),
vm = require('vm');
// 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:
// /*#=*/ eval (outside comments)
// *#=* eval (inside comments)
line = line.replace(/\/?\*#=\*\/?\s*([\w.]*)/g,
function(all, val) {
return eval(val);
}
);
// Now add a statement that when evaluated writes out this code line
code.push('out.push(' + JSON.stringify(line) + ');');
}
});
}
function parse() {
var out = [];
// Evaluate the collected code: Collects result in out, through out.push()
eval(code.join('\n'));
// Start again with a new code buffer.
code = [];
// Return the resulting lines as one string.
return out.join('\n');
}
// Parse arguments
var args = process.argv.slice(2),
options = {},
files = [],
strip = false;
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;
case '-i':
// Include code to be present at prepro time, e.g. for on-the-fly
// replacement of constants, using /*#=*/ statements.
// Luckily we can reuse the include() / parse() functionality to do so:
var file = args.shift();
if (file) {
include(path.resolve(), path.normalize(file));
eval(parse());
}
break;
case '-c':
strip = true;
break;
default:
files.push(arg);
}
}
// Include all files. Everything else happens from there, through include()
files.forEach(function(file) {
include(path.resolve(), file);
});
var out = parse();
if (strip) {
out = stripComments(out);
// Strip empty lines that contain only white space and line breaks, as they
// are left-overs from comment removal.
out = out.replace(/^[ \t]+(\r\n|\n|\r)/gm, function(all) {
return '';
});
// Replace a sequence of more than two line breaks with only two.
out = out.replace(/(\r\n|\n|\r)(\r\n|\n|\r)+/g, function(all, lineBreak) {
return lineBreak + lineBreak;
});
}
// Write the result out
process.stdout.write(out);
/**
* Strips comments out of JavaScript code, based on:
* http://james.padolsey.com/javascript/removing-comments-in-javascript/
*/
function stripComments(str) {
// Add some padding so we can always look ahead and behind by two chars
str = ('__' + str + '__').split('');
var quote = false,
quoteSign,
regularExpression = false,
characterClass = false,
blockComment = false,
lineComment = false,
preserveComment = false;
for (var i = 0, l = str.length; i < l; i++) {
// When checking for quote escaping, we also need to check that the
// escape sign itself is not escaped, as otherwise '\\' would cause
// the wrong impression of an unclosed string:
var unescaped = str[i - 1] !== '\\' || str[i - 2] === '\\';
if (quote) {
if (str[i] === quoteSign && unescaped)
quote = false;
} else if (regularExpression) {
// Make sure '/'' inside character classes is not considered the end
// of the regular expression.
if (str[i] === '[' && unescaped) {
characterClass = true;
} else if (str[i] === ']' && unescaped && characterClass) {
characterClass = false;
} else if (str[i] === '/' && unescaped && !characterClass) {
regularExpression = false;
}
} else if (blockComment) {
// Is the block comment closing?
if (str[i] === '*' && str[i + 1] === '/') {
if (!preserveComment)
str[i] = str[i + 1] = '';
blockComment = preserveComment = false;
// Increase by 1 to skip closing '/', as it would be mistaken
// for a regexp otherwise
i++;
} else if (!preserveComment) {
str[i] = '';
}
} else if (lineComment) {
// One-line comments end with the line-break
if (/[\n\r]/.test(str[i + 1]))
lineComment = false;
str[i] = '';
} else {
if (/['"]/.test(str[i])) {
quote = true;
quoteSign = str[i];
} else if (str[i] === '/') {
if (str[i + 1] === '*') {
// Do not filter out conditional comments /*@ ... */
// and comments marked as protected /*! ... */
preserveComment = /[@!]/.test(str[i + 2]);
if (!preserveComment)
str[i] = '';
blockComment = true;
} else if (str[i + 1] === '/') {
str[i] = '';
lineComment = true;
} else {
// We need to make sure we don't count normal divisions as
// regular expresions. Matching this properly is difficult,
// but if we assume that normal division always have a space
// after /, a simple check for white space or '='' (for /=)
// is enough to distinguish divisions from regexps.
// TODO: Develop a proper check for regexps.
if (!/[\s=]/.test(str[i + 1])) {
regularExpression = true;
}
}
}
}
}
// Remove padding again.
return str.join('').slice(2, -2);
}

View file

@ -36,7 +36,7 @@ OPTIONS=$(printf '%q' $(node -e "
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\", \"stats\": false }' $3 $2"
COMMAND="../node_modules/.bin/prepro -o $OPTIONS -o '{ \"version\": \"$VERSION\", \"date\": \"$DATE\", \"stats\": false }' $3 $2"
case $1 in
commented)

4
node_modules/.gitignore generated vendored
View file

@ -1,2 +1,6 @@
.bin
canvas
jsdom
uglify-js
prepro
grunt*

View file

@ -1,18 +1,36 @@
{
"name": "paper",
"version": "0.9.4",
"main": "./src/node/index.js",
"engines": { "node": ">= 0.4.0" },
"dependencies": {
"canvas": ">= 0.7.0",
"jsdom": ">= 0.6.0"
},
"description": "The Swiss Army Knife of Vector Graphics Scripting",
"contributors": [
"Jürg Lehni <juerg@lehni.org> (http://lehni.org)",
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
],
"homepage": "http://paperjs.org",
"repository": "git://github.com/paperjs/paper.js",
"keywords": ["vector", "graphic", "graphics", "bezier", "curve", "curves", "canvas", "svg", "paper.js"]
"name": "paper",
"version": "0.9.4",
"main": "./src/node/index.js",
"engines": {
"node": ">= 0.4.0"
},
"dependencies": {
"canvas": ">= 0.7.0",
"jsdom": ">= 0.6.0"
},
"description": "The Swiss Army Knife of Vector Graphics Scripting",
"contributors": [
"Jürg Lehni <juerg@lehni.org> (http://lehni.org)",
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
],
"homepage": "http://paperjs.org",
"repository": "git://github.com/paperjs/paper.js",
"keywords": [
"vector",
"graphic",
"graphics",
"bezier",
"curve",
"curves",
"canvas",
"svg",
"paper.js"
],
"devDependencies": {
"uglify-js": "~2.3.6",
"prepro": "~0.5.0",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.2"
}
}