Move local Grunt tasks to tasks/ dir

This commit is contained in:
Eric Ferraiuolo 2013-11-18 14:45:37 -05:00
parent bdc76d6fd0
commit 5cec523755
4 changed files with 65 additions and 58 deletions

View File

@ -213,6 +213,7 @@ grunt.initConfig({
// -- Main Tasks ---------------------------------------------------------------
// npm tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
@ -222,8 +223,11 @@ grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-css-selectors');
// Local tasks.
grunt.loadTasks('tasks/');
grunt.registerTask('default', ['import', 'test', 'build']);
grunt.registerTask('import', ['bower-install']);
grunt.registerTask('import', ['bower_install']);
grunt.registerTask('test', ['csslint']);
grunt.registerTask('build', [
'clean:build',
@ -245,61 +249,4 @@ grunt.registerTask('release', [
'compress:release'
]);
// -- Suppress Task ------------------------------------------------------------
grunt.registerTask('suppress', function () {
var allowed = ['success', 'fail', 'warn', 'error'];
grunt.util.hooker.hook(grunt.log, {
passName: true,
pre: function (name) {
if (allowed.indexOf(name) === -1) {
grunt.log.muted = true;
}
},
post: function () {
grunt.log.muted = false;
}
});
});
// -- Bower Tasks --------------------------------------------------------------
grunt.registerTask('bower-install', 'Installs Bower dependencies.', function () {
var bower = require('bower'),
done = this.async();
bower.commands.install()
.on('log', function (data) {
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 -------------------------------------------------------------
grunt.registerMultiTask('license', 'Stamps license banners on files.', function () {
var options = this.options({banner: ''}),
banner = grunt.template.process(options.banner),
tally = 0;
this.files.forEach(function (filePair) {
filePair.src.forEach(function (file) {
grunt.file.write(file, banner + grunt.file.read(file));
tally += 1;
});
});
grunt.log.writeln('Stamped license on ' + String(tally).cyan + ' files.');
});
};

21
tasks/bower_install.js Normal file
View File

@ -0,0 +1,21 @@
'use strict';
module.exports = function (grunt) {
grunt.registerTask('bower_install', 'Installs Bower dependencies.', function () {
var bower = require('bower'),
done = this.async();
bower.commands.install()
.on('log', function (data) {
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();
});
});
};

18
tasks/license.js Normal file
View File

@ -0,0 +1,18 @@
'use strict';
module.exports = function (grunt) {
grunt.registerMultiTask('license', 'Stamps license banners on files.', function () {
var options = this.options({banner: ''}),
banner = grunt.template.process(options.banner),
tally = 0;
this.files.forEach(function (filePair) {
filePair.src.forEach(function (file) {
grunt.file.write(file, banner + grunt.file.read(file));
tally += 1;
});
});
grunt.log.writeln('Stamped license on ' + String(tally).cyan + ' files.');
});
};

21
tasks/suppress.js Normal file
View File

@ -0,0 +1,21 @@
'use strict';
module.exports = function (grunt) {
grunt.registerTask('suppress', 'Suppresses noisy logs', function () {
var allowed = ['success', 'fail', 'warn', 'error'];
grunt.util.hooker.hook(grunt.log, {
passName: true,
pre: function (name) {
if (allowed.indexOf(name) === -1) {
grunt.log.muted = true;
}
},
post: function () {
grunt.log.muted = false;
}
});
});
};