2014-02-19 09:15:05 -05:00
|
|
|
module.exports = function(grunt) {
|
|
|
|
grunt.initConfig({
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
2014-03-07 11:58:57 -05:00
|
|
|
buildName: 'matter',
|
2015-05-20 15:37:52 -04:00
|
|
|
buildVersion: 'edge-master',
|
2014-03-10 21:17:41 -04:00
|
|
|
docVersion: 'v<%= pkg.version %>',
|
2014-02-19 09:15:05 -05:00
|
|
|
concat: {
|
|
|
|
build: {
|
|
|
|
options: {
|
|
|
|
process: function(src, filepath) {
|
|
|
|
return '// Begin ' + filepath + '\n\n' + src + '\n\n; // End ' + filepath + '\n\n';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
src: ['src/**/*.js', '!src/module/*'],
|
2014-03-07 11:58:57 -05:00
|
|
|
dest: 'build/<%= buildName %>.js'
|
2014-02-19 09:15:05 -05:00
|
|
|
},
|
|
|
|
pack: {
|
|
|
|
options: {
|
2014-03-22 11:15:01 -04:00
|
|
|
banner: '/**\n* <%= buildName %>.js <%= buildVersion %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n'
|
2014-02-19 09:15:05 -05:00
|
|
|
},
|
2014-03-07 11:58:57 -05:00
|
|
|
src: ['src/module/Intro.js', 'build/<%= buildName %>.js', 'src/module/Outro.js'],
|
|
|
|
dest: 'build/<%= buildName %>.js'
|
2014-02-19 09:15:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
uglify: {
|
2014-03-22 11:15:01 -04:00
|
|
|
min: {
|
|
|
|
options: {
|
|
|
|
banner: '/**\n* <%= buildName %>.min.js <%= buildVersion %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n'
|
|
|
|
},
|
2014-03-07 11:58:57 -05:00
|
|
|
src: 'build/<%= buildName %>.js',
|
|
|
|
dest: 'build/<%= buildName %>.min.js'
|
2014-03-22 11:15:01 -04:00
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
options: {
|
|
|
|
mangle: false,
|
|
|
|
compress: false,
|
|
|
|
preserveComments: false,
|
|
|
|
beautify: {
|
|
|
|
width: 32000,
|
|
|
|
indent_level: 2,
|
|
|
|
space_colon: false,
|
|
|
|
beautify: true
|
|
|
|
},
|
|
|
|
banner: '/**\n* <%= buildName %>.min.js <%= buildVersion %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n'
|
|
|
|
},
|
|
|
|
src: 'build/<%= buildName %>.js',
|
|
|
|
dest: 'build/<%= buildName %>.js'
|
2014-02-19 09:15:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
demo: {
|
2014-03-07 11:58:57 -05:00
|
|
|
src: 'build/<%= buildName %>.js',
|
|
|
|
dest: 'demo/js/lib/<%= buildName %>.js'
|
2014-02-19 09:15:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
jshint: {
|
|
|
|
options: {
|
|
|
|
jshintrc: '.jshintrc'
|
|
|
|
},
|
2015-08-03 16:00:54 -04:00
|
|
|
all: ['src/**/*.js', 'demo/js/*.js', 'tests/browser/TestDemo.js', '!src/module/*']
|
2014-02-19 09:15:05 -05:00
|
|
|
},
|
|
|
|
connect: {
|
|
|
|
watch: {
|
|
|
|
options: {
|
|
|
|
port: 9000,
|
2014-03-07 11:58:57 -05:00
|
|
|
open: 'http://localhost:9000/demo/dev.html',
|
2014-02-19 09:15:05 -05:00
|
|
|
livereload: 9001
|
|
|
|
}
|
2015-08-04 14:53:15 -04:00
|
|
|
},
|
|
|
|
serve: {
|
|
|
|
options: {
|
|
|
|
port: 9000
|
|
|
|
}
|
2014-02-19 09:15:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
options: {
|
|
|
|
livereload: {
|
|
|
|
port: 9001
|
|
|
|
}
|
|
|
|
},
|
|
|
|
src: {
|
|
|
|
files: ['src/**/*.js'],
|
2014-03-12 05:35:36 -04:00
|
|
|
tasks: ['build:dev']
|
2014-02-19 09:15:05 -05:00
|
|
|
},
|
|
|
|
demo: {
|
|
|
|
files: ['build/matter.js', 'demo/js/**/*.html', 'demo/js/**/*.js', 'demo/css/**/*.css']
|
|
|
|
}
|
|
|
|
},
|
2014-02-28 13:23:25 -05:00
|
|
|
yuidoc: {
|
|
|
|
compile: {
|
2014-03-10 21:17:41 -04:00
|
|
|
name: '<%= pkg.name %>.js Physics Engine API Documentation for <%= docVersion %>',
|
2014-02-28 13:23:25 -05:00
|
|
|
description: '<%= pkg.description %>',
|
2014-03-10 21:17:41 -04:00
|
|
|
version: '<%= docVersion %>',
|
2014-02-28 13:23:25 -05:00
|
|
|
url: '<%= pkg.homepage %>',
|
|
|
|
options: {
|
|
|
|
paths: 'src',
|
|
|
|
themedir: 'matter-doc-theme',
|
|
|
|
outdir: 'doc',
|
|
|
|
linkNatives: true
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 07:06:55 -05:00
|
|
|
},
|
|
|
|
preprocess: {
|
|
|
|
options: {
|
|
|
|
inline: true,
|
|
|
|
context : {
|
|
|
|
DEBUG: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
js: {
|
|
|
|
src: 'build/<%= buildName %>.js',
|
|
|
|
dest: 'build/<%= buildName %>.js'
|
|
|
|
}
|
2015-08-03 16:00:54 -04:00
|
|
|
},
|
|
|
|
shell: {
|
2015-08-03 19:37:40 -04:00
|
|
|
testDemo: {
|
|
|
|
command: function(arg) {
|
|
|
|
arg = arg ? ' --' + arg : '';
|
|
|
|
return 'phantomjs tests/browser/TestDemo.js' + arg;
|
|
|
|
},
|
2015-08-03 16:00:54 -04:00
|
|
|
options: {
|
|
|
|
execOptions: {
|
|
|
|
timeout: 1000 * 60
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 13:23:25 -05:00
|
|
|
}
|
2014-02-19 09:15:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
2014-02-28 13:23:25 -05:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
2015-01-25 07:06:55 -05:00
|
|
|
grunt.loadNpmTasks('grunt-preprocess');
|
2015-08-03 16:00:54 -04:00
|
|
|
grunt.loadNpmTasks('grunt-shell');
|
2014-02-19 09:15:05 -05:00
|
|
|
|
2014-03-07 11:58:57 -05:00
|
|
|
grunt.registerTask('default', ['test', 'build']);
|
2015-08-04 14:53:15 -04:00
|
|
|
grunt.registerTask('test', ['jshint', 'test:demo']);
|
|
|
|
grunt.registerTask('test:all', ['build:dev', 'connect:serve', 'test']);
|
2014-03-12 05:35:36 -04:00
|
|
|
grunt.registerTask('dev', ['build:dev', 'connect:watch', 'watch']);
|
2014-03-11 06:25:44 -04:00
|
|
|
|
2015-08-04 14:53:15 -04:00
|
|
|
grunt.registerTask('test:demo', function() {
|
2015-08-03 19:37:40 -04:00
|
|
|
var updateAll = grunt.option('updateAll'),
|
|
|
|
diff = grunt.option('diff');
|
|
|
|
|
|
|
|
if (updateAll) {
|
|
|
|
grunt.task.run('shell:testDemo:updateAll');
|
|
|
|
} else if (diff) {
|
|
|
|
grunt.task.run('shell:testDemo:diff');
|
|
|
|
} else {
|
|
|
|
grunt.task.run('shell:testDemo');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-12 05:35:36 -04:00
|
|
|
grunt.registerTask('build', function(mode) {
|
|
|
|
var isDev = (mode === 'dev'),
|
|
|
|
isRelease = (mode === 'release'),
|
|
|
|
isEdge = (mode === 'edge'),
|
2014-03-22 11:15:01 -04:00
|
|
|
pkg = grunt.file.readJSON('package.json'),
|
|
|
|
uglifyTask;
|
2014-03-11 06:25:44 -04:00
|
|
|
|
|
|
|
// development build mode
|
|
|
|
if (isDev) {
|
|
|
|
grunt.config.set('buildName', 'matter-dev');
|
|
|
|
grunt.config.set('buildVersion', pkg.version + '-dev');
|
2014-03-22 11:15:01 -04:00
|
|
|
grunt.task.run('concat', 'uglify:dev', 'uglify:min', 'copy');
|
2014-03-11 06:25:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// release build mode
|
|
|
|
if (isRelease) {
|
|
|
|
grunt.config.set('buildName', 'matter-' + pkg.version);
|
|
|
|
grunt.config.set('buildVersion', pkg.version + '-alpha');
|
2014-03-22 11:15:01 -04:00
|
|
|
grunt.task.run('concat', 'uglify:min', 'copy');
|
2014-03-11 06:25:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// edge build mode (default)
|
|
|
|
if (isEdge || (!isDev && !isRelease)) {
|
2015-05-20 15:37:52 -04:00
|
|
|
grunt.config.set('buildVersion', 'edge-master');
|
2015-01-25 07:06:55 -05:00
|
|
|
grunt.task.run('concat', 'preprocess', 'uglify:min');
|
2014-03-11 06:25:44 -04:00
|
|
|
}
|
|
|
|
});
|
2014-03-10 21:17:41 -04:00
|
|
|
|
2014-03-23 19:07:04 -04:00
|
|
|
grunt.registerTask('doc', function(mode) {
|
|
|
|
var isDev = (mode === 'dev'),
|
|
|
|
isRelease = (mode === 'release'),
|
|
|
|
isEdge = (mode === 'edge');
|
|
|
|
|
|
|
|
if (isEdge)
|
2014-03-10 21:17:41 -04:00
|
|
|
grunt.config.set('docVersion', 'edge version (master)');
|
2014-03-23 19:07:04 -04:00
|
|
|
|
2014-03-10 21:17:41 -04:00
|
|
|
grunt.task.run('yuidoc');
|
|
|
|
});
|
2014-03-07 11:58:57 -05:00
|
|
|
|
|
|
|
grunt.registerTask('set_config', 'Set a config property.', function(name, val) {
|
|
|
|
grunt.config.set(name, val);
|
|
|
|
});
|
2014-02-19 09:15:05 -05:00
|
|
|
};
|