@@ -162,6 +162,12 @@ export type CMSPluginOptions = {
162
162
* Adjust console output verbosity. Default is `'info'`.
163
163
*/
164
164
logLevel ?: 'info' | 'warn' | 'error' | 'silent' | 'debug' ;
165
+
166
+ /**
167
+ * Whether to enable/disable file watching in dev (e.g. for generating
168
+ * `root-cms.d.ts`). Defaults to `true`.
169
+ */
170
+ watch ?: boolean ;
165
171
} ;
166
172
167
173
export type CMSPlugin = Plugin & {
@@ -433,18 +439,6 @@ export function cmsPlugin(options: CMSPluginOptions): CMSPlugin {
433
439
cms : path . resolve ( __dirname , './app.js' ) ,
434
440
} ) ,
435
441
436
- /**
437
- * Watches for .schema.ts file changes and generates a root-cms.d.ts file.
438
- */
439
- onFileChange : (
440
- eventName : 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir' ,
441
- filepath : string
442
- ) => {
443
- if ( filepath . endsWith ( '.schema.ts' ) ) {
444
- generateTypes ( ) ;
445
- }
446
- } ,
447
-
448
442
/**
449
443
* Attaches CMS-specific middleware to the Root.js server.
450
444
*/
@@ -588,6 +582,22 @@ export function cmsPlugin(options: CMSPluginOptions): CMSPlugin {
588
582
} ,
589
583
} ;
590
584
585
+ if ( options . watch !== false ) {
586
+ plugin . onFileChange = (
587
+ eventName : 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir' ,
588
+ filepath : string
589
+ ) => {
590
+ if ( filepath . endsWith ( '.schema.ts' ) ) {
591
+ // Avoid loading the `generate-types.js` module if it is not needed.
592
+ // See: https://github.com/blinkk/rootjs/issues/426
593
+ import ( '../cli/generate-types.js' ) . then ( ( generateTypesModule ) => {
594
+ const generateTypes = generateTypesModule . generateTypes ;
595
+ generateTypes ( ) ;
596
+ } ) ;
597
+ }
598
+ } ;
599
+ }
600
+
591
601
return plugin ;
592
602
}
593
603
0 commit comments