2014-03-11 14:54:36 +00:00
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
|
|
|
require('load-grunt-tasks')(grunt);
|
|
|
|
|
2014-04-03 09:39:11 +00:00
|
|
|
/* 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',
|
2014-03-13 10:21:03 +00:00
|
|
|
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: {
|
2014-04-04 16:48:37 +00:00
|
|
|
configFile: '<%= config.tests %>/config/karma.unit.js',
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
|
|
|
single: {
|
|
|
|
singleRun: true,
|
|
|
|
autoWatch: false,
|
|
|
|
|
2014-04-03 09:39:11 +00:00
|
|
|
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: {
|
2014-04-04 16:48:37 +00:00
|
|
|
browsers: TEST_BROWSERS,
|
|
|
|
transform: [ 'brfs' ]
|
2014-03-11 14:54:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
browserify: {
|
|
|
|
options: {
|
2014-04-04 16:48:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}],
|
2014-03-31 13:54:45 +00:00
|
|
|
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: {
|
2014-03-31 13:54:45 +00:00
|
|
|
'<%= 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: [
|
2014-04-04 16:48:37 +00:00
|
|
|
'node_modules/jquery:jquery',
|
2014-03-31 13:54:45 +00:00
|
|
|
'node_modules/lodash:lodash',
|
2014-04-03 17:26:00 +00:00
|
|
|
'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: [
|
2014-04-04 16:48:37 +00:00
|
|
|
'node_modules/jquery:jquery',
|
2014-03-31 13:54:45 +00:00
|
|
|
'node_modules/lodash:lodash',
|
2014-04-03 17:26:00 +00:00
|
|
|
'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
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-03-11 15:24:31 +00:00
|
|
|
copy: {
|
|
|
|
samples: {
|
|
|
|
files: [
|
|
|
|
// copy sample files
|
|
|
|
{
|
|
|
|
expand: true,
|
|
|
|
cwd: '<%= config.samples %>/',
|
2014-03-26 16:45:04 +00:00
|
|
|
src: ['**/*.*'],
|
2014-03-11 15:24:31 +00:00
|
|
|
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' ],
|
2014-04-04 16:48:37 +00:00
|
|
|
tasks: [ 'build:lib' ]
|
2014-03-13 10:21:03 +00:00
|
|
|
},
|
|
|
|
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: {
|
2014-03-13 10:21:03 +00:00
|
|
|
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: {
|
2014-03-17 14:11:15 +00:00
|
|
|
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-13 10:21:03 +00:00
|
|
|
}
|
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-13 10:21:03 +00:00
|
|
|
|
2014-03-12 09:59:06 +00:00
|
|
|
grunt.registerTask('auto-build', [
|
2014-04-04 16:48:37 +00:00
|
|
|
'build:all',
|
2014-03-12 09:59:06 +00:00
|
|
|
'connect:livereload',
|
|
|
|
'watch'
|
|
|
|
]);
|
2014-03-11 14:54:36 +00:00
|
|
|
|
2014-04-08 11:41:03 +00:00
|
|
|
grunt.registerTask('auto-test', [ 'karma:unit' ]);
|
2014-03-11 14:54:36 +00:00
|
|
|
|
|
|
|
grunt.registerTask('default', [ 'jshint', 'test', 'build', 'jsdoc' ]);
|
|
|
|
};
|