Reputation: 965
I try to reproduce in Gulp something I could do with Grunt: Write a date to file the generation of the latter (Stylus -> CSS or Jade -> html).
Here's what I did with Grunt (with grunt-banner):
// *.Gruntfile.js
<%= grunt.template.today("yyyy-mm-dd H:MM:ss") %>
How under Gulp? And above all, what use plugin Gulp (I have not yet found equivalent to grunt-banner...)?
EDIT :
I looked toward gulp-header, and then I finally decided to gulp-replace. Indeed the first place banners in the header files but my goal was to replace existing information.
Example :
// Gulpfile.js
var pkg = require('./package.json'),
rename = require('gulp-rename');
gulp.task('templates', function() {
return gulp
.src(source + '/Styles/Header.styl')
.pipe(replace(/@-name .*\n/g, '@-name ' + pkg.name + '\n'))
.pipe(replace(/@-description .*\n/g, '@-description ' + pkg.description + '\n'))
.pipe(replace(/@-version .*\n/g, '@-version ' + pkg.version + '\n'))
.pipe(replace(/@-author .*\n/g, '@-author ' + pkg.author + '\n'))
.pipe(replace(/@-homepage .*\n/g, '@-homepage ' + pkg.homepage + '\n'))
.pipe(replace(/@-license .*\n/g, '@-license ' + pkg.license + '\n'))
.pipe(gulp.dest(source + '/Styles'))
});
But I still do not know how to put a date modified as under Grunt ...
Upvotes: 0
Views: 762
Reputation: 767
Alternativ:
var headerComment = require('gulp-header-comment');
and in pipe:
.pipe(headerComment(`Generated on: <%= moment().format('DD.MM.YY') %>`))
Upvotes: 0
Reputation: 965
All right, I found:
var versionDate = new Date(); // javascript, just
Moved in the context it gives:
gulp.task('templates', function() {
return gulp
.src(source + '/Styles/Header.styl')
.pipe(replace(/@name .*\n/g, '@name ' + pkg.name + '\n'))
.pipe(replace(/@description .*\n/g, '@description ' + pkg.description + '\n'))
.pipe(replace(/@version .*\n/g, '@version ' + pkg.version + '\n'))
.pipe(replace(/@lastmodified .*\n/g, '@lastmodified ' + versionDate + '\n'))
.pipe(replace(/@author .*\n/g, '@author ' + pkg.author + '\n'))
.pipe(replace(/@homepage .*\n/g, '@homepage ' + pkg.homepage + '\n'))
.pipe(replace(/@license .*\n/g, '@license ' + pkg.license + '\n'))
.pipe(gulp.dest(source + '/Styles'))
});
Upvotes: 1