利用gulp把本地文件移动到指定待发布文件夹

一、目标

把本地的文件移动到待发布的文件中,把static_grab文件中file.txt所列文件列表移动到beta对应文件夹中;

二、实现

var gulp = require('gulp'),
	webpack = require('webpack'),
	fs = require('fs'),
	debug = require('gulp-debug');


var file = './file.txt'
gulp.task('copybeta', function() {
	fs.readFile(file, function(err, obj){
		//console.log('err:', err)
		obj = obj.toString().replace(/s{2,}/g, '
').replace(/(^s+)|(s+$)/g, '').split('
')

		for(var i = 0; i< obj.length; i++){

			var srcFile = obj[i].replace(/s+/g,'')
            
			if(srcFile.indexOf('.') == -1){
				srcFile = srcFile + '/**/*.*'
			}
			console.log('dir:', srcFile)

			if(srcFile.indexOf('static_grab') != -1){
				gulp.src(srcFile, {base: './static_grab'})    
                        .pipe(debug({title: 'static_grab:'}))
                        .pipe(gulp.dest( fs.realpathSync('./beta/static_grab') ))
			}else{
				srcFile = srcFile.replace('grab/web/','')

				gulp.src(srcFile, {base: './html'})    
                        .pipe(debug({title: 'grab:'}))
                        .pipe(gulp.dest( fs.realpathSync('./beta/grab/web/html') ))
			}
            
		}
        
	})  


})

  

原文地址:https://www.cnblogs.com/leaf930814/p/8408854.html