misc: make copyUntypedFiles work for watch mode (#7445)

This commit is contained in:
Joshua Chen 2022-05-18 19:18:32 +08:00 committed by GitHub
parent 5c3d3cfef1
commit 6b53d4263d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 71 additions and 187 deletions

View file

@ -0,0 +1,36 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs-extra';
import path from 'path';
import chokidar from 'chokidar';
const srcDir = path.join(process.cwd(), 'src');
const libDir = path.join(process.cwd(), 'lib');
const ignoredPattern = /(?:__tests__|\.tsx?$)/;
async function copy() {
await fs.copy(srcDir, libDir, {
filter(testedPath) {
return !ignoredPattern.test(testedPath);
},
});
}
if (process.argv.includes('--watch')) {
const watcher = chokidar.watch(srcDir, {
ignored: ignoredPattern,
ignoreInitial: true,
persistent: true,
});
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) =>
watcher.on(event, copy),
);
} else {
await copy();
}