2014-03-11 14:54:36 +00:00
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
|
|
|
require('load-grunt-tasks')(grunt);
|
2014-04-28 13:30:22 +00:00
|
|
|
require('time-grunt')(grunt);
|
2014-03-11 14:54:36 +00:00
|
|
|
|
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: {
|
2014-04-09 13:07:35 +00:00
|
|
|
options: {
|
|
|
|
specNameMatcher: '.*Spec',
|
|
|
|
jUnit: {
|
|
|
|
report: true,
|
|
|
|
savePath : 'tmp/reports/jasmine',
|
|
|
|
useDotNotation: true,
|
|
|
|
consolidate: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
node: [ 'test/spec/node/' ]
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
|
|
|
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: {
|
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-25 11:28:40 +00:00
|
|
|
transform: [ 'brfs' ],
|
2014-03-31 13:54:45 +00:00
|
|
|
browserifyOptions: {
|
2014-04-25 11:28:40 +00:00
|
|
|
builtins: [ 'fs' ],
|
2014-03-31 13:54:45 +00:00
|
|
|
commondir: false
|
|
|
|
},
|
|
|
|
bundleOptions: {
|
|
|
|
detectGlobals: false,
|
|
|
|
insertGlobalVars: [],
|
|
|
|
debug: true
|
|
|
|
}
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
2014-04-28 13:30:22 +00:00
|
|
|
watch: {
|
|
|
|
options: {
|
|
|
|
alias: [
|
|
|
|
'node_modules/jquery:jquery',
|
|
|
|
'node_modules/lodash:lodash',
|
|
|
|
'node_modules/bpmn-moddle:bpmn/Model',
|
|
|
|
'<%= config.sources %>/main.js:bpmn',
|
|
|
|
'<%= config.sources %>/Viewer.js:bpmn/Viewer',
|
|
|
|
'<%= config.sources %>/Modeler.js:bpmn/Modeler'
|
|
|
|
],
|
|
|
|
watch: true,
|
|
|
|
keepalive: true
|
|
|
|
},
|
|
|
|
files: {
|
|
|
|
'<%= config.dist %>/bpmn.js': [ '<%= config.sources %>/**/*.js' ],
|
|
|
|
'<%= config.dist %>/bpmn-viewer.js': [ '<%= config.sources %>/lib/Viewer.js' ]
|
|
|
|
}
|
|
|
|
},
|
2014-03-25 13:06:52 +00:00
|
|
|
modeler: {
|
2014-03-11 14:54:36 +00:00
|
|
|
files: {
|
2014-04-28 13:30:22 +00:00
|
|
|
'<%= config.dist %>/bpmn.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: {
|
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-05-06 07:59:21 +00:00
|
|
|
},
|
|
|
|
modeler: {
|
|
|
|
files: [ '<%= config.dist %>/bpmn.js' ],
|
|
|
|
tasks: [ 'uglify:modeler' ]
|
|
|
|
},
|
|
|
|
viewer: {
|
|
|
|
files: [ '<%= config.dist %>/bpmn-viewer.js' ],
|
|
|
|
tasks: [ 'uglify:viewer' ]
|
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") %> - ' +
|
2014-05-06 12:32:54 +00:00
|
|
|
'http://bpmn.io/license - ' +
|
2014-03-31 13:53:31 +00:00
|
|
|
'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
|
2014-04-25 11:28:40 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
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-28 13:30:22 +00:00
|
|
|
'browserify:watch',
|
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' ]);
|
|
|
|
};
|