bpmn-js/Gruntfile.js

289 lines
7.0 KiB
JavaScript
Raw Normal View History

2014-03-11 14:54:36 +00:00
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
2014-03-11 14:54:36 +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);
function bundleAlias(components) {
var alias = [];
if (components.indexOf('libs-external') >= 0) {
alias.push('node_modules/jquery:jquery');
alias.push('node_modules/lodash:lodash');
}
if (components.indexOf('libs-local') >= 0) {
alias.push('node_modules/bpmn-moddle:bpmn-moddle');
}
if (components.indexOf('viewer') >= 0) {
alias.push('index.js:bpmn-js');
}
if (components.indexOf('modeler') >= 0) {
alias.push('<%= config.sources %>/Modeler.js:bpmn-js/Modeler');
}
return alias;
}
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',
2014-06-14 11:09:05 +00:00
bowerDist: '../bower-bpmn-js'
2014-03-11 14:54:36 +00:00
},
jshint: {
src: [
['<%=config.sources %>']
],
gruntfile: [
'Gruntfile.js'
],
options: {
jshintrc: true
}
},
release: {
options: {
tagName: 'v<%= version %>',
commitMessage: 'chore(project): release v<%= version %>',
tagMessage: 'chore(project): tag v<%= version %>'
}
},
2014-03-11 14:54:36 +00:00
jasmine_node: {
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
},
2014-03-11 14:54:36 +00:00
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
},
unit: {
browsers: TEST_BROWSERS
2014-03-11 14:54:36 +00:00
}
},
2014-03-11 14:54:36 +00:00
browserify: {
options: {
browserifyOptions: {
builtins: false
},
bundleOptions: {
detectGlobals: false,
insertGlobalVars: [],
debug: true
}
2014-03-11 14:54:36 +00:00
},
watch: {
files: {
'<%= config.dist %>/bpmn.js': [ '<%= config.sources %>/**/*.js' ],
'<%= config.dist %>/bpmn-viewer.js': [ '<%= config.sources %>/Viewer.js' ]
2014-03-11 14:54:36 +00:00
},
options: {
watch: true,
alias: bundleAlias([
'viewer',
'modeler',
'libs-external',
'libs-local'
])
2014-03-11 14:54:36 +00:00
}
},
bowerViewer: {
files: {
'<%= config.bowerDist %>/bpmn-viewer.js': [ '<%= config.sources %>/Viewer.js' ]
},
options: {
browserifyOptions: {
builtins: false
},
bundleOptions: {
standalone: 'BpmnJS',
detectGlobals: false,
insertGlobalVars: [],
debug: false
},
transform: [
[ 'exposify', {
expose: {
sax: 'sax',
snapsvg: 'Snap',
lodash: '_',
jquery: '$',
'jquery-mousewheel': '$'
}
} ]
]
}
},
standaloneViewer: {
2014-03-11 14:54:36 +00:00
files: {
'<%= config.dist %>/bpmn-viewer.js': [ '<%= config.sources %>/Viewer.js' ]
},
options: {
alias: bundleAlias([
'viewer',
'libs-external',
'libs-local'
])
}
},
standaloneModeler: {
files: {
'<%= config.dist %>/bpmn.js': [ '<%= config.sources %>/**/*.js' ],
},
options: {
alias: bundleAlias([
'viewer',
'modeler',
'libs-external',
'libs-local'
])
2014-03-11 14:54:36 +00:00
}
}
},
2014-03-11 14:54:36 +00:00
watch: {
2014-06-14 11:09:05 +00:00
standaloneModeler: {
files: [ '<%= config.dist %>/bpmn.js' ],
2014-06-14 11:09:05 +00:00
tasks: [ 'uglify:standaloneModeler' ]
},
2014-06-14 11:09:05 +00:00
standaloneViewer: {
files: [ '<%= config.dist %>/bpmn-viewer.js' ],
2014-06-14 11:09:05 +00:00
tasks: [ 'uglify:standaloneViewer' ]
},
bowerViewer: {
files: [ '<%= config.bowerDist %>/bpmn-viewer.js' ],
tasks: [ 'uglify:bowerViewer' ]
2014-03-11 14:54:36 +00:00
}
},
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' ]
}
}
},
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;
}
}
},
2014-06-14 11:09:05 +00:00
bowerViewer: {
files: {
'<%= config.bowerDist %>/bpmn-viewer.min.js': [ '<%= config.bowerDist %>/bpmn-viewer.js' ]
}
},
standaloneModeler: {
2014-03-31 13:53:31 +00:00
files: {
'<%= config.dist %>/bpmn.min.js': [ '<%= config.dist %>/bpmn.js' ]
}
},
2014-06-14 11:09:05 +00:00
standaloneViewer: {
2014-03-31 13:53:31 +00:00
files: {
'<%= config.dist %>/bpmn-viewer.min.js': [ '<%= config.dist %>/bpmn-viewer.js' ]
}
}
}
2014-03-11 14:54:36 +00:00
});
// tasks
2014-03-11 14:54:36 +00:00
grunt.registerTask('test', [ 'jasmine_node', 'karma:single' ]);
2014-03-25 13:06:52 +00:00
2014-06-14 11:09:05 +00:00
/////
//
// the main build task that bundles bpmn-js files
//
// valid executions are
//
// * build -> build:all
// * build:all -> build:lib, build:bower
// * build:lib -> { packages library files as standalone bundle }
// * build:lib -> { packages library files as bower bundle }
//
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
2014-06-14 11:09:05 +00:00
if (target === 'bower') {
return grunt.task.run(['browserify:bowerViewer', 'uglify:bowerViewer']);
}
2014-03-25 13:06:52 +00:00
if (target === 'lib') {
2014-03-31 13:53:31 +00:00
var tasks = [];
if (mode !== 'dev') {
2014-06-14 11:09:05 +00:00
tasks.push('uglify:standaloneModeler', 'uglify:standaloneViewer');
2014-03-31 13:53:31 +00:00
}
return grunt.task.run(['browserify:standaloneViewer', 'browserify:standaloneModeler'].concat(tasks));
2014-03-25 13:06:52 +00:00
}
if (!target || target === 'all') {
2014-06-14 11:09:05 +00:00
return grunt.task.run(['build:lib:' + mode, 'build:bower' ]);
2014-03-25 13:06:52 +00:00
}
});
2014-03-12 09:59:06 +00:00
grunt.registerTask('auto-build', [
'browserify:watch',
2014-03-12 09:59:06 +00:00
'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' ]);
};