habitica-self-host/Gruntfile.js

165 lines
4.7 KiB
JavaScript
Raw Normal View History

2013-09-06 17:19:43 +00:00
/*global module:false*/
var _ = require('lodash');
2013-09-06 17:19:43 +00:00
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
2014-02-14 17:35:21 +00:00
pkg: grunt.file.readJSON('package.json'),
git_changelog: {
minimal: {
options: {
repo_url: 'https://github.com/habitrpg/habitrpg',
appName : 'HabitRPG',
branch_name: 'develop'
}
},
extended: {
options: {
file: 'EXTENDEDCHANGELOG.md',
repo_url: 'https://github.com/habitrpg/habitrpg',
appName : 'HabitRPG',
branch_name: 'develop',
grep_commits: '^perf|^style|^fix|^feat|^docs|^refactor|^chore|BREAKING'
}
}
},
2013-09-06 17:19:43 +00:00
karma: {
unit: {
configFile: 'karma.conf.js'
},
continuous: {
configFile: 'karma.conf.js',
singleRun: true,
autoWatch: false
}
},
2013-09-06 17:19:43 +00:00
clean: {
build: ['build']
2013-09-06 17:19:43 +00:00
},
2013-09-06 19:39:18 +00:00
stylus: {
build: {
options: {
compress: false, // AFTER
'include css': true,
paths: ['public']
},
files: {
'build/app.css': ['public/css/index.styl'],
'build/static.css': ['public/css/static.styl']
2013-09-06 19:39:18 +00:00
}
}
},
2013-09-10 12:40:00 +00:00
copy: {
build: {
2014-01-07 19:23:39 +00:00
files: [
{expand: true, cwd: 'public/', src: 'favicon.ico', dest: 'build/'},
{expand: true, cwd: 'public/', src: 'bower_components/habitrpg-shared/dist/spritesmith*.png', dest: 'build/'},
2014-02-12 17:08:17 +00:00
{expand: true, cwd: 'public/', src: 'bower_components/habitrpg-shared/img/sprites/backer-only/*.gif', dest: 'build/'},
{expand: true, cwd: 'public/', src: 'bower_components/habitrpg-shared/img/sprites/npc_ian.gif', dest: 'build/'},
{expand: true, cwd: 'public/', src: 'bower_components/bootstrap/dist/fonts/*', dest: 'build/'}
2014-01-07 19:23:39 +00:00
]
2013-09-10 12:40:00 +00:00
}
},
2013-09-10 12:43:30 +00:00
// UPDATE IT WHEN YOU ADD SOME FILES NOT ALREADY MATCHED!
hashres: {
build: {
options: {
fileNameFormat: '${name}-${hash}.${ext}'
},
src: [
2013-09-10 12:40:00 +00:00
'build/*.js', 'build/*.css', 'build/favicon.ico',
'build/bower_components/habitrpg-shared/dist/*.png',
2014-02-12 17:08:17 +00:00
'build/bower_components/habitrpg-shared/img/sprites/backer-only/*.gif',
'build/bower_components/habitrpg-shared/img/sprites/npc_ian.gif',
'build/bower_components/bootstrap/dist/fonts/*'
],
dest: 'build/*.css'
}
},
2014-02-14 17:35:21 +00:00
nodemon: {
dev: {
script: '<%= pkg.main %>'
}
},
2013-09-07 10:47:44 +00:00
watch: {
dev: {
2013-09-10 20:57:34 +00:00
files: ['public/**/*.styl'], // 'public/**/*.js' Not needed because not in production
2013-09-07 10:47:44 +00:00
tasks: [ 'build:dev' ],
options: {
nospawn: true
2013-09-06 20:33:00 +00:00
}
}
2013-09-07 10:47:44 +00:00
},
2013-09-06 19:39:18 +00:00
2013-09-07 10:47:44 +00:00
concurrent: {
dev: ['nodemon', 'watch'],
2013-09-06 17:19:43 +00:00
options: {
2013-09-07 10:47:44 +00:00
logConcurrentOutput: true
2013-09-06 17:19:43 +00:00
}
2013-09-07 10:47:44 +00:00
}
2013-09-06 17:19:43 +00:00
});
//Load build files from public/manifest.json
grunt.registerTask('loadManifestFiles', 'Load all build files from public/manifest.json', function(){
var files = grunt.file.readJSON('./website/public/manifest.json');
var uglify = {};
var cssmin = {};
_.each(files, function(val, key){
var js = uglify['build/' + key + '.js'] = [];
_.each(files[key]['js'], function(val){
js.push('public/' + val);
});
var css = cssmin['build/' + key + '.css'] = [];
_.each(files[key]['css'], function(val){
var path = (val == 'app.css' || val == 'static.css') ? 'build/' : 'public/';
css.push(path + val)
});
});
console.log(uglify);
console.log(cssmin);
grunt.config.set('uglify.build.files', uglify);
grunt.config.set('uglify.build.options', {compress: false});
grunt.config.set('cssmin.build.files', cssmin);
// Rewrite urls to relative path
grunt.config.set('cssmin.build.options', {'target': 'public/css/whatever-css.css'});
});
2013-09-06 17:19:43 +00:00
// Register tasks.
grunt.registerTask('build:prod', ['loadManifestFiles', 'clean:build', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']);
2014-02-12 12:59:13 +00:00
grunt.registerTask('build:dev', ['stylus']);
grunt.registerTask('test', ['loadManifestFiles', 'uglify', 'cssmin']);
2013-09-07 10:47:44 +00:00
grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]);
2013-09-06 17:19:43 +00:00
// Load tasks
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
2013-09-06 19:39:18 +00:00
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-cssmin');
2013-09-10 12:40:00 +00:00
grunt.loadNpmTasks('grunt-contrib-copy');
2013-09-07 10:47:44 +00:00
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-hashres');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('git-changelog');
2013-09-06 17:19:43 +00:00
};