Skip to content

Instantly share code, notes, and snippets.

@anareyna
Created March 31, 2014 23:37
Show Gist options
  • Save anareyna/9904773 to your computer and use it in GitHub Desktop.
Save anareyna/9904773 to your computer and use it in GitHub Desktop.
module.exports = function(grunt) {
grunt.file.defaultEncoding = 'utf8';
cfg = grunt.file.readJSON('grunt/config.json');
//var version = grunt.file.read('../../src/last_commit').replace(/\n|<br\s*\/?>/gi, "");
var version = grunt.template.today("dd-mm-yyyy")
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// clean
clean: {
options: {force: true},
build: {
src: [cfg.js_compiled_source_path]
}
},
//coffee
coffee: {
glob_to_multiple: {
options: {
bare: true
},
expand: true,
cwd: cfg.coffee_source_path, // all the source
src: ['**/*.coffee','!**/_*.coffee'], // Pattern to match, relative to the cwd.
dest: cfg.js_compiled_source_path,
ext: '.js'
}
},
//concat
concat: {
options: {
stripBanners: false
}
},
//uglify
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("dd/mm/yyyy") %> */\n',
mangle: false,
compress: {
drop_console: true
}
},
js: {
files: [{
expand: true,
cwd: cfg.js_source_path, // all the source
src: '**/*.js', // pattern relative to cwd
dest: cfg.js_min_source_path,
}]
}
},
//jade
jade: {
compile: {
options: {
data: {}
},
files: [{
expand: true,
cwd: cfg.jademobile_source_path,
src: [ '**/*.jade', '!config/*.jade', '!layout/*.jade', '!render/*.jade'],
dest: cfg.jade_compiled_source_path,
ext: '.html'
}]
}
},
//watch
watch: {
javascript: {
files: [cfg.coffee_source_path+'modules/**/*.coffee'],
tasks: ['js'],
options: {
interrupt: true
}
},
},
//copy
copy: {
main: {
src: '../../public/f/img_src/favicon.ico',
dest: '../../public/f/img/favicon.ico'
},
},
//imagemin
imagemin: {
dynamic: {
options: {
optimizationLevel: 3
},
files: [{
expand: true, // Enable dynamic expansion
cwd: '../../public/f/img_src', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: '../../public/f/img' // Destination path prefix
}]
}
},
sprite:{
all: {
src: '../../public/f/sprite/*.png',
destImg: '../../public/f/sprite/resultado/spritesheet.png',
destCSS: '../../public/f/sprite/resultado/sprites.styl',
'algorithm': 'binary-tree',
//'cssFormat': 'stylus'
}
},
sprites: { //imagine
icons36: {
src: ['../../public/f/sprite/*.png'],
css: '../../public/f/sprite/imagine/spritesheet.styl',
map: '../../public/f/sprite/imagine/spritesheet.png',
output: 'stylus'
}
},
//jshint
jshint: {
options: {
jshintrc : 'grunt/jshint/.jshintrc',
"smarttabs" : true
},
js: [cfg.js_source_path+'**/*.js', '!'+cfg.js_source_path+'abautos/*.js', '!'+cfg.js_source_path+'libs/*.js', '!'+cfg.js_source_path+'libs/utils/*.js', '!'+cfg.js_source_path+'libs/jquery/*.js', '!'+cfg.js_source_path+'libs/yoson/old_modules/*.js', '!'+cfg.js_source_path+'libs/yoson/data/*.js']
},
//replace
replace: {
dist: {
options: {
patterns: [
{
match: /version/g,
replacement: version
}
]
},
files: [
{expand: true, flatten: true, src: [cfg.css_compiled_source_path+'*.css'], dest: cfg.css_compiled_source_path}
]
}
},
js2coffee: {
options: {
indent : " "
},
// Example: this target compiles a single file from JavaScript to CofeeScript
single: {
src: cfg.js_to_coffee_compiled + 'main.js',
dest: cfg.js_to_coffee_compiled + 'main.coffee'
}
}
});
//loadNpmTasks
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-spritesmith');
grunt.loadNpmTasks('grunt-imagine');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-js2coffee');
grunt.loadNpmTasks('grunt-replace');
// load tasks
grunt.task.loadTasks('grunt/custom_tasks/');
//registerTask
grunt.registerTask('cafe', ['clean', 'coffee']);
grunt.registerTask('js_source', ['concatenation', 'concat']);
grunt.registerTask('javascript', ['js_source', 'jshint']); //, 'uglify']);
grunt.registerTask('js', ['cafe', 'javascript']); //, 'uglify']);
grunt.registerTask('imgmin', ['imagemin', 'copy']);
// Run Default task(s).
grunt.registerTask('default', ['cafe', 'javascript']); // 'replace']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment