[英]Gulp RSync - Save progress to log file
I've been using gulp-rsync for deploying static assets to my server via gulp task. 我一直在使用gulp-rsync通过gulp任务将静态资产部署到服务器。 And I use incremental option to determine whether a file needs to be updated or not.
我使用增量选项来确定文件是否需要更新。 This works fine :)
这很好用:)
I need save the progress displayed in the console in a file or whatever.. Because i need purge individual files in the cache on cloudflare :/ 我需要将控制台中显示的进度保存到文件或其他文件中。.因为我需要清除 cloudflare 缓存中的单个文件 :/
Looks like that ( in the console ): 看起来像( 在控制台中 ):
[20:49:52] Starting 'rsync'...
[20:49:53] gulp-rsync: Starting rsync to my-ssh-hostname:/example/public-html/assets/...
[20:49:55] gulp-rsync: sending incremental file list
[20:49:57] gulp-rsync: favicon.ico
[20:49:57] gulp-rsync: 1150 100% 439.45kB/s 0:00:00 (xfer#1, to-check=12/13)
[20:49:57] gulp-rsync: css/main.css
[20:49:57] gulp-rsync: 2712 100% 101.86kB/s 0:00:00 (xfer#2, to-check=11/13)
[20:49:57] gulp-rsync: css/style.css
[20:49:57] gulp-rsync: 1445 100% 54.27kB/s 0:00:00 (xfer#3, to-check=9/13)
[20:49:57] gulp-rsync: js/app.js
[20:49:57] gulp-rsync: 31878 100% 1.09MB/s 0:00:00 (xfer#7, to-check=3/13)
[20:49:57] gulp-rsync: scripts.js
[20:50:01] gulp-rsync: 76988 100% 2.53MB/s 0:00:00 (xfer#9, to-check=1/13)
[20:50:01] gulp-rsync: sent 2401 bytes received 2820 bytes 10442.00 bytes/sec
[20:50:02] gulp-rsync: total size is 10106 speedup is 4.37
[20:50:02] gulp-rsync: Finished 'rsync' after 3.38 s
I need save and extract the files in log: 我需要保存并提取日志文件:
favicon.ico,
css/main.css,
css/style.css,
js/app.js,
scripts.js
-- My original " gulpfile.js " : -我原来的“ gulpfile.js ”:
var
gulp = require('gulp'),
gutil = require('gulp-util'),
rsync = require('gulp-rsync'),
logCapture = require('gulp-log-capture');
var config = {
hostname : 'my-ssh-hostname',
destination : '/example/public-html/assets/',
progress: true,
incremental: true,
relative: true,
emptyDirectories: true,
recursive: true,
clean: true,
exclude: ['._', '.DS_Store' , 'thumbs.db', 'desktop.ini'],
chmod: '775',
};
gulp.task('rsync', function (){
return gulp.src('./my-local-dir/' + '**/*')
.pipe(rsync(config))
});
-- I found the " Log Capture Plugin for Gulp " - gulp-log-capture -我找到了“ 用于Gulp的日志捕获插件 ” -gulp-log-capture
What's the right way to use? 什么是正确的使用方式? :/
:/
gulp.task('rsync', function (){
return gulp.src('./my-local-dir/' + '**/*')
.pipe(logCapture.start(process.stdout, 'write'))
.pipe(rsync(config))
.pipe(logCapture.stop('txt'))
.pipe(gulp.dest('./dest'));
});
Any sugestions will be apreciated :) 任何建议都会被加深:)
You cannot use gulp-log-capture
for this because of the way that gulp-rsync
works. 由于
gulp-rsync
工作方式,您不能为此使用gulp-log-capture
。
gulp-rsync
waits until it has collected all the file names before it invokes rsync
. gulp-rsync
会等到它收集了所有文件名后再调用rsync
。 Otherwise it would have to call rsync
for each individual file which would severely degrade performance. 否则,它必须为每个文件调用
rsync
,这将严重降低性能。
So by the time that rsync
is invoked logCapture
has already stopped capturing the log output. 因此,在调用
rsync
时, logCapture
已经停止捕获日志输出。
You need to listen for the 'end'
event and capture the log output yourself by substituting process.stdout.write()
with a function of your own (which is what gulp-log-capture
does): 您需要侦听
'end'
事件并通过用您自己的函数替换process.stdout.write()
自己捕获日志输出(这是gulp-log-capture
作用):
gulp.task('rsync', function (){
var logOutput = "";
var stdoutWrite;
return gulp.src('./my-local-dir/' + '**/*')
.on('end', function() {
stdoutWrite = process.stdout.write;
process.stdout.write = function(output) { logOutput += output; };
})
.pipe(rsync(config))
.on('end', function() {
process.stdout.write = stdoutWrite;
process.stdout.write(logOutput);
fs.writeFileSync('./dest/logOutput.txt', new Buffer(logOutput));
});
});
This stores the progress log generated by rsync
in the logOutput
variable and writes it to the file ./dest/logOutput.txt
. 这会将
rsync
生成的进度日志存储在logOutput
变量中,并将其写入文件./dest/logOutput.txt
。
Extracting the files names from logOutput
is now just a matter of coming up with the appropriate regexes. 现在,从
logOutput
提取文件名logOutput
是提供适当的正则表达式的问题。 I'll leave that part to you. 我会把那部分留给你。 If this gives you trouble, it's probably best to ask the people over in regex .
如果这给您带来麻烦,最好是用正则表达式来问问人们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.