2013-08-30 22:45:29 +00:00
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-less');
|
|
|
|
grunt.loadNpmTasks('grunt-string-replace');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
|
|
|
grunt.loadNpmTasks('grunt-bower-requirejs');
|
2013-09-03 10:37:59 +00:00
|
|
|
grunt.loadNpmTasks('grunt-bump');
|
2013-08-30 22:45:29 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
grunt.initConfig({
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
requirejs: {
|
|
|
|
compile: {
|
|
|
|
options: {
|
2013-10-06 22:29:08 +00:00
|
|
|
baseUrl: "public/res",
|
2013-08-30 22:45:29 +00:00
|
|
|
name: "main",
|
2013-10-06 22:29:08 +00:00
|
|
|
out: "public/res-min/main.js",
|
|
|
|
mainConfigFile: 'public/res/main.js',
|
2013-08-30 22:45:29 +00:00
|
|
|
optimize: "uglify2",
|
2013-09-14 16:59:40 +00:00
|
|
|
inlineText: true,
|
2013-08-30 22:45:29 +00:00
|
|
|
uglify2: {
|
|
|
|
output: {
|
|
|
|
beautify: true,
|
|
|
|
indent_level: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
excludeShallow: [
|
|
|
|
'css/css-builder',
|
|
|
|
'less/lessc-server',
|
|
|
|
'less/lessc'
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
less: {
|
|
|
|
compile: {
|
|
|
|
files: [
|
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res/themes',
|
2013-08-30 22:45:29 +00:00
|
|
|
src: [
|
|
|
|
'*.less'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/themes',
|
2013-08-30 22:45:29 +00:00
|
|
|
ext: '.css',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
options: {
|
|
|
|
compress: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
paths: 'public/res/styles'
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
files: [
|
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res-min/themes',
|
2013-08-30 22:45:29 +00:00
|
|
|
src: [
|
|
|
|
'*.css'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/themes',
|
2013-08-30 22:45:29 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'string-replace': {
|
|
|
|
'css-import': {
|
|
|
|
files: {
|
2013-10-06 22:29:08 +00:00
|
|
|
'./': 'public/res-min/themes/*.css',
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /@import /g,
|
|
|
|
replacement: '@import (less) '
|
2013-09-21 15:01:16 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'font-parameters': {
|
|
|
|
files: {
|
2013-10-06 22:29:08 +00:00
|
|
|
'./': 'public/res-min/themes/*.css',
|
2013-09-21 15:01:16 +00:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /(font\/fontello\.\w+)\?\w+/g,
|
|
|
|
replacement: '$1'
|
2013-08-30 22:45:29 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-09-03 10:37:59 +00:00
|
|
|
'config': {
|
|
|
|
files: {
|
2013-10-06 22:29:08 +00:00
|
|
|
'public/res/config.js': 'public/res/config.js'
|
2013-09-03 10:37:59 +00:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /(var VERSION = ).*/,
|
|
|
|
replacement: 'var VERSION = "<%= pkg.version %>";'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-08-30 22:45:29 +00:00
|
|
|
'cache-manifest': {
|
|
|
|
files: {
|
2013-10-06 22:29:08 +00:00
|
|
|
'public/cache.manifest': 'public/cache.manifest'
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
options: {
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
pattern: /(#Date ).*/,
|
|
|
|
replacement: '$1<%= grunt.template.today() %>'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: /(#DynamicResourcesBegin\n)[\s\S]*(\n#DynamicResourcesEnd)/,
|
|
|
|
replacement: '$1<%= resources %>$2'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2013-09-03 10:37:59 +00:00
|
|
|
},
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
resources: {
|
|
|
|
files: [
|
|
|
|
// Fonts
|
2013-09-16 23:14:17 +00:00
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res/font',
|
2013-09-16 23:14:17 +00:00
|
|
|
src: [
|
|
|
|
'**'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/font/'
|
2013-09-16 23:14:17 +00:00
|
|
|
},
|
2013-08-30 22:45:29 +00:00
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res/libs/fontello/font',
|
2013-08-30 22:45:29 +00:00
|
|
|
src: [
|
|
|
|
'**'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/font/'
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
// Images
|
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res/img',
|
2013-08-30 22:45:29 +00:00
|
|
|
src: [
|
|
|
|
'**'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/img/'
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
// Libraries
|
|
|
|
{
|
|
|
|
expand: true,
|
2013-10-06 22:29:08 +00:00
|
|
|
cwd: 'public/res/bower-libs/requirejs',
|
2013-08-30 22:45:29 +00:00
|
|
|
src: [
|
|
|
|
'require.js'
|
|
|
|
],
|
2013-10-06 22:29:08 +00:00
|
|
|
dest: 'public/res-min/'
|
2013-08-30 22:45:29 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Inject bower dependencies into RequireJS configuration
|
|
|
|
bower: {
|
|
|
|
target: {
|
2013-10-06 22:29:08 +00:00
|
|
|
rjsConfig: 'public/res/main.js'
|
2013-08-30 22:45:29 +00:00
|
|
|
}
|
2013-09-03 10:37:59 +00:00
|
|
|
},
|
|
|
|
bump: {
|
|
|
|
options: {
|
|
|
|
files: [
|
|
|
|
'package.json',
|
|
|
|
'bower.json'
|
|
|
|
],
|
|
|
|
updateConfigs: [
|
|
|
|
'pkg'
|
2013-09-03 13:40:23 +00:00
|
|
|
],
|
2013-09-16 23:14:17 +00:00
|
|
|
commitFiles: [
|
|
|
|
'-a'
|
|
|
|
],
|
2013-09-03 13:40:23 +00:00
|
|
|
pushTo: 'origin'
|
|
|
|
}
|
|
|
|
},
|
2013-08-30 22:45:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Clean
|
|
|
|
*/
|
|
|
|
grunt.registerTask('clean', function() {
|
|
|
|
|
2013-10-06 22:29:08 +00:00
|
|
|
// Remove public/res-min folder
|
|
|
|
grunt.file['delete']('public/res-min');
|
2013-08-30 22:45:29 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Build JavaScript
|
|
|
|
*/
|
|
|
|
grunt.registerTask('build-js', function() {
|
|
|
|
|
|
|
|
// Run r.js optimization
|
|
|
|
grunt.task.run('requirejs');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Build CSS
|
|
|
|
*/
|
|
|
|
grunt.registerTask('build-css', function() {
|
|
|
|
|
|
|
|
// First compile less files
|
|
|
|
grunt.task.run('less:compile');
|
|
|
|
// Then force evaluation of CSS imports
|
|
|
|
grunt.task.run('string-replace:css-import');
|
|
|
|
// Run less another time with CSS evaluation and compression
|
|
|
|
grunt.task.run('less:compress');
|
2013-09-21 15:01:16 +00:00
|
|
|
// Remove fontello checksum arguments
|
|
|
|
grunt.task.run('string-replace:font-parameters');
|
2013-08-30 22:45:29 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* Resources
|
|
|
|
*/
|
|
|
|
grunt.registerTask('build-res', function() {
|
2013-08-30 23:29:01 +00:00
|
|
|
|
2013-08-30 22:45:29 +00:00
|
|
|
// Copy some resources (images, fonts...)
|
|
|
|
grunt.task.run('copy:resources');
|
2013-08-30 23:29:01 +00:00
|
|
|
|
2013-08-30 22:45:29 +00:00
|
|
|
// List resources and inject them in cache.manifest
|
2013-08-30 23:29:01 +00:00
|
|
|
var resFolderList = [
|
2013-10-06 22:29:08 +00:00
|
|
|
'public/res-min',
|
2013-10-09 01:16:49 +00:00
|
|
|
'public/libs/dictionaries',
|
|
|
|
'public/libs/MathJax/extensions',
|
|
|
|
'public/libs/MathJax/fonts/HTML-CSS/TeX/woff',
|
|
|
|
'public/libs/MathJax/jax/output/HTML-CSS/fonts/TeX',
|
|
|
|
'public/libs/MathJax/jax/output/HTML-CSS/fonts/STIX'
|
2013-08-30 23:29:01 +00:00
|
|
|
];
|
|
|
|
grunt.task.run('list-res:' + resFolderList.join(':'));
|
2013-08-30 22:45:29 +00:00
|
|
|
grunt.task.run('string-replace:cache-manifest');
|
2013-08-30 23:29:01 +00:00
|
|
|
|
2013-08-30 22:45:29 +00:00
|
|
|
});
|
2013-08-30 23:29:01 +00:00
|
|
|
|
2013-08-30 22:45:29 +00:00
|
|
|
grunt.registerTask('list-res', function() {
|
|
|
|
var resourceList = [];
|
2013-08-30 23:29:01 +00:00
|
|
|
grunt.util.recurse(arguments, function(arg) {
|
|
|
|
grunt.log.writeln('Listing resources: ' + arg);
|
|
|
|
grunt.file.recurse(arg, function(abspath) {
|
2013-10-06 22:29:08 +00:00
|
|
|
resourceList.push(abspath.replace(/^public\//, ''));
|
2013-08-30 23:29:01 +00:00
|
|
|
});
|
2013-08-30 22:45:29 +00:00
|
|
|
});
|
|
|
|
grunt.config.set('resources', resourceList.join('\n'));
|
|
|
|
});
|
|
|
|
|
2013-09-03 10:37:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Default task
|
|
|
|
*/
|
2013-08-30 22:45:29 +00:00
|
|
|
grunt.registerTask('default', function() {
|
|
|
|
grunt.task.run('clean');
|
|
|
|
grunt.task.run('build-js');
|
|
|
|
grunt.task.run('build-css');
|
|
|
|
grunt.task.run('build-res');
|
|
|
|
});
|
2013-09-03 10:37:59 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
2013-10-20 14:41:56 +00:00
|
|
|
* Tag task
|
2013-09-03 10:37:59 +00:00
|
|
|
*/
|
2013-10-20 14:41:56 +00:00
|
|
|
grunt.registerTask('tag', function() {
|
2013-09-03 13:40:23 +00:00
|
|
|
grunt.task.run('bump-only');
|
2013-09-03 10:37:59 +00:00
|
|
|
grunt.task.run('string-replace:config');
|
|
|
|
grunt.task.run('default');
|
2013-09-03 13:40:23 +00:00
|
|
|
grunt.task.run('bump-commit');
|
2013-09-03 10:37:59 +00:00
|
|
|
});
|
2013-08-30 22:45:29 +00:00
|
|
|
};
|