Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
gulp-header
Advanced tools
The gulp-header npm package is a Gulp plugin that allows you to add headers to your files. This can be useful for adding comments, metadata, or any other text at the beginning of your files during the build process.
Add a simple header
This feature allows you to add a simple header to your files. The example code adds a comment with the project name, version, and current date to the top of all JavaScript files in the 'src' directory and outputs them to the 'dist' directory.
const gulp = require('gulp');
const header = require('gulp-header');
const banner = '/* My Project - v1.0.0 - ' + new Date().toISOString() + ' */\n';
gulp.task('add-header', function() {
return gulp.src('src/*.js')
.pipe(header(banner))
.pipe(gulp.dest('dist'));
});
Add a header with dynamic content
This feature allows you to add a header with dynamic content using template strings. The example code uses data from the package.json file to create a header with the project name, version, description, and author.
const gulp = require('gulp');
const header = require('gulp-header');
const pkg = require('./package.json');
const banner = ['/**',
' * <%= pkg.name %> - <%= pkg.version %>',
' * <%= pkg.description %>',
' * (c) ' + new Date().getFullYear() + ' <%= pkg.author %>',
' */',
''].join('\n');
gulp.task('add-header', function() {
return gulp.src('src/*.js')
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('dist'));
});
The gulp-footer package is similar to gulp-header but adds footers to files instead of headers. It can be used in conjunction with gulp-header to add both headers and footers to your files.
The gulp-preprocess package allows you to preprocess files with directives and variables. While it is more general-purpose than gulp-header, it can be used to add headers to files as part of a larger preprocessing task.
The gulp-insert package provides more general text insertion capabilities, allowing you to insert text at the beginning, end, or any position within a file. It can be used to add headers, but also offers more flexibility for other text manipulation tasks.
gulp-header is a Gulp extension to add a header to file(s) in the pipeline. Gulp is a streaming build system utilizing node.js.
npm install --save-dev gulp-header
// assign the module to a local variable
var header = require('gulp-header');
// literal string
// NOTE: a line separator will not be added automatically
gulp.src('./foo/*.js')
.pipe(header('Hello'))
.pipe(gulp.dest('./dist/'))
// ejs style templating
gulp.src('./foo/*.js')
.pipe(header('Hello <%= name %>\n', { name : 'World'} ))
.pipe(gulp.dest('./dist/'))
// ES6-style template string
gulp.src('./foo/*.js')
.pipe(header('Hello ${name}\n', { name : 'World'} ))
.pipe(gulp.dest('./dist/'))
// using data from package.json
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
gulp.src('./foo/*.js')
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./dist/'))
// reading the header file from disk
var fs = require('fs');
gulp.src('./foo/*.js')
.pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg : pkg } ))
.pipe(gulp.dest('./dist/'))
// for use with coffee-script
return gulp.src([
'src/*.coffee',
])
.pipe(header(banner, { pkg : pkg } ))
.pipe(sourcemaps.init()) // init sourcemaps *after* header
.pipe(coffee({
bare: true
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/js'))
My handle on twitter is @tracker1 - If there is an urgent issue, I get twitter notifications sent to my phone.
Type: String
Default: ''
The template text.
Type: Object
Default: {}
The data object used to populate the text.
In addition to the passed in data, file
will be the stream object for the file being templated against and filename
will be the path relative from the stream's basepath.
NOTE: using false
will disable template processing of the header
FAQs
Gulp extension to add header to file(s) in the pipeline.
We found that gulp-header demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.