Repository navigation
feat: add global specification watcher #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
58634a9
feat: add global specification watcher
imabp fdd4413
fix: temporary remove test for watch mode
imabp 300a068
fix:lint
imabp 3ae7505
fix: specfile to file
imabp 24f55c7
fix: edit change message for watcher
imabp 755e1ac
fix: change watch flag description
imabp 3f29110
feat: add watcher in diff
imabp 2458b90
Merge branch 'master' of https://github.com/asyncapi/cli into imabp-w…
imabp 2cf0aa5
fix: refactor watcher configuration
imabp 3f94bc9
fix: code smell
imabp aa0db23
fix: refactor watch command.
imabp 5cae99b
feat: auto-disable watch mode for web URLs
imabp bef53f7
Merge branch 'master' into imabp-watch
imabp 71afd18
fix: merge conflicts
imabp a91f94d
fix: update log messages
imabp 15d58ca
fix: change log color
imabp 89b88a9
fix: make log color private
imabp 87e8023
fix: remove unused red log
imabp 4e88942
fix: disable watch for web urls in validate
imabp 0f791e7
fix: refactor auto-disable log
imabp 4600880
fix: fix multiple watch instances
imabp 8c6cdf9
feat: add conditional logs for watcher
imabp 470fc7d
Remove ConditionalNestedLogs
imabp 056a712
Add conditional log to watch_messages natively.
imabp e60126e
fix: update function signature
imabp 79580fb
fix: update conditional check for chokidar
imabp f80690f
feat: Chokidar Instance Store
imabp 7694cf4
fix: use map to store instances.
imabp 84ec9ff
fix: remove start message
imabp aa42efd
feat: extend support for node versions
imabp 3b5651a
fix: refactor watcher
imabp 64f57d0
Merge branch 'master' into imabp-watch
magicmatatjahu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
| import { flags } from '@oclif/command'; | ||
|
|
||
| export const watchFlag = flags.boolean({ | ||
| char: 'w', | ||
| description: 'Enable watch mode' | ||
| }); | ||
This file contains hidden or 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,50 @@ | ||
| import chokidar from 'chokidar'; | ||
| import chalk from 'chalk'; | ||
| import Command from './base'; | ||
| import { Specification } from './models/SpecificationFile'; | ||
|
|
||
| const GreenLog = chalk.hex('#00FF00'); | ||
| const OrangeLog = chalk.hex('#FFA500'); | ||
| const CHOKIDAR_CONFIG = { | ||
| // awaitWriteFinish: true // Used for large size specification files. | ||
|
|
||
| }; | ||
| const WATCH_MESSAGES = { | ||
| logOnStart: (filePath: string) => console.log(GreenLog(`Watching AsyncAPI file at ${filePath}\n`)), | ||
| logOnChange: (handlerName: string) => console.log(OrangeLog(`Change detected, running ${handlerName}\n`)), | ||
| logOnAutoDisable: (docVersion: 'old' | 'new' | '' = '') => console.log(OrangeLog(`Watch mode for ${docVersion || 'AsyncAPI'} file was not enabled.`), OrangeLog('\nINFO: Watch works only with files from local file system\n')) | ||
| }; | ||
|
|
||
| const CHOKIDAR_INSTANCE_STORE = new Map<string, boolean>(); | ||
|
|
||
| export type specWatcherParams = { | ||
| spec: Specification, | ||
| handler: Command, | ||
| handlerName: string, | ||
| label?: string, | ||
| docVersion?: 'old' | 'new'; | ||
| } | ||
|
|
||
| export const specWatcher = (params: specWatcherParams) => { | ||
| if (!params.spec.getFilePath()) { return WATCH_MESSAGES.logOnAutoDisable(params.docVersion); } | ||
| if (CHOKIDAR_INSTANCE_STORE.get(params.label || '_default')) { return; } | ||
|
|
||
| const filePath = params.spec.getFilePath() as string; | ||
| try { | ||
| WATCH_MESSAGES.logOnStart(filePath); | ||
| chokidar | ||
| .watch(filePath, CHOKIDAR_CONFIG) | ||
| .on('change', async () => { | ||
| WATCH_MESSAGES.logOnChange(params.handlerName); | ||
| try { | ||
| await params.handler.run(); | ||
| } catch (err) { | ||
| await params.handler.catch(err); | ||
| } | ||
| }); | ||
| CHOKIDAR_INSTANCE_STORE.set(params.label || '_default', true); | ||
| } catch (error) { | ||
| console.log(error); | ||
| } | ||
| }; | ||
|
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.