bpmn-js/Gruntfile.js

252 lines
6.1 KiB
JavaScript
Raw Normal View History

2014-03-11 14:54:36 +00:00
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
/* global Buffer,process*/
// configures browsers to run test against
// any of [ 'PhantomJS', 'Chrome', 'Firefox', 'IE']
var TEST_BROWSERS = ((process.env.TEST_BROWSERS || '').replace(/^\s+|\s+$/, '') || 'PhantomJS').split(/\s*,\s*/g);
2014-03-11 14:54:36 +00:00
// project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: {
sources: 'lib',
tests: 'test',
dist: 'dist',
samples: 'example'
},
jshint: {
src: [
['<%=config.sources %>']
],
gruntfile: [
'Gruntfile.js'
],
options: {
jshintrc: true
}
},
jasmine_node: {
specNameMatcher: '.*Spec',
projectRoot: 'test/spec/node',
2014-03-11 14:54:36 +00:00
jUnit: {
report: true,
savePath : 'tmp/reports/jasmine',
useDotNotation: true,
consolidate: true
}
},
karma: {
options: {
configFile: '<%= config.tests %>/config/karma.unit.js',
2014-03-11 14:54:36 +00:00
},
single: {
singleRun: true,
autoWatch: false,
browsers: TEST_BROWSERS,
2014-03-11 14:54:36 +00:00
browserify: {
watch: false,
2014-03-14 16:52:30 +00:00
debug: false,
transform: [ 'brfs' ]
2014-03-11 14:54:36 +00:00
}
},
unit: {
browsers: TEST_BROWSERS,
transform: [ 'brfs' ]
2014-03-11 14:54:36 +00:00
}
},
browserify: {
options: {
transform: [ 'brfs', function() {
// remove require('fs') from source code as it is
// optimized away (i.e. inlined) by brfs transform
var through = require('through');
var data = '';
return through(write, end);
function write (buf) { data += buf; }
function end () {
this.queue(data.replace(/require\('fs'\)/, '{}'));
this.queue(null);
}
}],
browserifyOptions: {
builtins: false,
commondir: false
},
bundleOptions: {
detectGlobals: false,
ignoreMissing: true,
insertGlobalVars: [],
debug: true
}
2014-03-11 14:54:36 +00:00
},
2014-03-25 13:06:52 +00:00
modeler: {
2014-03-11 14:54:36 +00:00
files: {
'<%= config.dist %>/bpmn.js': [ 'shim/*.js', '<%= config.sources %>/**/*.js' ]
2014-03-11 14:54:36 +00:00
},
options: {
2014-03-25 13:06:52 +00:00
alias: [
'node_modules/jquery:jquery',
'node_modules/lodash:lodash',
'node_modules/bpmn-moddle:bpmn/Model',
2014-03-25 13:06:52 +00:00
'<%= config.sources %>/main.js:bpmn',
'<%= config.sources %>/Viewer.js:bpmn/Viewer',
'<%= config.sources %>/Modeler.js:bpmn/Modeler'
2014-03-31 13:53:31 +00:00
]
2014-03-11 14:54:36 +00:00
}
},
2014-03-25 13:06:52 +00:00
viewer: {
2014-03-11 14:54:36 +00:00
files: {
2014-03-25 13:06:52 +00:00
'<%= config.dist %>/bpmn-viewer.js': [ '<%= config.sources %>/lib/Viewer.js' ]
2014-03-11 14:54:36 +00:00
},
options: {
2014-03-25 13:06:52 +00:00
alias: [
'node_modules/jquery:jquery',
'node_modules/lodash:lodash',
'node_modules/bpmn-moddle:bpmn/Model',
2014-03-25 13:06:52 +00:00
'<%= config.sources %>/main.js:bpmn',
'<%= config.sources %>/Viewer.js:bpmn/Viewer'
]
2014-03-11 14:54:36 +00:00
}
}
},
copy: {
samples: {
files: [
// copy sample files
{
expand: true,
cwd: '<%= config.samples %>/',
src: ['**/*.*'],
dest: '<%= config.dist %>/<%= config.samples %>'
}
]
}
},
2014-03-11 14:54:36 +00:00
watch: {
sources: {
2014-03-25 13:06:52 +00:00
files: [ '<%= config.sources %>/**/*.js' ],
tasks: [ 'build:lib' ]
},
samples: {
files: [ '<%= config.samples %>/**/*.*' ],
2014-03-25 13:06:52 +00:00
tasks: [ 'build:samples' ]
2014-03-11 14:54:36 +00:00
},
jasmine_node: {
files: [ '<%= config.sources %>/**/*.js', '<%= config.tests %>/spec/node/**/*.js' ],
tasks: [ 'jasmine_node' ]
2014-03-11 14:54:36 +00:00
}
},
jsdoc: {
dist: {
src: [ '<%= config.sources %>/**/*.js' ],
options: {
destination: 'docs/api',
2014-03-11 14:54:36 +00:00
plugins: [ 'plugins/markdown' ]
}
}
},
concurrent: {
2014-03-25 13:06:52 +00:00
'lib': [ 'build:lib', 'jshint' ],
2014-03-11 14:54:36 +00:00
'build': [ 'jshint', 'build', 'jsdoc' ]
2014-03-12 09:59:06 +00:00
},
connect: {
options: {
port: 9003,
livereload: 35726,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
base: [
'<%= config.dist %>'
]
}
}
2014-03-31 13:53:31 +00:00
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> - ' +
'https://github.com/bpmn-io/bpmn-js */',
sourceMap: true,
sourceMapIncludeSources: true,
sourceMapIn: function(file) {
var content = grunt.file.read(file, { encoding: 'utf-8' });
var match = /\/\/# sourceMappingURL=data:application\/json;base64,(.*)/.exec(content);
if (match) {
var b = new Buffer(match[1] + '==', 'base64');
var s = b.toString();
grunt.file.write('tmp/sourceMap.json', s, { encoding: 'utf-8' });
return 'tmp/sourceMap.json';
} else {
return null;
}
}
},
modeler: {
files: {
'<%= config.dist %>/bpmn.min.js': [ '<%= config.dist %>/bpmn.js' ]
}
},
viewer: {
files: {
'<%= config.dist %>/bpmn-viewer.min.js': [ '<%= config.dist %>/bpmn-viewer.js' ]
}
}
}
2014-03-11 14:54:36 +00:00
});
// tasks
grunt.registerTask('test', [ 'jasmine_node', 'karma:single' ]);
2014-03-25 13:06:52 +00:00
grunt.registerTask('build', function(target, mode) {
2014-03-31 13:53:31 +00:00
mode = mode || 'prod';
2014-03-25 13:06:52 +00:00
if (target === 'lib') {
2014-03-31 13:53:31 +00:00
var tasks = [];
if (mode !== 'dev') {
tasks.push('uglify:modeler', 'uglify:viewer');
}
return grunt.task.run([ 'browserify:modeler', 'browserify:viewer' ].concat(tasks));
2014-03-25 13:06:52 +00:00
}
if (target === 'samples') {
return grunt.task.run(['copy:samples']);
}
if (!target || target === 'all') {
2014-03-31 13:53:31 +00:00
return grunt.task.run([ 'build:lib:' + mode, 'build:samples:' + mode ]);
2014-03-25 13:06:52 +00:00
}
});
2014-03-12 09:59:06 +00:00
grunt.registerTask('auto-build', [
'build:all',
2014-03-12 09:59:06 +00:00
'connect:livereload',
'watch'
]);
2014-03-11 14:54:36 +00:00
grunt.registerTask('auto-test', [ 'karma:unit' ]);
2014-03-11 14:54:36 +00:00
grunt.registerTask('default', [ 'jshint', 'test', 'build', 'jsdoc' ]);
};