MCPcopy Create free account
hub / github.com/TanStack/cli / DevWatchManager

Class DevWatchManager

packages/cli/src/dev-watch.ts:83–565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83export class DevWatchManager {
84 private watcher: FSWatcher | null = null
85 private debounceQueue: DebounceQueue
86 private syncer: FileSyncer
87 private tempDir: string | null = null
88 private isBuilding = false
89 private buildCount = 0
90 private appDevProcess: ReturnType<typeof spawn> | null = null
91 private lastSyncedSourceFiles: Set<string> | null = null
92
93 constructor(private options: DevWatchOptions) {
94 this.syncer = new FileSyncer()
95 this.debounceQueue = new DebounceQueue((changes) => this.rebuild(changes))
96 }
97
98 async start(): Promise<void> {
99 // Validate watch path
100 if (!fs.existsSync(this.options.watchPath)) {
101 throw new Error(`Watch path does not exist: ${this.options.watchPath}`)
102 }
103
104 // Validate target directory exists (should have been created by createApp)
105 if (!fs.existsSync(this.options.targetDir)) {
106 throw new Error(
107 `Target directory does not exist: ${this.options.targetDir}`,
108 )
109 }
110
111 if (this.options.cliOptions.install === false) {
112 throw new Error('Cannot use the --no-install flag when using --dev-watch')
113 }
114
115 // Log startup with tree style
116 console.log()
117 console.log(chalk.bold('dev-watch'))
118 this.log.tree('', `watching: ${chalk.cyan(this.options.watchPath)}`)
119 this.log.tree('', `target: ${chalk.cyan(this.options.targetDir)}`)
120 if (this.options.runDevCommand) {
121 this.log.tree('', `app dev server: ${chalk.cyan('enabled')}`)
122 }
123 this.log.tree('', 'ready', true)
124
125 // Setup signal handlers
126 process.on('SIGINT', () => this.cleanup())
127 process.on('SIGTERM', () => this.cleanup())
128
129 // Start watching
130 this.startWatcher()
131
132 if (this.options.runDevCommand) {
133 this.startAppDevServer()
134 }
135 }
136
137 async stop(): Promise<void> {
138 console.log()
139 this.log.info('Stopping dev watch mode...')
140

Callers

nothing calls this directly

Calls 2

logMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected