Using gulp-header and Node’s file system npm install --save-dev gulp-header
Copyright 標頭檔
# vim Copyright /* Author: netkiller <netkiller@msn.com> Website: https://www.netkiller.cn Version: <%= version %> */
Version 檔案
# vim Version 1.0.0
gulpfile.js:
// including plugins var gulp = require('gulp') , fs = require('fs') , concat = require("gulp-concat") , header = require("gulp-header"); // functions // Get version using NodeJs file system var getVersion = function () { return fs.readFileSync('Version'); }; // Get copyright using NodeJs file system var getCopyright = function () { return fs.readFileSync('Copyright'); }; // task gulp.task('concat-copyright-version', function () { gulp.src('./javascript/*.js') .pipe(concat('finaly.js')) // concat and name it "concat-copyright-version.js" .pipe(header(getCopyrightVersion(), {version: getVersion()})) .pipe(gulp.dest('path/to/destination')); });
Run:
gulp concat-copyright-version