標籤:body cfile blog 目標 htm for real bpa 指定
一、目標
把本地的檔案移動到待發布的檔案中,把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, ‘\n‘).replace(/(^\s+)|(\s+$)/g, ‘‘).split(‘\n‘)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‘) ))} } }) })
利用gulp把本地檔案移動到指定待發布檔案夾