UNPKG

1.07 kBJavaScriptView Raw
1/*
2 * grunt
3 * https://github.com/cowboy/grunt
4 *
5 * Copyright (c) 2012 "Cowboy" Ben Alman
6 * Licensed under the MIT license.
7 * http://benalman.com/about/license/
8 */
9
10// ============================================================================
11// TASKS
12// ============================================================================
13
14task.registerBasicTask('concat', 'Concatenate files.', function(data, name) {
15 // Concat specified files.
16 var files = file.expand(data);
17 file.write(name, task.helper('concat', files));
18
19 // Fail task if errors were logged.
20 if (task.hadErrors()) { return false; }
21
22 // Otherwise, print a success message.
23 log.writeln('File "' + name + '" created.');
24});
25
26// ============================================================================
27// HELPERS
28// ============================================================================
29
30// Concat source files.
31task.registerHelper('concat', function(files) {
32 return files ? files.map(function(filepath) {
33 return task.directive(filepath, file.read);
34 }).join('\n') : '';
35});