diff --git a/README.md b/README.md index 241dfa31..0ca5cb99 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Paper.js, in minified and normal variants: ### Installing Node.js, NPM and Bower -Node.js is required by Bower, as well as by Gulp, which needs to be installed if -you intend to build the library or its documentation by yourself. +Node.js is required by Bower, as well as by Gulp.js, which needs to be installed +if you intend to build the library or its documentation by yourself. There are many tutorials explaining the different ways to install Node.js on different platforms. It is generally not recommended to install Node.js through @@ -147,7 +147,7 @@ run: ### Setting Up For Building -As of 2016, Paper.js uses [Gulp](http://gulpjs.com/) for building, and has a +As of 2016, Paper.js uses [Gulp.js](http://gulpjs.com/) for building, and has a couple of dependencies as Bower and NPM modules. Read the chapter [Installing Node.js, NPM and Bower](#installing-nodejs-npm-and-bower) if you still need to install these. @@ -159,8 +159,8 @@ following commands from the Paper.js directory: npm install bower install -It is also recommended to install Gulp globally, so you can easier execute the -build commands from anywhere in the command line: +It is also recommended to install Gulp.js globally, so you can easier execute +the build commands from anywhere in the command line: npm install -g gulp @@ -235,7 +235,7 @@ folder in your web browser. There should be a green bar at the top, meaning all tests have passed. If the bar is red, some tests have not passed. These will be highlighted and become visible when scrolling down. -You can also run the unit tests through Gulp on the command line: +You can also run the unit tests through Gulp.js on the command line: gulp test diff --git a/gulpfile.js b/gulpfile.js index 47de9e7a..8e907916 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,14 +21,19 @@ var gulp = require('gulp'), whitespace = require('gulp-whitespace'), merge = require('merge-stream'), del = require('del'), - zip = require('gulp-zip'), + extend = require('extend'), + fs = require('fs'), gitty = require('gitty'), - fs = require('fs'); + zip = require('gulp-zip'); /** * Options */ +// Require the __options object before preprocessing, so we have access to the +// version number and can make amendments, e.g. the release date. +var options = require('./src/options.js'); + // Options to be used in Prepro.js preprocessing through the global __options // object. var buildOptions = { @@ -66,13 +71,12 @@ function git(param) { return new gitty.Command(gitRepo, operation, args).execSync().trim(); } -var gitDate = git('log -1 --pretty=format:%ad'); -var gitVersion = git('describe --abbrev=0 --tags'); -var gitBranch = git('rev-parse --abbrev-ref HEAD'); -if (gitBranch !== 'master') - gitVersion += '-' + gitBranch; - -gulp.task('nop'); +// Get the date of the last commit from this branch for release date: +options.date = git('log -1 --pretty=format:%ad'); +// If we're not on the master branch, append the branch name to the version: +var branch = git('rev-parse --abbrev-ref HEAD'); +if (branch !== 'master') + options.version += '-' + branch; /** * Task: default @@ -148,15 +152,17 @@ buildNames.forEach(function(name) { gulp.task('build:' + name, ['build:start'], function() { return gulp.src('src/paper.js') .pipe(prepro({ - evaluate: ['src/constants.js', 'src/options.js'], + // Evaluate constants.js inside the precompilation scope before + // the actual precompilation, so all the constants substitution + // statements in the code can work (look for: /*#=*/): + evaluate: ['src/constants.js'], setup: function() { - var options = buildOptions[name]; - options.version = gitVersion; - options.date = gitDate; - // 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 }; + // Return objects to be defined in the preprocess-scope. + // Note that this would be merge in with already existing + // objects. + return { + __options: extend({}, options, buildOptions[name]) + }; } })) .pipe(uncomment({ diff --git a/package.json b/package.json index 885936ab..cabdb5bc 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "devDependencies": { "del": "^2.2.0", + "extend": "^3.0.0", "gitty": "^3.3.3", "gulp": "^3.9.0", "gulp-prepro": "^2.0.0", diff --git a/src/load.js b/src/load.js index 8a0403ad..1973ced7 100644 --- a/src/load.js +++ b/src/load.js @@ -14,6 +14,11 @@ // the browser, avoiding the step of having to manually preprocess it after each // change. This is very useful during development of the library itself. if (typeof window === 'object') { + /* jshint -W082 */ + function load(src) { + document.write(''); + } + // Browser based loading through Prepro.js: if (!window.include) { var scripts = document.getElementsByTagName('script'); @@ -24,29 +29,29 @@ if (typeof window === 'object') { var root = src.match(/^(.*\/)\w*\//)[1]; // First load the prepro's browser.js file, which provides the include() // function for the browser. - document.write(''); - // Now that we have include(), load this file again, which will execute - // the lower part of the code the 2nd time around. - document.write(''); + load(root + 'node_modules/prepro/lib/browser.js'); + // Now that we will have window.include() through browser.js, trigger + // the loading of this file again, which will execute the lower part of + // the code the 2nd time around. + load(root + 'src/load.js'); } else { include('options.js'); include('paper.js'); } } else { - // Node based loading through Prepro.js: - var prepro = require('prepro/lib/node.js'); - // Include deafult browser options. - // 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. + // Node.js based loading through Prepro.js: + var prepro = require('prepro/lib/node.js'), + // Load the default browser-based options for further amendments. + // Step out and back into src, if this is loaded from dist/paper-node.js + options = require('../src/options.js'); + // Override Node.js specific options. + options.version += '-load'; + options.environment = 'node'; + options.load = true; 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: { environment: 'node' } - }; + // Return objects to be defined in the preprocess-scope. + // Note that this would be merge in with already existing objects. + return { __options: options }; }); // Load Paper.js library files. prepro.include('../src/paper.js'); diff --git a/src/options.js b/src/options.js index 47ee4f3a..0b2979e5 100644 --- a/src/options.js +++ b/src/options.js @@ -14,12 +14,24 @@ // browser based compile-time preprocessing when loading the separate source // files directly through load.js / Prepro.js during development. +// The paper.js version. +// NOTE: Adjust value here before calling publish.sh, which then updates and +// publishes the various JSON package files automatically. +var version = '0.9.25'; +// If this file is loaded in the browser, we're in load.js mode. +var load = typeof window === 'object'; + var __options = { - version: 'dev', + version: version + (load ? '-load' : ''), environment: 'browser', + load: load, parser: 'acorn', svg: true, booleanOperations: true, nativeContains: false, paperScript: true }; + +// Export for use in Gulp.js +if (typeof module !== 'undefined') + module.exports = __options; diff --git a/src/paper.js b/src/paper.js index d19d89e6..781a03e5 100644 --- a/src/paper.js +++ b/src/paper.js @@ -1,5 +1,5 @@ /*! - * Paper.js *#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting. + * Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting. * http://paperjs.org/ * * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey @@ -36,11 +36,11 @@ var paper = new function(undefined) { // Inline Straps.js core (the Base class) inside the paper scope first: /*#*/ include('../bower_components/straps/straps.js', { exports: false }); -/*#*/ if (__options.version == 'dev' && __options.environment == 'browser') { +/*#*/ if (__options.load && __options.environment == 'browser') { /*#*/ include('../bower_components/stats.js/build/stats.min.js'); /*#*/ } -/*#*/ if (__options.version == 'dev') { +/*#*/ if (__options.load) { /*#*/ include('constants.js'); /*#*/ } @@ -122,7 +122,7 @@ var paper = new function(undefined) { /*#*/ include('canvas/CanvasProvider.js'); /*#*/ include('canvas/BlendMode.js'); -/*#*/ if (__options.version == 'dev') { +/*#*/ if (__options.load) { /*#*/ include('canvas/ProxyContext.js'); /*#*/ }