Skip to content

Instantly share code, notes, and snippets.

@awinogradov
Forked from gruzzilkin/Gruntfile.js
Created February 19, 2014 18:53
Show Gist options
  • Save awinogradov/9098971 to your computer and use it in GitHub Desktop.
Save awinogradov/9098971 to your computer and use it in GitHub Desktop.
module.exports = function (grunt) {
'use strict';
// Enb targets
var fs = require('fs');
var targetsList = [],
htmlList = [],
cssList = ['desktop.bundles/common/common.css', 'desktop.bundles/common/common.ie.css', 'desktop.bundles/common/common.ie8.css', 'desktop.bundles/common/common.ie9.css'],
jsList = ['desktop.bundles/common/common.js'];
fs.readdirSync('desktop.bundles').map(function (page) {
targetsList.push('desktop.bundles/' + page + '/');
if (page !== 'common') {
htmlList.push('desktop.bundles/' + page + '/'/*+page+'.html'*/);
}
});
// Grunt tasks list
var defaultTask = 'enb:development prettify autoprefixer cssmin'; /*imagemin csso*/
var allTask = 'clean newer:imagemin favicons enb:development prettify autoprefixer cssmin'; /*imgo csscomb*/
// Grunt watch tasks list
var watchStyles = 'concurrent:css autoprefixer';
var watchScripts = 'enb:js';
var watchHtml = 'enb:html prettify';
require('time-grunt')(grunt);
grunt.initConfig({
meta: {
styles: ['blocks.common/**/*.css', 'blocks.common/**/*.styl', 'desktop.blocks/**/*.css', 'desktop.blocks/**/*.styl'],
bemhtml: ['blocks.common/**/*.bemhtml', 'desktop.blocks/**/*.bemhtml', 'desktop.templates/**/*.bemhtml'],
xjst: ['blocks.common/**/*.bemhtml.xjst', 'desktop.blocks/**/*.bemhtml.xjst', 'desktop.templates/**/*.bemhtml.xjst'],
deps: ['blocks.common/**/*.deps.js', 'desktop.blocks/**/*.deps.js', 'desktop.templates/**/*.deps.js'],
bemjson: ['desktop.bundles/**/*.bemjson.js'],
js: ['blocks.common/**/*.js', 'desktop.blocks/**/*.js'],
assets: ['desktop.assets/**/*.png', 'desktop.assets/**/*.jpg', 'desktop.assets/**/*.gif', 'desktop.assets/**/*.*']
},
enb: {
development: {
beforeBuild: function () {
console.log('beforeBuild');
},
afterBuild: function () {
console.log('afterBuild');
},
targets: targetsList
},
css: {
targets: ['desktop.bundles/common/']/*cssList*/
},
commonCSS: {
targets: [cssList[0]]
},
ieCSS: {
targets: [cssList[1]]
},
ie8CSS: {
targets: [cssList[2]]
},
ie9CSS: {
targets: [cssList[3]]
},
js: {
targets: jsList
},
html: {
targets: htmlList
},
options: {
noLog: true
}
},
concurrent: {
css: ['enb:commonCSS', 'enb:ieCSS', 'enb:ie8CSS', 'enb:ie9CSS']
},
clean: {
build: {
src: ["product/**/*"]
}
},
prettify: {
options: {
"indent_size": 1,
"condense": true,
"indent_inner_html": true,
"indent_char": " ",
"unformatted": ["a", "abbr", "acronym", "address", "b", "bdo", "big", "cite", "code", "del", "dfn", "dt", "em", "font", "h1", "h2", "h3", "h4", "h5", "h6", "i", "ins", "kbd", "pre", "q", "s", "samp", "small", "span", "strike", "strong", "sub", "sup", "tt", "u", "var" ]
},
html: {
expand: true,
cwd: 'product/',
ext: '.html',
src: ['*.html'],
dest: 'product/'
}
},
autoprefixer: {
mixdown: {
options: {
browsers: ['last 2 version', '> 1%', 'ie 8', 'ie 7']
},
files: [
{
expand: true,
cwd: 'product/css',
src: ['*.css'],
dest: 'product/css',
filter: 'isFile'
}
]
}
},
favicons: {
options: {
trueColor: true,
precomposed: true,
appleTouchBackgroundColor: "#fff",
windowsTile: true,
tileBlackWhite: false,
tileColor: "#fff"
},
icons: {
src: 'desktop.assets/i/favicon.png',
dest: 'product/'
}
},
watch: {
styl: {
files: '<%= meta.styles %>',
tasks: 'watchingStyles'
},
js: {
files: '<%= meta.js %>',
tasks: 'watchingScripts'
},
bemhtml: {
files: '<%= meta.bemhtml %>',
tasks: 'watchingHtml',
options: {
spawn: false
}
},
xjst: {
files: '<%= meta.xjst %>',
tasks: 'watchingHtml',
options: {
spawn: false
}
},
deps: {
files: '<%= meta.deps %>',
tasks: 'default'
},
bemjson: {
files: '<%= meta.bemjson %>',
tasks: 'watchingHtml',
options: {
spawn: false
}
}
}
});
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Compile
grunt.registerTask('default', defaultTask.split(' '));
grunt.registerTask('all', allTask.split(' '));
// Watch
grunt.registerTask('watchingStyles', watchStyles.split(' '));
grunt.registerTask('watchingScripts', watchScripts.split(' '));
grunt.registerTask('watchingHtml', watchHtml.split(' '));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment