Split gulpfile.js into separate task files.

This commit is contained in:
Jürg Lehni 2016-01-23 18:26:56 +01:00
parent 145135b4f5
commit eda738d4fa
12 changed files with 320 additions and 226 deletions

66
gulp/tasks/build.js Normal file
View file

@ -0,0 +1,66 @@
/*
* 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.
*/
var gulp = require('gulp'),
prepro = require('gulp-prepro'),
rename = require('gulp-rename'),
uncomment = require('gulp-uncomment'),
whitespace = require('gulp-whitespace'),
extend = require('extend'),
options = require('../utils/options.js');
// Options to be used in Prepro.js preprocessing through the global __options
// object, merged in with the options required above.
var buildOptions = {
full: { paperScript: true },
core: { paperScript: false },
node: { environment: 'node', paperScript: true }
};
var buildNames = Object.keys(buildOptions);
gulp.task('build',
buildNames.map(function(name) {
return 'build:' + name;
})
);
buildNames.forEach(function(name) {
gulp.task('build:' + name, ['clean:build', 'minify:acorn'], function() {
return gulp.src('src/paper.js')
.pipe(prepro({
// 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() {
// 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({
mergeEmptyLines: true
}))
.pipe(whitespace({
spacesToTabs: 4,
removeTrailing: true
}))
.pipe(rename({
suffix: '-' + name
}))
.pipe(gulp.dest('dist'));
});
});

34
gulp/tasks/clean.js Normal file
View file

@ -0,0 +1,34 @@
/*
* 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.
*/
var gulp = require('gulp'),
del = require('del');
gulp.task('clean:build', function() {
return del([
'dist/paper-*.js'
]);
});
gulp.task('clean:docs', function(callback) {
return del([
'dist/docs/**',
'dist/serverdocs/**'
]);
});
gulp.task('clean:load', function() {
return del([
'dist/paper-full.js',
'dist/paper-node.js'
]);
});

31
gulp/tasks/dist.js Normal file
View file

@ -0,0 +1,31 @@
/*
* 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.
*/
var gulp = require('gulp'),
merge = require('merge-stream'),
zip = require('gulp-zip');
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'));
});

31
gulp/tasks/docs.js Normal file
View file

@ -0,0 +1,31 @@
/*
* 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.
*/
var gulp = require('gulp'),
del = require('del'),
shell = require('gulp-shell');
var docOptions = {
local: 'docs', // Generates the offline docs
server: 'serverdocs' // Generates the website templates for the online docs
};
Object.keys(docOptions).forEach(function(name) {
gulp.task('docs:' + name, ['clean:docs'], 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']);

21
gulp/tasks/load.js Normal file
View file

@ -0,0 +1,21 @@
/*
* 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.
*/
var gulp = require('gulp'),
del = require('del'),
symlink = require('gulp-symlink');
gulp.task('load', ['clean:load'], function() {
return gulp.src('src/load.js')
.pipe(symlink('dist/paper-full.js'))
.pipe(symlink('dist/paper-node.js'));
});

51
gulp/tasks/minify.js Normal file
View file

@ -0,0 +1,51 @@
/*
* 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.
*/
var gulp = require('gulp'),
rename = require('gulp-rename'),
fs = require('fs'),
uglify = require('gulp-uglify');
var acornPath = 'bower_components/acorn/';
var uglifyOptions = {
output: {
ascii_only: true,
comments: /^!/
}
};
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('minify:acorn', function() {
// Only compress acorn if the compressed file doesn't exist yet.
try {
fs.accessSync(acornPath + 'acorn.min.js');
} catch(e) {
return gulp.src(acornPath + 'acorn.js')
.pipe(uglify(uglifyOptions))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(acornPath));
}
});

19
gulp/tasks/test.js Normal file
View file

@ -0,0 +1,19 @@
/*
* 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.
*/
var gulp = require('gulp'),
qunit = require('gulp-qunit');
gulp.task('test', function() {
return gulp.src('test/index.html')
.pipe(qunit({ timeout: 20, noGlobals: true }));
});