Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature - Add Header with each file name #115

Closed
wants to merge 1 commit into from

Conversation

jcalvor
Copy link

@jcalvor jcalvor commented Feb 25, 2016

'addHeader' lines with the name of each file to identify each file in
the 'bundle' final file.

'addHeader' lines with the name of each file to identify each file in
the 'bundle' final file.
@yocontra
Copy link
Member

Use gulp-header?

@jcalvor
Copy link
Author

jcalvor commented Feb 26, 2016

Hi there!, I saw gulp-header but this adds more work at the end of the day we usually need something fast and that it can be optional like this idea.
This specific feature lets you add a new line on top of every file with the name of that file. It takes the files names without the need of setting variables like gulp-header does for every file, the same concat pluggin provides the variable. This helps to keep track of big data files and to track information/bugs from that big file without the time consuming of the other plugging. You just add a group of files and concat them and that's it.

var concat = require('gulp-concat');

gulp.task('scripts', function() {
return gulp.src(['./lib/.js'])
.pipe(concat('bundle.css', {addHeaders: function(fileName, src) {
return '/
* '+fileName+' **/\n' + src;
}}))
.pipe(gulp.dest('./dist'));
});

here is the beauty of it, you can set the option to add the new line with the name of every file that its been concatenating and you can add this with a comment as a comment for any language: js, css, sql or anything as long as you surround the comment with the proper delimiters.

At the end you only have a 3 line extra code in the pluggin that is optional:
if (opt.addHeaders){
file.contents = new Buffer(opt.addHeaders(file.relative, file.contents));
}

more that adding a "simple header", it is identifying all the files in one. I guess if you want you can change the name, because I think it is more powerful than just adding a "header". Does that make sense? I hope you like it. I think your work is really good.

@yocontra
Copy link
Member

You can use templating in your header - set the header to // ${file.name} and it will add the comment to the top of each file, then pipe to concat. gulp has a philosophy that plugins do one thing well, so this feature won't end up in concat.

@yocontra yocontra closed this Feb 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants