@@ -6,12 +6,16 @@ import { watch } from "chokidar";
66class RunCommandsPlugin {
77 private static copyManifest ( callback ?: ( ) => void ) : void {
88 exec ( "npx tsx ./script/copyManifest.ts" , ( err , stdout ) => {
9+ // eslint-disable-next-line no-console
10+ console . log ( "Copying manifest files..." ) ;
911 if ( err ) {
1012 // eslint-disable-next-line no-console
1113 console . error ( `Error: ${ err . message } ` ) ;
1214 } else {
1315 // eslint-disable-next-line no-console
1416 console . log ( stdout ) ;
17+ // eslint-disable-next-line no-console
18+ console . log ( "Finished copying manifest files." ) ;
1519 if ( callback ) {
1620 callback ( ) ;
1721 }
@@ -21,27 +25,36 @@ class RunCommandsPlugin {
2125
2226 // eslint-disable-next-line class-methods-use-this
2327 public apply ( compiler : Compiler ) : void {
28+ let isWatchMode = false ;
29+ let isFirstRun = true ;
2430 let manifestWatcher : ReturnType < typeof watch > | null = null ;
2531
2632 compiler . hooks . watchRun . tapAsync ( "RunCommandsPlugin" , ( _params , callback ) => {
33+ isWatchMode = true ;
34+
2735 if ( manifestWatcher ) {
2836 callback ( ) ;
29- } else {
30- manifestWatcher = watch ( "src/manifest/" , {
31- ignored : ( pathString , stats ) => Boolean ( stats && stats . isFile ( ) && ! pathString . endsWith ( ".json" ) )
32- } ) ;
33- manifestWatcher . on ( "change" , ( pathString : string ) => {
34- // eslint-disable-next-line no-console
35- console . log ( `Manifest file changed: ${ pathString } ` ) ;
36- RunCommandsPlugin . copyManifest ( ) ;
37- } ) ;
38-
39- RunCommandsPlugin . copyManifest ( callback ) ;
37+ return ;
4038 }
39+
40+ manifestWatcher = watch ( "src/manifest/" , {
41+ ignored : ( pathString , stats ) => Boolean ( stats && stats . isFile ( ) && ! pathString . endsWith ( ".json" ) )
42+ } ) ;
43+ manifestWatcher . on ( "change" , ( pathString : string ) => {
44+ // eslint-disable-next-line no-console
45+ console . log ( `Manifest file changed: ${ pathString } ` ) ;
46+ RunCommandsPlugin . copyManifest ( ) ;
47+ } ) ;
48+
49+ callback ( ) ;
4150 } ) ;
4251
4352 compiler . hooks . afterEmit . tapAsync ( "RunCommandsPlugin" , ( _compilation , callback ) => {
44- RunCommandsPlugin . copyManifest ( ) ;
53+ if ( ! isWatchMode || isFirstRun ) {
54+ RunCommandsPlugin . copyManifest ( ) ;
55+ }
56+
57+ isFirstRun = false ;
4558
4659 exec ( "npx tsx ./script/addUserScriptComment.ts" , ( err , stdout ) => {
4760 if ( err ) {
0 commit comments