html2canvas/Gruntfile.js

197 lines
6.8 KiB
JavaScript
Raw Normal View History

2012-11-25 22:59:31 +04:00
/*global module:false*/
var _ = require('lodash'), path = require('path');
var proxy = require('html2canvas-proxy');
2014-08-26 21:01:15 +04:00
2012-11-25 22:59:31 +04:00
module.exports = function(grunt) {
2014-01-19 20:04:27 +04:00
var meta = {
banner: '/*\n <%= pkg.title || pkg.name %> <%= pkg.version %>' +
'<%= pkg.homepage ? " <" + pkg.homepage + ">" : "" %>' + '\n' +
' Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' +
'\n\n Released under <%= _.pluck(pkg.licenses, "type").join(", ") %> License\n*/\n',
2014-10-15 21:28:26 +04:00
pre: '\n(function(window, document, module, exports, global, define, undefined){\n\n',
2014-09-29 20:15:50 +04:00
post: '\n}).call({}, window, document);'
2014-01-19 20:04:27 +04:00
};
2014-01-19 20:04:27 +04:00
// Project configuration.
grunt.initConfig({
2014-01-19 20:04:27 +04:00
pkg: grunt.file.readJSON('package.json'),
2014-01-19 20:04:27 +04:00
concat: {
dist: {
src: [
'src/promise.js', 'src/fallback.js', 'src/punycode/punycode.js', 'src/core.js', 'src/*.js', 'src/renderers/*.js'
2014-01-19 20:04:27 +04:00
],
nonull: true,
2014-09-04 21:50:31 +04:00
dest: 'dist/<%= pkg.name %>.js',
options:{
banner: meta.banner + meta.pre,
footer: meta.post
}
2014-01-19 20:04:27 +04:00
},
2014-09-04 21:50:31 +04:00
svg: {
src: [
'src/fabric/dist/fabric.js'
],
dest: 'dist/<%= pkg.name %>.svg.js',
options:{
banner: meta.banner + '\n(function(window, document, exports, undefined){\n\n',
footer: '\n}).call({}, window, document, html2canvas);'
2014-09-04 21:50:31 +04:00
}
2014-01-19 20:04:27 +04:00
}
},
2014-09-20 19:18:39 +04:00
connect: {
2014-01-19 20:04:27 +04:00
server: {
options: {
port: 8080,
2014-09-20 19:18:39 +04:00
base: './',
keepalive: true
2014-01-19 20:04:27 +04:00
}
2014-05-18 18:39:24 +04:00
},
2014-05-18 18:40:01 +04:00
cors: {
options: {
port: 8081,
2014-09-20 19:18:39 +04:00
base: './',
middleware: function(connect, options) {
return [
function(req, res, next) {
if (req.url !== '/tests/assets/image2.jpg') {
next();
return;
}
res.setHeader("Access-Control-Allow-Origin", "*");
res.end(require("fs").readFileSync('tests/assets/image2.jpg'));
}
2014-09-20 19:18:39 +04:00
];
}
}
},
proxy: {
options: {
port: 8082,
2014-09-20 19:18:39 +04:00
middleware: function(connect, options) {
return [
function(req, res, next) {
res.jsonp = function(content) {
res.end(req.query.callback + "(" + JSON.stringify(content) + ")");
};
next();
},
2014-09-20 19:18:39 +04:00
proxy()
];
}
2014-05-18 18:40:01 +04:00
}
},
2014-05-18 18:39:24 +04:00
ci: {
options: {
port: 8080,
2014-09-20 19:18:39 +04:00
base: './'
2014-05-18 18:39:24 +04:00
}
2014-01-19 20:04:27 +04:00
}
},
execute: {
fabric: {
options: {
args: ['modules=' + ['text','serialization',
'parser', 'gradient', 'pattern', 'shadow', 'freedrawing',
'image_filters', 'serialization'].join(","), 'no-es5-compat', 'dest=' + path.resolve(__dirname, 'src/fabric/dist/') + '/']
},
src: ['src/fabric/build.js']
}
},
2014-01-19 20:04:27 +04:00
uglify: {
dist: {
src: ['<%= concat.dist.dest %>'],
2014-09-01 21:22:56 +04:00
dest: 'dist/<%= pkg.name %>.min.js'
2014-01-19 20:04:27 +04:00
},
2014-09-04 21:50:31 +04:00
svg: {
src: ['<%= concat.svg.dest %>'],
dest: 'dist/<%= pkg.name %>.svg.min.js'
},
2014-01-19 20:04:27 +04:00
options: {
banner: meta.banner
}
},
watch: {
files: ['src/**/*', '!src/fabric/**/*'],
2014-01-26 20:10:04 +04:00
tasks: ['jshint', 'build']
2014-01-19 20:04:27 +04:00
},
jshint: {
2014-09-04 21:50:31 +04:00
all: ['src/*.js', 'src/renderers/*.js', '!src/promise.js'],
2014-01-19 20:04:27 +04:00
options: grunt.file.readJSON('./.jshintrc')
2014-08-26 21:01:15 +04:00
},
2014-10-15 21:28:26 +04:00
mocha_phantomjs: {
all: ['tests/mocha/**/*.html']
},
2014-08-26 21:01:15 +04:00
webdriver: {
chrome: {
browserName: "chrome",
platform: "Windows 7",
version: "34"
},
firefox: {
browserName: "firefox",
version: "15",
platform: "Windows 7"
},
ie9: {
browserName: "internet explorer",
version: "9",
platform: "Windows 7"
},
ie10: {
browserName: "internet explorer",
version: "10",
platform: "Windows 8"
},
ie11: {
browserName: "internet explorer",
version: "11",
platform: "Windows 8.1"
},
safari6: {
browserName: "safari",
version: "6",
platform: "OS X 10.8"
},
safari7:{
browserName: "safari",
platform: "OS X 10.9",
version: "7"
},
chromeOSX:{
browserName: "chrome",
platform: "OS X 10.8",
version: "34"
}
2014-01-19 20:04:27 +04:00
}
});
2012-11-25 22:59:31 +04:00
2014-08-26 22:03:54 +04:00
grunt.registerTask('webdriver', 'Browser render tests', function(browser, test) {
2014-01-19 20:04:27 +04:00
var selenium = require("./tests/selenium.js");
var done = this.async();
2014-08-26 22:03:54 +04:00
var browsers = (browser) ? [grunt.config.get(this.name + "." + browser)] : _.values(grunt.config.get(this.name));
2014-09-18 23:25:37 +04:00
selenium.tests(browsers, test).catch(function() {
done(false);
}).finally(function() {
2014-09-17 01:11:47 +04:00
console.log("Done");
done();
});
2014-01-19 20:04:27 +04:00
});
2012-12-29 17:02:05 +04:00
2014-10-15 21:28:26 +04:00
grunt.loadNpmTasks('grunt-mocha-phantomjs');
2014-01-19 20:04:27 +04:00
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
2014-09-20 19:18:39 +04:00
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-execute');
2013-03-22 06:40:09 +04:00
2014-09-20 19:18:39 +04:00
grunt.registerTask('server', ['connect:cors', 'connect:proxy', 'connect:server']);
grunt.registerTask('build', ['execute', 'concat', 'uglify']);
2014-10-15 21:28:26 +04:00
grunt.registerTask('default', ['jshint', 'build', 'mocha_phantomjs']);
grunt.registerTask('travis', ['jshint', 'build','mocha_phantomjs', 'connect:ci', 'connect:proxy', 'connect:cors', 'webdriver']);
2012-11-25 22:59:31 +04:00
};