html2canvas/Gruntfile.js

221 lines
7.2 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 %>' +
2015-02-03 22:34:05 +03:00
'\n\n Released under <%= _.pluck(pkg.licenses, "type").join(", ") %> License\n*/\n'
2014-01-19 20:04:27 +04:00
};
var browsers = {
chrome: {
browserName: "chrome",
platform: "Windows 7",
version: "39"
},
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: "39"
}
};
2014-01-19 20:04:27 +04:00
grunt.initConfig({
2014-01-19 20:04:27 +04:00
pkg: grunt.file.readJSON('package.json'),
2015-02-03 22:34:05 +03:00
browserify: {
2014-01-19 20:04:27 +04:00
dist: {
2015-02-03 22:34:05 +03:00
src: ['src/core.js'],
2014-09-04 21:50:31 +04:00
dest: 'dist/<%= pkg.name %>.js',
2015-02-03 22:34:05 +03:00
options: {
browserifyOptions: {
standalone: 'html2canvas'
},
banner: meta.banner
2014-09-04 21:50:31 +04:00
}
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:{
2015-02-03 22:34:05 +03:00
browserifyOptions: {
standalone: 'html2canvas.svg'
},
banner: meta.banner
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
},
2015-01-18 22:38:05 +03:00
altServer: {
options: {
port: 8083,
base: './'
}
},
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: {
2015-02-03 22:34:05 +03:00
src: ['<%= browserify.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: {
2015-02-03 22:34:05 +03:00
src: ['<%= browserify.svg.dest %>'],
2014-09-04 21:50:31 +04:00
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: {
2015-02-03 22:34:05 +03:00
all: ['src/*.js', 'src/renderers/*.js'],
2014-01-19 20:04:27 +04:00
options: grunt.file.readJSON('./.jshintrc')
2014-08-26 21:01:15 +04:00
},
2015-01-20 00:33:29 +03:00
mochacli: {
options: {
reporter: 'spec'
},
all: ['tests/node/*.js']
},
2014-10-15 21:28:26 +04:00
mocha_phantomjs: {
all: ['tests/mocha/**/*.html']
},
mocha_webdriver: browsers,
webdriver: browsers
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
grunt.registerTask('mocha_webdriver', 'Browser mocha tests', function(browser, test) {
var selenium = require("./tests/mocha/selenium.js");
var done = this.async();
var browsers = (browser) ? [grunt.config.get(this.name + "." + browser)] : _.values(grunt.config.get(this.name));
selenium.tests(browsers, test).catch(function() {
done(false);
}).finally(function() {
done();
});
});
2015-02-03 22:34:05 +03:00
grunt.loadNpmTasks('grunt-browserify');
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-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
2014-09-20 19:18:39 +04:00
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-execute');
2015-01-20 00:33:29 +03:00
grunt.loadNpmTasks('grunt-mocha-cli');
2013-03-22 06:40:09 +04:00
2015-01-18 22:38:05 +03:00
grunt.registerTask('server', ['connect:cors', 'connect:proxy', 'connect:altServer', 'connect:server']);
2015-02-03 22:34:05 +03:00
grunt.registerTask('build', ['execute', 'browserify', 'uglify']);
2015-01-20 00:33:29 +03:00
grunt.registerTask('default', ['jshint', 'build', 'mochacli', 'connect:altServer', 'mocha_phantomjs']);
2015-01-18 22:38:05 +03:00
grunt.registerTask('travis', ['jshint', 'build', 'connect:altServer', 'connect:ci', 'connect:proxy', 'connect:cors', 'mocha_phantomjs', 'webdriver']);
2012-11-25 22:59:31 +04:00
};