Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

4.10. 文件头

		
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