I'm new to gulp. I'm using a gulp task to do an AWS publish. Before publishing, I want to rename all html files with no extension (i.e., remove extensions).
Then publish the content with two different headers in order to force content-type to 'text/html' for HTML files.
- IF the file is html (which I already removed the html extension) then use htmlHeaders where content-type is mentioned as 'text/html',
- ELSE use normalHeaders where no content-type is used.
Since I have already removed that .html file extension, I couldn't find the condition to do publish based on any condition.
The code below removes the html extension, but don't add different headers based on file type. How do I pipe publisher.publish(htmlHeaders) or publisher.publish(normalHeaders) based on file types?
gulp.task('aws-staging-main', function () {
var publisher = awspublish.create(
{
region: "us-east-1",
params: {
Bucket: "<my bucket>"
},
accessKeyId: "<my access key>",
secretAccessKey: "<my secret access key>"
}
);
var normalHeaders = {
"Cache-Control": "max-age=315360000, no-transform, public",
};
var htmlHeaders = {
"Cache-Control": "max-age=315360000, no-transform, public",
'Content-Type': 'text/html; charset=utf-8'
};
var cfSettings = {
distribution: '<my distribution>',
accessKeyId: "<my key>",
secretAccessKey: "<my secret key>",
wait: true,
originPath: '/dist',
}
return (
gulp.src(Paths.DIST_ALL)
.pipe(rename(function (path){
if( path.extname === '.html')
path.extname = "";
}))
.pipe(publisher.publish(normalHeaders));
.pipe(cloudfront(cfSettings))
.pipe(awspublish.reporter())
);
})