Stackedit/Gruntfile.js

293 lines
8.9 KiB
JavaScript
Raw Permalink Normal View History

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-09-03 13:40:23 +00:00
grunt.loadNpmTasks('grunt-shell');
2013-08-30 22:45:29 +00:00
/***************************************************************************
* Configuration
*/
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
requirejs: {
compile: {
options: {
baseUrl: "res",
name: "main",
out: "res-min/main.js",
mainConfigFile: 'res/main.js',
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,
cwd: 'res/themes',
src: [
'*.less'
],
dest: 'res-min/themes',
ext: '.css',
}
]
},
compress: {
options: {
compress: true,
paths: 'res/styles'
},
files: [
{
expand: true,
cwd: 'res-min/themes',
src: [
'*.css'
],
dest: 'res-min/themes',
}
]
},
},
'string-replace': {
'css-import': {
files: {
'./': 'res-min/themes/*.css',
},
options: {
replacements: [
{
pattern: /@import /g,
replacement: '@import (less) '
2013-09-21 15:01:16 +00:00
},
]
}
},
'font-parameters': {
files: {
'./': 'res-min/themes/*.css',
},
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: {
'res/config.js': 'res/config.js'
},
options: {
replacements: [
{
pattern: /(var VERSION = ).*/,
replacement: 'var VERSION = "<%= pkg.version %>";'
},
]
}
},
2013-08-30 22:45:29 +00:00
'cache-manifest': {
files: {
'cache.manifest': 'cache.manifest'
},
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,
cwd: 'res/font',
src: [
'**'
],
dest: 'res-min/font/'
},
2013-08-30 22:45:29 +00:00
{
expand: true,
cwd: 'res/libs/fontello/font',
src: [
'**'
],
dest: 'res-min/font/'
},
// Images
{
expand: true,
cwd: 'res/img',
src: [
'**'
],
dest: 'res-min/img/'
},
// Libraries
{
expand: true,
cwd: 'res/bower-libs/requirejs',
src: [
'require.js'
],
dest: 'res-min/'
},
]
}
},
// Inject bower dependencies into RequireJS configuration
bower: {
target: {
rjsConfig: 'res/main.js'
}
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'
}
},
shell: {
deploy: {
options: {
stdout: true,
stderr: true,
failOnError: true
},
command: [
'git branch -f gh-pages master',
'git push --all origin'
].join('&&')
2013-09-03 10:37:59 +00:00
}
2013-08-30 22:45:29 +00:00
}
});
/***************************************************************************
* Clean
*/
grunt.registerTask('clean', function() {
// Remove res-min/ folder
grunt.file['delete']('res-min');
});
/***************************************************************************
* 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 = [
'res-min',
'lib/MathJax/extensions',
'lib/MathJax/fonts/HTML-CSS/TeX/woff',
'lib/MathJax/jax/output/HTML-CSS/fonts/TeX',
'lib/MathJax/jax/output/HTML-CSS/fonts/STIX'
];
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) {
resourceList.push(abspath);
});
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
/***************************************************************************
* Deploy task
*/
grunt.registerTask('deploy', 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');
grunt.task.run('shell');
2013-09-03 10:37:59 +00:00
});
2013-08-30 22:45:29 +00:00
};