123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
-
-
- 'use strict';
-
- module.exports = function(grunt) {
-
-
- var comment = require('./lib/comment').init(grunt);
- var chalk = require('chalk');
- var sourcemap = require('./lib/sourcemap').init(grunt);
-
- grunt.registerMultiTask('concat', 'Concatenate files.', function() {
-
- var options = this.options({
- separator: grunt.util.linefeed,
- banner: '',
- footer: '',
- stripBanners: false,
- process: false,
- sourceMap: false,
- sourceMapName: undefined,
- sourceMapStyle: 'embed'
- });
-
-
- if (options.stripBanners === true) { options.stripBanners = {}; }
- if (options.process === true) { options.process = {}; }
-
-
- var banner = grunt.template.process(options.banner);
- var footer = grunt.template.process(options.footer);
-
-
- var sourceMap = options.sourceMap;
-
-
-
- if (
- sourceMap && options.sourceMapStyle === 'link' &&
- (options.stripBanners || options.process)
- ) {
-
- grunt.warn(
- 'stripBanners or process option is enabled. ' +
- 'Set sourceMapStyle option to \'embed\' or \'inline\'.'
- );
-
- grunt.log.warn('Skipping creation of source maps.');
-
- sourceMap = false;
- }
-
-
- this.files.forEach(function(f) {
-
- var sourceMapHelper;
- if (sourceMap) {
- sourceMapHelper = sourcemap.helper(f, options);
- sourceMapHelper.add(banner);
- }
-
-
- var src = banner + f.src.filter(function(filepath) {
-
- if (!grunt.file.exists(filepath)) {
- grunt.log.warn('Source file "' + filepath + '" not found.');
- return false;
- } else {
- return true;
- }
- }).map(function(filepath, i) {
- if (grunt.file.isDir(filepath)) {
- return;
- }
-
- var src = grunt.file.read(filepath);
-
- if (typeof options.process === 'function') {
- src = options.process(src, filepath);
- } else if (options.process) {
- src = grunt.template.process(src, options.process);
- }
-
- if (options.stripBanners) {
- src = comment.stripBanner(src, options.stripBanners);
- }
-
- if (sourceMapHelper) {
- src = sourceMapHelper.addlines(src, filepath);
- if (i < f.src.length - 1) {
- sourceMapHelper.add(options.separator);
- }
- }
- return src;
- }).join(options.separator) + footer;
-
- if (sourceMapHelper) {
- sourceMapHelper.add(footer);
- sourceMapHelper.write();
-
- src += sourceMapHelper.url();
- }
-
-
- grunt.file.write(f.dest, src);
-
-
- grunt.log.writeln('File ' + chalk.cyan(f.dest) + ' created.');
- });
- });
-
- };
|