Simplify Grunt tasks and include Normalize.css import by default

Running `grunt` will now use Bower to install Normalize.css. As of 1.0.0
Bower got much faster, and it also uses a cache so the install only
happens once.

Added `grunt build` which does not the "import" or "test" tasks.
This commit is contained in:
Eric Ferraiuolo 2013-08-07 18:57:06 -04:00
parent aa48d1d8b4
commit f2733cb2ff

View File

@ -6,8 +6,7 @@ module.exports = function (grunt) {
grunt.initConfig({ grunt.initConfig({
pkg : grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
normalize: grunt.file.readJSON('src/base/bower.json'),
// -- Constants ------------------------------------------------------------ // -- Constants ------------------------------------------------------------
@ -18,8 +17,7 @@ grunt.initConfig({
clean: { clean: {
build : ['build/'], build : ['build/'],
build_res: ['build/*-r.css'], build_res: ['build/*-r.css'],
release : ['release/<%= pkg.version %>/'], release : ['release/<%= pkg.version %>/']
base : ['src/base/css/', 'src/base/bower.json', 'src/base/LICENSE.md']
}, },
// -- Copy Config ---------------------------------------------------------- // -- Copy Config ----------------------------------------------------------
@ -28,44 +26,21 @@ grunt.initConfig({
build: { build: {
expand : true, expand : true,
flatten: true, flatten: true,
src : 'src/**/css/*.css',
dest : 'build/', dest : 'build/',
src: [
'bower_components/normalize-css/normalize.css',
'src/**/css/*.css'
],
rename: function (dest, src) { rename: function (dest, src) {
// normalize -> base // normalize -> base
src = src.replace(/^normalize(-.+\.css|\.css)$/, 'base$1'); if (src === 'normalize.css') {
src = 'base.css';
}
return path.join(dest, src); return path.join(dest, src);
} }
},
normalize: {
expand : true,
flatten: true,
cwd : 'bower_components/normalize-css/',
src : '{bower.json,LICENSE.md,normalize.css}',
dest : 'src/base/',
rename: function (dest, file) {
if (grunt.file.isMatch('*.css', file)) {
return path.join(dest, 'css', file);
}
return path.join(dest, file);
},
options: {
processContent: function (content, file) {
var comment = grunt.config('BUILD_COMMENT');
if (grunt.file.isMatch({matchBase: true}, '*.css', file)) {
content = '/* ' + comment + ' */\n' + content;
} else if (grunt.file.isMatch({matchBase: true}, '*.html', file)) {
content = '<!-- ' + comment + ' -->\n' + content;
}
return content;
}
}
} }
}, },
@ -80,7 +55,6 @@ grunt.initConfig({
]}, ]},
{'build/forms-nr.css': [ {'build/forms-nr.css': [
'build/forms-core.css',
'build/forms.css' 'build/forms.css'
]}, ]},
@ -143,11 +117,7 @@ grunt.initConfig({
}, },
src: { src: {
src: [ src: 'src/**/css/*.css'
'src/**/css/*.css',
'!src/base/css/*',
'!src/forms/css/forms-core.css'
]
} }
}, },
@ -175,8 +145,12 @@ grunt.initConfig({
expand : true, expand : true,
flatten: true, flatten: true,
src : 'build/*.css', dest : '<%= pkg.name %>/<%= pkg.version %>/',
dest : '<%= pkg.name %>/<%= pkg.version %>/'
src: [
'{bower.json,LICENSE.md,README.md,HISTORY.md}',
'build/*.css'
]
} }
}, },
@ -187,7 +161,7 @@ grunt.initConfig({
options: { options: {
banner: [ banner: [
'/*!', '/*!',
'normalize.css v<%= normalize.version %> | MIT License | git.io/normalize', 'normalize.css v1.1.2 | MIT License | git.io/normalize',
'Copyright (c) Nicolas Gallagher and Jonathan Neal', 'Copyright (c) Nicolas Gallagher and Jonathan Neal',
'*/\n' '*/\n'
].join('\n') ].join('\n')
@ -219,12 +193,11 @@ grunt.initConfig({
contextualize: { contextualize: {
normalize: { normalize: {
src : 'src/base/css/normalize.css', src : 'bower_components/normalize-css/normalize.css',
dest: 'src/base/css/normalize-context.css', dest: 'build/base-context.css',
options: { options: {
prefix: '.pure', prefix: '.pure'
banner: '/* <%= BUILD_COMMENT %> */\n'
} }
} }
}, },
@ -234,7 +207,7 @@ grunt.initConfig({
observe: { observe: {
src: { src: {
files: 'src/**/css/*.css', files: 'src/**/css/*.css',
tasks: ['test', 'suppress', 'default'], tasks: ['test', 'suppress', 'build'],
options: { options: {
interrupt: true interrupt: true
@ -253,9 +226,13 @@ grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-compress'); grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', [ grunt.registerTask('default', ['import', 'test', 'build']);
grunt.registerTask('import', ['bower-install']);
grunt.registerTask('test', ['csslint']);
grunt.registerTask('build', [
'clean:build', 'clean:build',
'copy:build', 'copy:build',
'contextualize:normalize',
'concat:build', 'concat:build',
'clean:build_res', 'clean:build_res',
'cssmin', 'cssmin',
@ -263,21 +240,11 @@ grunt.registerTask('default', [
'license' 'license'
]); ]);
grunt.registerTask('test', [
'csslint'
]);
// Makes the `watch` task run a build first. // Makes the `watch` task run a build first.
grunt.renameTask('watch', 'observe'); grunt.renameTask('watch', 'observe');
grunt.registerTask('watch', ['default', 'observe']); grunt.registerTask('watch', ['default', 'observe']);
grunt.registerTask('import', [
'bower-install',
'import-normalize'
]);
grunt.registerTask('release', [ grunt.registerTask('release', [
'test',
'default', 'default',
'clean:release', 'clean:release',
'compress:release' 'compress:release'
@ -303,14 +270,6 @@ grunt.registerTask('suppress', function () {
}); });
}); });
// -- Import Tasks -------------------------------------------------------------
grunt.registerTask('import-normalize', [
'clean:base',
'copy:normalize',
'contextualize:normalize'
]);
// -- Bower Task --------------------------------------------------------------- // -- Bower Task ---------------------------------------------------------------
grunt.registerTask('bower-install', 'Installs Bower dependencies.', function () { grunt.registerTask('bower-install', 'Installs Bower dependencies.', function () {
@ -318,8 +277,17 @@ grunt.registerTask('bower-install', 'Installs Bower dependencies.', function ()
done = this.async(); done = this.async();
bower.commands.install() bower.commands.install()
.on('data', function (data) { grunt.log.write(data); }) .on('log', function (data) {
.on('end', done); if (data.id !== 'install') { return; }
grunt.log.writeln('bower ' + data.id.cyan + ' ' + data.message);
})
.on('end', function (results) {
if (!Object.keys(results).length) {
grunt.log.writeln('No bower packages to install.');
}
done();
});
}); });
// -- License Task ------------------------------------------------------------- // -- License Task -------------------------------------------------------------
@ -355,6 +323,11 @@ grunt.registerMultiTask('contextualize', 'Makes Contextualized CSS files.', func
} }
this.files.forEach(function (filePair) { this.files.forEach(function (filePair) {
if (!filePair.src.length) {
processing += 1;
return oneDone();
}
filePair.src.forEach(function (file) { filePair.src.forEach(function (file) {
var src = grunt.file.read(file), var src = grunt.file.read(file),
contextual = banner, contextual = banner,