2015-05-04 17:02:16 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-07 16:03:08 +08:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var rename = require('gulp-rename');
|
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
var concat = require('gulp-concat');
|
|
|
|
var replace = require('gulp-replace');
|
|
|
|
var mochaPhantomJS = require('gulp-mocha-phantomjs');
|
|
|
|
var jsdoc = require('gulp-jsdoc');
|
|
|
|
var connect = require('gulp-connect');
|
2015-05-04 17:02:16 +08:00
|
|
|
var jscpd = require('gulp-jscpd');
|
|
|
|
var eslint = require('gulp-eslint');
|
2015-04-07 16:03:08 +08:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var NodeParams = fs.readFileSync('./resources/doc-includes/NodeParams.txt').toString();
|
|
|
|
var ContainerParams = fs.readFileSync('./resources/doc-includes/ContainerParams.txt').toString();
|
|
|
|
var ShapeParams = fs.readFileSync('./resources/doc-includes/ShapeParams.txt').toString();
|
|
|
|
|
|
|
|
var conf = require('./package.json');
|
|
|
|
|
|
|
|
var sourceFiles = [
|
|
|
|
// core
|
|
|
|
'src/Global.js',
|
|
|
|
'src/Util.js',
|
|
|
|
'src/Canvas.js',
|
|
|
|
'src/Context.js',
|
|
|
|
'src/Factory.js',
|
|
|
|
'src/Node.js',
|
|
|
|
|
|
|
|
// filters
|
|
|
|
'src/filters/Grayscale.js',
|
|
|
|
'src/filters/Brighten.js',
|
|
|
|
'src/filters/Invert.js',
|
|
|
|
'src/filters/Blur.js',
|
|
|
|
'src/filters/Mask.js',
|
|
|
|
'src/filters/RGB.js',
|
2015-06-09 17:25:41 +08:00
|
|
|
'src/filters/RGBA.js',
|
2015-04-07 16:03:08 +08:00
|
|
|
'src/filters/HSV.js',
|
|
|
|
'src/filters/HSL.js',
|
|
|
|
'src/filters/Emboss.js',
|
|
|
|
'src/filters/Enhance.js',
|
|
|
|
'src/filters/Posterize.js',
|
|
|
|
'src/filters/Noise.js',
|
|
|
|
'src/filters/Pixelate.js',
|
|
|
|
'src/filters/Threshold.js',
|
|
|
|
'src/filters/Sepia.js',
|
|
|
|
'src/filters/Solarize.js',
|
|
|
|
'src/filters/Kaleidoscope.js',
|
|
|
|
|
|
|
|
// core
|
|
|
|
'src/Container.js',
|
|
|
|
'src/Shape.js',
|
|
|
|
'src/Stage.js',
|
|
|
|
'src/BaseLayer.js',
|
|
|
|
'src/Layer.js',
|
|
|
|
'src/FastLayer.js',
|
|
|
|
'src/Group.js',
|
2015-04-08 23:26:43 +08:00
|
|
|
'src/Animation.js',
|
|
|
|
'src/Tween.js',
|
|
|
|
'src/DragAndDrop.js',
|
2015-04-07 16:03:08 +08:00
|
|
|
|
|
|
|
// shapes
|
|
|
|
'src/shapes/Rect.js',
|
|
|
|
'src/shapes/Circle.js',
|
|
|
|
'src/shapes/Ellipse.js',
|
|
|
|
'src/shapes/Ring.js',
|
|
|
|
'src/shapes/Wedge.js',
|
|
|
|
'src/shapes/Arc.js',
|
|
|
|
'src/shapes/Image.js',
|
|
|
|
'src/shapes/Text.js',
|
|
|
|
'src/shapes/Line.js',
|
|
|
|
'src/shapes/Sprite.js',
|
2016-05-06 15:10:50 +08:00
|
|
|
'src/shapes/Path.js',
|
|
|
|
'src/shapes/TextPath.js',
|
|
|
|
'src/shapes/RegularPolygon.js',
|
|
|
|
'src/shapes/Star.js',
|
|
|
|
'src/shapes/Label.js',
|
|
|
|
'src/shapes/Arrow.js'
|
2015-04-07 16:03:08 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
function build() {
|
|
|
|
return gulp.src(sourceFiles)
|
|
|
|
.pipe(concat('konva-dev.js'))
|
|
|
|
.pipe(replace('@@shapeParams', ShapeParams))
|
|
|
|
.pipe(replace('@@nodeParams', NodeParams))
|
|
|
|
.pipe(replace('@@containerParams', ContainerParams))
|
|
|
|
.pipe(replace('@@version', conf.version))
|
|
|
|
.pipe(replace('@@date', new Date().toDateString()));
|
|
|
|
}
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
|
|
|
|
// create development build
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('dev-build', function() {
|
2015-04-07 16:23:59 +08:00
|
|
|
return build()
|
2015-04-07 16:03:08 +08:00
|
|
|
.pipe(gulp.dest('./dist/'));
|
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
|
|
|
|
// create usual build konva.js and konva.min.js
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('build', function() {
|
|
|
|
return build()
|
|
|
|
.pipe(rename('konva.js'))
|
|
|
|
.pipe(gulp.dest('./'))
|
|
|
|
.pipe(uglify({
|
2015-05-04 17:02:16 +08:00
|
|
|
preserveComments: 'some'
|
2015-04-07 16:03:08 +08:00
|
|
|
}))
|
|
|
|
.pipe(rename('konva.min.js'))
|
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
// tun tests
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('test', ['dev-build'], function () {
|
|
|
|
return gulp
|
|
|
|
.src('test/runner.html')
|
|
|
|
.pipe(mochaPhantomJS());
|
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
// local server for better development
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('server', function() {
|
|
|
|
connect.server();
|
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
// lint files
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('lint', function() {
|
|
|
|
return gulp.src('./src/**/*.js')
|
2015-05-04 17:02:16 +08:00
|
|
|
.pipe(eslint({
|
|
|
|
configFile: './.eslintrc'
|
|
|
|
}))
|
|
|
|
// eslint.format() outputs the lint results to the console.
|
|
|
|
// Alternatively use eslint.formatEach() (see Docs).
|
|
|
|
.pipe(eslint.format())
|
|
|
|
// To have the process exit with an error code (1) on
|
|
|
|
// lint error, return the stream and pipe to failOnError last.
|
|
|
|
.pipe(eslint.failOnError());
|
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
// check code for duplication
|
2015-05-04 17:02:16 +08:00
|
|
|
gulp.task('inspect', function() {
|
|
|
|
return gulp.src('./src/**/*.js')
|
|
|
|
.pipe(jscpd({
|
|
|
|
'min-lines': 10,
|
|
|
|
verbose: true
|
|
|
|
}));
|
2015-04-07 16:03:08 +08:00
|
|
|
});
|
|
|
|
|
2015-05-04 17:14:11 +08:00
|
|
|
|
|
|
|
// generate documentation
|
2015-04-07 16:03:08 +08:00
|
|
|
gulp.task('api', function() {
|
|
|
|
return gulp.src('./src/**/*.js')
|
|
|
|
.pipe(jsdoc('./api'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
2015-06-02 09:14:54 +08:00
|
|
|
gulp.watch(['src/**/*.js'], ['dev-build']);
|
2015-04-07 16:03:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-05-04 17:02:16 +08:00
|
|
|
gulp.task('default', ['dev-build', 'watch', 'server']);
|