forked from gruntjs/grunt
/
name.js
51 lines (41 loc) · 1.58 KB
/
name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* {%= name %}
* {%= homepage %}
*
* Copyright (c) {%= grunt.template.today('yyyy') %} {%= author_name %}
* Licensed under the {%= licenses.join(', ') %} license{%= licenses.length === 1 ? '' : 's' %}.
*/
'use strict';
module.exports = function(grunt) {
// Please see the grunt documentation for more information regarding task
// creation: https://github.com/cowboy/grunt/blob/devel/docs/toc.md
grunt.registerMultiTask('{%= short_name %}', 'Your task description goes here.', function() {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
punctuation: '.',
separator: ', '
});
// Iterate over all specified file groups.
this.files.forEach(function(fileObj) {
// The source files to be concatenated. The "nonull" option is used
// to retain invalid files/patterns so they can be warned about.
var files = grunt.file.expand({nonull: true}, fileObj.src);
// Concat specified files.
var src = files.map(function(filepath) {
// Warn if a source file/pattern was invalid.
if (!grunt.file.exists(filepath)) {
grunt.log.error('Source file "' + filepath + '" not found.');
return '';
}
// Read file source.
return grunt.file.read(filepath);
}).join(options.separator);
// Handle options.
src += options.punctuation;
// Write the destination file.
grunt.file.write(fileObj.dest, src);
// Print a success message.
grunt.log.writeln('File "' + fileObj.dest + '" created.');
});
});
};