This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c45307
commit 53b3ffa
Showing
12 changed files
with
230 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './watcher'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { WatcherOptions } from 'watchpack'; | ||
|
||
import { logger } from '@nrwl/devkit'; | ||
import Watchpack = require('watchpack'); | ||
|
||
export type WatchFunc<T = unknown> = () => Promise<T>; | ||
|
||
export type Options = Omit<WatcherOptions, 'ignored'> & { | ||
dir: string; | ||
watch?: boolean; | ||
}; | ||
|
||
export async function watcher(func: WatchFunc, options: Options) { | ||
const { dir, watch, ...watcherOptions } = options; | ||
|
||
if (watch === true) { | ||
const wp = new Watchpack({ | ||
...watcherOptions, | ||
ignored: [ | ||
'.eslintrc.json', | ||
'.lib.swcrc', | ||
'**/.codegen', | ||
'**/.git', | ||
'**/.mesh', | ||
'**/node_modules', | ||
'jest.config.ts', | ||
'project.json', | ||
], | ||
}); | ||
|
||
wp.watch({ directories: [dir], startTime: 0 }); | ||
|
||
wp.on('aggregated', async () => { | ||
await func(); | ||
|
||
logger.info(''); | ||
logger.info(''); | ||
logger.info('Watching for changes...'); | ||
}); | ||
|
||
await new Promise<{ success: boolean }>(() => { | ||
// This Promise intentionally never resolves, leaving the process running. | ||
}); | ||
} else { | ||
await func(); | ||
} | ||
} |
Oops, something went wrong.