22import * as Chokidar from 'chokidar'
33import * as Process from 'node:process'
44import * as Crypto from 'node:crypto'
5+ import * as Fs from 'node:fs'
56import { RunDebugServer } from './utils/http-server.js'
67import { Build } from './build.js'
78
@@ -11,31 +12,28 @@ if (Process.cwd().endsWith('/builder')) {
1112}
1213const WatchingGlob = [ ] ;
1314[ 'builder/' , 'userscript/' , '' ] . forEach ( Dir => {
14- WatchingGlob . push ( `${ ProjectRoot } /${ Dir } sources /**/*.ts` )
15- WatchingGlob . push ( `${ ProjectRoot } /${ Dir } sources /**/*.json` )
16- WatchingGlob . push ( `${ ProjectRoot } /${ Dir } sources /**/*.txt` )
15+ WatchingGlob . push ( ... Fs . globSync ( `${ ProjectRoot } /${ Dir } source /**/*.ts` ) )
16+ WatchingGlob . push ( ... Fs . globSync ( `${ ProjectRoot } /${ Dir } source /**/*.json` ) )
17+ WatchingGlob . push ( ... Fs . globSync ( `${ ProjectRoot } /${ Dir } source /**/*.txt` ) )
1718} )
18- const Watcher = Chokidar . watch ( [
19- `${ ProjectRoot } /sources/**/*.ts` ,
20- `${ ProjectRoot } /sources/**/*.json`
21- ] , {
22- cwd : ProjectRoot ,
19+ const Watcher = Chokidar . watch ( [ ...WatchingGlob ] , {
2320 ignored : '**/node_modules/**' ,
2421} )
2522
2623let BuildCooldownTimer : NodeJS . Timeout = null
2724let ShouldPreventHTTPResponse = false
28- Watcher . on ( 'all' , ( WatcherEvent , WatcherPath ) => {
25+ let Version : number = 0
26+ Watcher . on ( 'all' , async ( WatcherEvent , WatcherPath ) => {
2927 clearTimeout ( BuildCooldownTimer )
3028 BuildCooldownTimer = setTimeout ( async ( ) => {
3129 console . log ( `Detected file change (${ WatcherEvent } ):` , WatcherPath )
3230 ShouldPreventHTTPResponse = true
33- await Build ( { Minify : false , UseCache : true , BuildType : 'development' , SubscriptionUrl : `http://localhost:${ RandomPort } /tinyShield.dev.user.js` } )
31+ await Build ( { Version : `0.0.${ Version } ` , Minify : false , UseCache : true , BuildType : 'development' , SubscriptionUrl : `http://localhost:${ RandomPort } /tinyShield.dev.user.js` } )
32+ Version ++
3433 ShouldPreventHTTPResponse = false
3534 } , 1500 )
3635} )
3736
3837let RandomPort = Crypto . randomInt ( 8000 , 8999 )
39- await Build ( { Minify : false , UseCache : true , BuildType : 'development' , SubscriptionUrl : `http://localhost:${ RandomPort } /tinyShield.dev.user.js` } )
4038RunDebugServer ( RandomPort , [ 'tinyShield.dev.user.js' ] , ShouldPreventHTTPResponse )
4139console . log ( `Debug HTTP server running on http://localhost:${ RandomPort } /tinyShield.dev.user.js` )
0 commit comments