-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
94a208a
commit 582c3f3
Showing
12 changed files
with
173 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
import type {Framework, Server} from '@roots/bud-framework' | ||
import {chalk} from '@roots/bud-support' | ||
|
||
export interface watch { | ||
(files: Server.Configuration['watch']['files']): Framework | ||
( | ||
files: Server.Configuration['watch']['files'], | ||
options?: Server.Configuration['watch']['options'], | ||
): Framework | ||
} | ||
|
||
export const watch: watch = function (files) { | ||
/** | ||
* Set files that, when modified, will force the browser to reload. | ||
* | ||
* @remarks | ||
* Modifying these files will cause a full page reload, even in hot mode. | ||
* | ||
* @example | ||
* ```js | ||
* app.watch(['templates/*.html']) | ||
* ``` | ||
* | ||
* @example | ||
* Set chokidar options as well: | ||
* | ||
* ```js | ||
* app.watch(['templates/*.html'], { | ||
* // chokidar options | ||
* }) | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
export const watch: watch = function (files, options = {}) { | ||
const ctx = (this.root as Framework) ?? (this as Framework) | ||
|
||
if (!ctx.isDevelopment) { | ||
ctx.api.log('log', { | ||
message: 'skipping watch files', | ||
suffix: 'production mode is set', | ||
}) | ||
return ctx | ||
} | ||
files = Array.isArray(files) ? files : [files] | ||
|
||
ctx.store.set( | ||
'server.watch.files', | ||
Array.isArray(files) ? files : [files], | ||
) | ||
|
||
ctx.api.log('success', { | ||
message: `watch files added`, | ||
suffix: chalk.dim(files.join(', ')), | ||
}) | ||
ctx.store | ||
.merge('server.watch.files', files) | ||
.merge('server.watch.options', options) | ||
|
||
return ctx | ||
} |
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
20 changes: 20 additions & 0 deletions
20
tests/unit/bud-api/repository/__snapshots__/watch.test.ts.snap
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ Object { | |
}, | ||
"watch": Object { | ||
"files": Array [], | ||
"options": Object {}, | ||
}, | ||
} | ||
`; |
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