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-08-06 07:30:02 +00:00
|
|
|
|
|
|
|
function extractSourceMap(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();
|
|
|
|
|
|
|
|
s = s.replace(/\\\\/g, '/'); // convert \\ -> /
|
|
|
|
|
|
|
|
var dir = __dirname;
|
|
|
|
|
|
|
|
var dirPattern = dir.replace(/\\/g, '/').replace(/\./g, '\\.') + '/';
|
|
|
|
|
|
|
|
var pattern = new RegExp(dirPattern, 'g');
|
|
|
|
|
|
|
|
s = s.replace(pattern, '');
|
|
|
|
|
|
|
|
grunt.file.write('tmp/sourceMap.json', s, { encoding: 'utf-8' });
|
|
|
|
|
|
|
|
return 'tmp/sourceMap.json';
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 %>']
|
|
|
|
],
|
|
|
|
options: {
|
|
|
|
jshintrc: true
|
|
|
|
}
|
|
|
|
},
|
2014-05-08 06:52:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
karma: {
|
|
|
|
options: {
|
2014-07-30 14:26:08 +00:00
|
|
|
configFile: '<%= config.tests %>/config/karma.unit.js'
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
|
|
|
single: {
|
|
|
|
singleRun: true,
|
|
|
|
autoWatch: false,
|
|
|
|
|
2014-06-23 12:50:23 +00:00
|
|
|
browsers: TEST_BROWSERS
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
|
|
|
unit: {
|
2014-06-23 12:50:23 +00:00
|
|
|
browsers: TEST_BROWSERS
|
2014-03-11 14:54:36 +00:00
|
|
|
}
|
|
|
|
},
|
2014-06-02 12:24:10 +00:00
|
|
|
|
2014-03-11 14:54:36 +00:00
|
|
|
browserify: {
|
|
|
|
options: {
|
2014-03-31 13:54:45 +00:00
|
|
|
browserifyOptions: {
|
2014-06-11 13:08:45 +00:00
|
|
|
builtins: false
|
2014-03-31 13:54:45 +00:00
|
|
|
},
|
|
|
|
bundleOptions: {
|
|
|
|
detectGlobals: false,
|
|
|
|
insertGlobalVars: [],
|
|
|
|
debug: true
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
2014-03-11 14:54:36 +00:00
|
|
|
},
|
2014-06-13 14:55:31 +00:00
|
|
|
bowerViewer: {
|
|
|
|
files: {
|
2014-06-19 15:17:45 +00:00
|
|
|
'<%= config.bowerDist %>/bpmn-viewer.js': [ '<%= config.sources %>/Viewer.js' ]
|
2014-06-13 14:55:31 +00:00
|
|
|
},
|
|
|
|
options: {
|
2014-06-19 15:17:45 +00:00
|
|
|
browserifyOptions: {
|
|
|
|
builtins: false
|
|
|
|
},
|
2014-06-13 14:55:31 +00:00
|
|
|
bundleOptions: {
|
2014-06-19 15:17:45 +00:00
|
|
|
standalone: 'BpmnJS',
|
2014-06-13 14:55:31 +00:00
|
|
|
detectGlobals: false,
|
|
|
|
insertGlobalVars: [],
|
|
|
|
debug: false
|
|
|
|
},
|
|
|
|
transform: [
|
|
|
|
[ 'exposify', {
|
2014-08-05 06:15:41 +00:00
|
|
|
global: true,
|
2014-06-13 14:55:31 +00:00
|
|
|
expose: {
|
|
|
|
sax: 'sax',
|
|
|
|
snapsvg: 'Snap',
|
|
|
|
lodash: '_',
|
|
|
|
jquery: '$',
|
|
|
|
'jquery-mousewheel': '$'
|
|
|
|
}
|
|
|
|
} ]
|
2014-06-19 15:17:45 +00:00
|
|
|
]
|
2014-06-13 14:55:31 +00:00
|
|
|
}
|
2014-03-11 14:54:36 +00:00
|
|
|
}
|
|
|
|
},
|
2014-06-02 12:24:10 +00:00
|
|
|
|
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' ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-06-02 12:24:10 +00:00
|
|
|
|
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) {
|
2014-08-06 07:30:02 +00:00
|
|
|
return extractSourceMap(file);
|
2014-03-31 13:53:31 +00:00
|
|
|
}
|
|
|
|
},
|
2014-06-14 11:09:05 +00:00
|
|
|
bowerViewer: {
|
|
|
|
files: {
|
|
|
|
'<%= config.bowerDist %>/bpmn-viewer.min.js': [ '<%= config.bowerDist %>/bpmn-viewer.js' ]
|
|
|
|
}
|
2014-03-31 13:53:31 +00:00
|
|
|
}
|
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-07-30 14:26:08 +00:00
|
|
|
grunt.registerTask('test', [ '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
|
2014-08-21 13:34:37 +00:00
|
|
|
// * build:all -> build:bower
|
|
|
|
// * build:bower
|
2014-06-14 11:09:05 +00:00
|
|
|
//
|
2014-08-21 13:34:37 +00:00
|
|
|
grunt.registerTask('build', function(target) {
|
2014-03-25 13:06:52 +00:00
|
|
|
|
2014-06-14 11:09:05 +00:00
|
|
|
if (target === 'bower') {
|
2014-08-21 13:34:37 +00:00
|
|
|
return grunt.task.run([ 'browserify:bowerViewer', 'uglify:bowerViewer' ]);
|
2014-03-25 13:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!target || target === 'all') {
|
2014-08-21 13:34:37 +00:00
|
|
|
return grunt.task.run([ 'build:bower' ]);
|
2014-03-25 13:06:52 +00:00
|
|
|
}
|
|
|
|
});
|
2014-03-13 10:21:03 +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' ]);
|
|
|
|
};
|