mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
misc: make copyUntypedFiles work for watch mode (#7445)
This commit is contained in:
parent
5c3d3cfef1
commit
6b53d4263d
51 changed files with 71 additions and 187 deletions
36
admin/scripts/copyUntypedFiles.mjs
Normal file
36
admin/scripts/copyUntypedFiles.mjs
Normal 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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue