Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 知乎專欄 | 視頻教程 | About

4.13. 檔案頭

		
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