Cofey
Cofey

Reputation: 11404

Including current year in Header file with Gulp Header

Is there anyway to print out the current year in a header file using Gulp Header?

Here's an example of what I'd like to do:

var banner = ['/**',
  ' * Copyright (c) 2014 Cofey',
  ' * <%= pkg.name %> - <%= pkg.description %>',
  ' * @version v<%= pkg.version %>',
  ' * @link <%= pkg.homepage %>',
  ' * @license <%= pkg.license %>',
  ' */',
  ''].join('\n');

Upvotes: 5

Views: 2576

Answers (2)

AxeEffect
AxeEffect

Reputation: 7471

Since Node.js 4.4.1 ES6 template literals are supported:

var banner = `/**
 * Copyright (c) ${new Date().getFullYear()} Cofey
 * ${pkg.name} - ${pkg.description}
 * @version v${pkg.version}
 * @link ${pkg.homepage}
 * @license ${pkg.license}
 */\n`;

Upvotes: 0

circusbred
circusbred

Reputation: 1240

Looks like gulp uses lodash templates; you should be able to include arbitrary JavaScript:

var banner = ['/**',
  ' * Copyright (c) <%= new Date().getFullYear() %> Cofey',
  ' * <%= pkg.name %> - <%= pkg.description %>',
  ' * @version v<%= pkg.version %>',
  ' * @link <%= pkg.homepage %>',
  ' * @license <%= pkg.license %>',
  ' */',
  ''].join('\n');

Upvotes: 6

Related Questions