ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit 2a293f506a1e4a8bc381b6a790a0b47b4d1bab57
parent be2a130f08752639fefcab2158c2593dc641c434
Author: Vladimir Kutepov <frenzzy.man@gmail.com>
Date:   Thu, 15 Dec 2016 15:46:13 +0300

Add ignore initial flag for watcher in copy task

Diffstat:
Mtools/copy.js | 10+++++++---
Mtools/run.js | 2+-
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/copy.js b/tools/copy.js @@ -11,6 +11,7 @@ import path from 'path'; import chokidar from 'chokidar'; import { writeFile, copyFile, makeDir, copyDir, cleanDir } from './lib/fs'; import pkg from '../package.json'; +import { format } from './run'; /** * Copies static files such as robots.txt, favicon.ico to the @@ -36,25 +37,28 @@ async function copy() { const watcher = chokidar.watch([ 'src/content/**/*', 'public/**/*', - ]); + ], { ignoreInitial: true }); watcher.on('all', async (event, filePath) => { + const start = new Date(); const src = path.relative('./', filePath); const dist = path.join('build/', src.startsWith('src') ? path.relative('src', src) : src); switch (event) { case 'add': case 'change': - if (filePath.endsWith('/')) return; await makeDir(path.dirname(dist)); await copyFile(filePath, dist); break; case 'unlink': + case 'unlinkDir': cleanDir(dist, { nosort: true, dot: true }); break; default: return; } - console.log(`[file ${event}] ${dist}`); + const end = new Date(); + const time = end.getTime() - start.getTime(); + console.log(`[${format(end)}] ${event} '${dist}' after ${time} ms`); }); } } diff --git a/tools/run.js b/tools/run.js @@ -7,7 +7,7 @@ * LICENSE.txt file in the root directory of this source tree. */ -function format(time) { +export function format(time) { return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1'); }