diff --git a/.gitignore b/.gitignore index e43b0f98..fd4f2b06 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +node_modules .DS_Store diff --git a/.gitmodules b/.gitmodules index 9d45b547..5adf851b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "build/jsdoc-toolkit"] - path = build/jsdoc-toolkit - url = git://github.com/paperjs/jsdoc-toolkit.git +[submodule "jsdoc-toolkit"] + path = jsdoc-toolkit + url = https://github.com/paperjs/jsdoc-toolkit.git diff --git a/build/build.sh b/build/build.sh deleted file mode 100755 index 6594e011..00000000 --- a/build/build.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# Usage: -# build.sh MODE -# -# MODE: -# commented Preprocessed, still formated and commented -# stripped Preprocessed, formated but without comments - -if [ $# -eq 0 ] -then - MODE="stripped" -else - MODE=$1 -fi - -# Create the dist folder if it does not exist yet. -if [ ! -d ../dist/ ] -then - mkdir ../dist/ -fi - -if [ -f ../dist/paper-full.js ] -then - rm ../dist/paper-full.js -fi - -if [ -f ../dist/paper-node.js ] -then - rm ../dist/paper-node.js -fi - -./preprocess.sh $MODE ../src/paper.js "-i '../src/constants.js'" ../dist/paper-full.js -./preprocess.sh $MODE ../src/paper.js "-o '{ \"paperScript\": false, \"palette\": false }' -i '../src/constants.js'" ../dist/paper-core.js -./preprocess.sh $MODE ../src/paper.js "-o '{ \"environment\": \"node\", \"legacy\": false }' -i '../src/constants.js'" ../dist/paper-node.js diff --git a/build/dist.sh b/build/dist.sh deleted file mode 100755 index e9999669..00000000 --- a/build/dist.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -echo "Building paper.js" -./build.sh -echo "Minifying paper.js" -./minify.sh -echo "Building docs" -./docs.sh -echo "Zipping paperjs.zip" -./zip.sh diff --git a/build/docs.sh b/build/docs.sh deleted file mode 100755 index 0e85e255..00000000 --- a/build/docs.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# Generate documentation -# -# MODE: -# docs Generates the JS API docs - Default -# serverdocs Generates the website templates for the online JS API docs - -if [ $# -eq 0 ] -then - MODE="docs" -else - MODE=$1 -fi - -cd jsdoc-toolkit -# TODO: jsdoc2 -c=conf/$MODE.conf -D="renderMode:$MODE" -java -cp jsrun.jar:lib/* JsRun app/run.js -c=conf/$MODE.conf -D="renderMode:$MODE" -cd .. - -if [ $MODE = "docs" ] -then - # Build paper.js library for documentation - ./preprocess.sh stripped ../src/paper.js "-i '../src/constants.js'" ../dist/docs/assets/js/paper.js -fi diff --git a/build/jsdoc-toolkit b/build/jsdoc-toolkit deleted file mode 160000 index 00b7f8e4..00000000 --- a/build/jsdoc-toolkit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 00b7f8e4c2594620f58e03d3d1dd233548dab392 diff --git a/build/load.sh b/build/load.sh deleted file mode 100755 index 5ad58c37..00000000 --- a/build/load.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# This script simply creates symbolic links to src/load.js from -# dist/paper-full.js and dist/paper-node.js, which loads the library from -# separate sources through Prepro.js both in the browser and in Node.js. - -if [ -f ../dist/paper-full.js ] -then - rm ../dist/paper-full.js -fi - -if [ -f ../dist/paper-node.js ] -then - rm ../dist/paper-node.js -fi - -ln -s ../src/load.js ../dist/paper-full.js -ln -s ../src/load.js ../dist/paper-node.js diff --git a/build/minify-components.sh b/build/minify-components.sh deleted file mode 100755 index 01fbb234..00000000 --- a/build/minify-components.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -../node_modules/.bin/uglifyjs ../bower_components/acorn/acorn.js -o ../bower_components/acorn/acorn.min.js -c -m -b ascii_only=true,beautify=falsefy=false diff --git a/build/minify.sh b/build/minify.sh deleted file mode 100755 index 74bb77bb..00000000 --- a/build/minify.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -../node_modules/.bin/uglifyjs ../dist/paper-full.js -o ../dist/paper-full.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 /^!/ diff --git a/build/preprocess.sh b/build/preprocess.sh deleted file mode 100755 index f0a5ddeb..00000000 --- a/build/preprocess.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# 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 -# (#include, #ifdef, etc.). Three options offer control over whether comments -# are preserved or stripped and whitespaces are compressed. -# -# Usage: -# preprocess.sh MODE SOURCE ARGUMENTS DESTINATION -# -# MODE: -# 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 " - 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 diff --git a/build/publish.sh b/build/publish.sh deleted file mode 100755 index f638b84e..00000000 --- a/build/publish.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# Extract the paper.js version from options.js: -VERSION=$(printf '%q' $(node -e " - eval(require('fs').readFileSync('../src/options.js', 'utf8')); - process.stdout.write(__options.version); -")) - -# Helper function that updates paper.js vesion in JSON files -function update_version() -{ -node -e " - var data = require('$1'); - data.version = '$VERSION'; - require('fs').writeFile('$1', - JSON.stringify(data, null, ' ') + require('os').EOL); -" -} - -cd .. -PAPER_DIR=`PWD` -cd ../paperjs.org -SITE_DIR=`PWD` -DIST_FILE=content/11-Download/paperjs-v$VERSION.zip # Relative to $SITE_DIR - -cd $PAPER_DIR -# Make sure we're in the right branch -git checkout develop -cd $PAPER_DIR/build -./dist.sh -cd $PAPER_DIR -echo "Commiting Version" -# Update versions -update_version './package.json' -update_version './component.json' -# Add changed json configuration files -git add -u src/options.js # Commit as well, since it was manually bumped. -git add -u package.json -git add -u component.json -# Add all changed files in dist -git add -u dist -# Commit version -git commit -m "Release version v$VERSION" -# Tag version -git tag "v$VERSION" -# Merge develop into master -git checkout master -git merge develop -X theirs -# Push commits on both branches and tags -git push origin master develop -git push --tags -# Publish -npm publish -# Go back to develop branch and switch to using load.js again -git checkout develop -cd $PAPER_DIR/build -./load.sh -cd $PAPER_DIR -# Add all changed files in dist -git add -u dist -# Commit version -git commit -m "Switch back to load.js versions for development." -git push origin develop - -# Copy paperjs.zip to the website's download folder -cd $SITE_DIR -git pull -cp $PAPER_DIR/dist/paperjs.zip $DIST_FILE -# Update the online version of paper.js -cp $PAPER_DIR/dist/paper-full.js assets/js/paper.js -# Commit to paperjs.org -git add -A $DIST_FILE -git add -u assets/js/paper.js -git commit -m "Release version v$VERSION" -# Tag & Push -git tag "v$VERSION" -git push -git push --tags - -cd "$PAPER_DIR/build" diff --git a/build/typescript.sh b/build/typescript.sh deleted file mode 100755 index 338015df..00000000 --- a/build/typescript.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# Generates TypeScript declaration file - -cd jsdoc-toolkit -java -jar jsrun.jar app/run.js -c=conf/typescript.conf -cd .. diff --git a/build/zip.sh b/build/zip.sh deleted file mode 100755 index 84862426..00000000 --- a/build/zip.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. -# http://paperjs.org/ -# -# Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey -# http://scratchdisk.com/ & http://jonathanpuckey.com/ -# -# Distributed under the MIT license. See LICENSE file for details. -# -# All rights reserved. - -# Create a temporary folder to copy all files in for zipping -mkdir zip -cd zip -BASE=../.. - -# Copy license over -cp $BASE/LICENSE.txt . -# Make library folder and copy paper.js there -mkdir dist -# Copy all versions -cp $BASE/dist/paper-full.js dist -cp $BASE/dist/paper-full.min.js dist -cp $BASE/dist/paper-core.js dist -cp $BASE/dist/paper-core.min.js dist -# Copy examples over -cp -r $BASE/examples . -# Copy docs over -cp -r $BASE/dist/docs . -# Erase the old Zip file -if [ -f $BASE/dist/paperjs.zip ] -then - rm $BASE/dist/paperjs.zip -fi -# Zip the whole thing -zip -9 -r $BASE/dist/paperjs.zip * LICENSE.txt -x "*/.DS_Store" -cd .. -# Remove the temporary folder again -rm -fr zip diff --git a/gulpfile.js b/gulpfile.js index a7b59f25..4f1ef508 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,9 +11,160 @@ */ var gulp = require('gulp'), - qunit = require('gulp-qunit'); + qunit = require('gulp-qunit'), + prepro = require('gulp-prepro'), + rename = require('gulp-rename'), + rimraf = require('gulp-rimraf'), + shell = require('gulp-shell'), + symlink = require('gulp-symlink'), + uglify = require('gulp-uglify'), + uncomment = require('gulp-uncomment'), + whitespace = require('gulp-whitespace'), + zip = require('gulp-zip'), + merge = require('merge-stream'), + gitty = require('gitty')('.'), + fs = require('fs'); + +// Options to be used in Prepro.js preprocessing through the global __options +// object. +var buildOptions = { + full: { paperScript: true }, + core: { paperScript: false }, + node: { environment: 'node', paperScript: true } +}; + +var docOptions = { + local: 'docs', // Generates the offline docs + server: 'serverdocs' // Generates the website templates for the online docs +}; + +var uglifyOptions = { + output: { + // ascii_only: true, + comments: /^!/ + } +}; + +var buildNames = Object.keys(buildOptions); +var docNames = Object.keys(docOptions); + +gulp.on('error', function(err) { + console.error(err.toString()); + gulp.emit('end'); +}); gulp.task('test', function() { - return gulp.src('./test/index.html') + return gulp.src('test/index.html') .pipe(qunit({ timeout: 20, noGlobals: true })); }); + +docNames.forEach(function(name) { + gulp.task('docs:' + name, shell.task([ + 'java -cp jsrun.jar:lib/* JsRun app/run.js -c=conf/' + name + '.conf ' + + '-D="renderMode:' + docOptions[name] + '"', + ], { + cwd: 'jsdoc-toolkit' + })); +}); + +gulp.task('docs', ['docs:local']); + +gulp.task('load', ['clean:load'], function() { + return gulp.src('src/load.js') + .pipe(symlink('dist/paper-full.js')) + .pipe(symlink('dist/paper-node.js')); +}); + +gulp.task('clean:load', function() { + return gulp.src([ + 'dist/paper-full.js', + 'dist/paper-node.js' + ], { read: false }) + .pipe(rimraf()); +}); + +gulp.task('build', + buildNames.map(function(name) { + return 'build:' + name; + }) +); + +gulp.task('minify', ['build'], function() { + return gulp.src([ + 'dist/paper-full.js', + 'dist/paper-core.js' + ]) + .pipe(uglify(uglifyOptions)) + .pipe(rename({ + suffix: '.min' + })) + .pipe(gulp.dest('dist')); +}); + +gulp.task('dist', ['minify', 'docs'], function() { + return merge( + gulp.src([ + 'dist/paper-full*.js', + 'dist/paper-core*.js', + 'LICENSE.txt', + 'examples/**/*', + ], { base: '.' }), + gulp.src([ + 'dist/docs/**/*' + ], { base: 'dist' }) + ) + .pipe(zip('/paperjs.zip')) + .pipe(gulp.dest('dist')); +}); + +buildNames.forEach(function(name) { + // Get the date of the last commit from git. + var logData = gitty.logSync('-1'); + gulp.task('build:' + name, ['build:start'], function() { + return gulp.src('src/paper.js') + .pipe(prepro({ + evaluate: ['src/constants.js', 'src/options.js'], + setup: function() { + var options = buildOptions[name]; + options.date = logData[0].date; + // This object will be merged into the Prepro.js VM scope, + // which already holds a __options object from the above + // include statement. + return { __options: options }; + } + })) + .pipe(uncomment({ + mergeEmptyLines: true + })) + .pipe(whitespace({ + spacesToTabs: 4, + removeTrailing: true + })) + .pipe(rename({ + suffix: '-' + name + })) + .pipe(gulp.dest('dist')); + }); +}); + +gulp.task('build:start', ['clean:build', 'minify:acorn']); + +gulp.task('clean:build', function() { + return gulp.src('dist/paper-*.js', { read: false }) + .pipe(rimraf()); +}); + +gulp.task('minify:acorn', function() { + var path = 'bower_components/acorn/'; + // Only compress acorn if the compressed file doesn't exist yet. + try { + fs.accessSync(path + 'acorn.min.js'); + } catch(e) { + return gulp.src(path + 'acorn.js') + .pipe(uglify(uglifyOptions)) + .pipe(rename({ + suffix: '.min' + })) + .pipe(gulp.dest(path)); + } +}); diff --git a/jsdoc-toolkit b/jsdoc-toolkit new file mode 160000 index 00000000..29d94296 --- /dev/null +++ b/jsdoc-toolkit @@ -0,0 +1 @@ +Subproject commit 29d942966af938da861181e87ee98b6e91c92073 diff --git a/node_modules/.gitignore b/node_modules/.gitignore deleted file mode 100644 index 514ffca0..00000000 --- a/node_modules/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.bin -canvas -grunt* -gulp* -jsdom -jshint -prepro -qunitjs -request -uglify-js diff --git a/package.json b/package.json index 076e00fa..7f4aad73 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,21 @@ "canvas": ">=1.2.9 <2.0.0" }, "devDependencies": { + "gitty": "^3.3.3", "gulp": "^3.9.0", + "gulp-prepro": "^2.0.0", "gulp-qunit": "git://github.com/lehni/gulp-qunit.git#459c5603ceac460327a40dc89df6f19c786dc61b", + "gulp-rename": "^1.2.2", + "gulp-rimraf": "^0.2.0", + "gulp-shell": "^0.5.1", + "gulp-symlink": "^2.1.3", + "gulp-uglify": "^1.5.1", + "gulp-uncomment": "^0.2.0", + "gulp-whitespace": "^0.1.0", + "gulp-zip": "^3.0.2", "jshint": "2.8.x", - "prepro": "~0.9.1", - "uglify-js": "~2.4.24" + "merge-stream": "^1.0.0", + "prepro": "^2.0.0" }, "keywords": [ "vector", diff --git a/src/load.js b/src/load.js index 09048e5c..01632223 100644 --- a/src/load.js +++ b/src/load.js @@ -41,10 +41,15 @@ if (typeof window === 'object') { // Step out and back into src in case this is loaded from dist/paper-node.js prepro.include('../src/options.js'); // Override node specific options. - prepro.setOptions({ - environment: 'node', - legacy: false, - version: 'dev' + prepro.setup(function() { + // This object will be merged into the Prepro.js VM scope, which already + // holds a __options object from the above include statement. + return { + __options: { + version: 'dev', + environment: 'node' + } + }; }); // Load Paper.js library files. prepro.include('../src/paper.js'); diff --git a/src/path/Curve.js b/src/path/Curve.js index 11e25fb0..66a7b00e 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1847,7 +1847,7 @@ new function() { // Scope for intersection using bezier fat-line clipping geomEpsilon = /*#=*/Numerical.GEOMETRIC_EPSILON, straight1 = Curve.isStraight(v1), straight2 = Curve.isStraight(v2), - straightBoth = straight1 && straight2; + straightBoth = straight1 && straight2; // Linear curves can only overlap if they are collinear. Instead of // using the #isCollinear() check, we pick the longer of the two