@@ -4,6 +4,12 @@ import { exec } from "child_process";
44import { watch } from "chokidar" ;
55
66class RunCommandsPlugin {
7+ private readonly env : Record < string , unknown > ;
8+
9+ public constructor ( env : Record < string , unknown > ) {
10+ this . env = env ;
11+ }
12+
713 private static copyManifest ( callback ?: ( ) => void ) : void {
814 exec ( "npx tsx ./script/copyManifest.ts" , ( err , stdout ) => {
915 // eslint-disable-next-line no-console
@@ -23,7 +29,6 @@ class RunCommandsPlugin {
2329 } ) ;
2430 }
2531
26- // eslint-disable-next-line class-methods-use-this
2732 public apply ( compiler : Compiler ) : void {
2833 let isWatchMode = false ;
2934 let isFirstRun = true ;
@@ -56,29 +61,34 @@ class RunCommandsPlugin {
5661
5762 isFirstRun = false ;
5863
59- exec ( "npx tsx ./script/addUserScriptComment.ts" , ( err , stdout ) => {
60- if ( err ) {
61- // eslint-disable-next-line no-console
62- console . error ( `Error: ${ err . message } ` ) ;
63- } else {
64- // eslint-disable-next-line no-console
65- console . log ( stdout ) ;
66- }
64+ if ( this . env . updateUserScripts ) {
65+ exec ( "npx tsx ./script/addUserScriptComment.ts" , ( err , stdout ) => {
66+ if ( err ) {
67+ // eslint-disable-next-line no-console
68+ console . error ( `Error: ${ err . message } ` ) ;
69+ } else {
70+ // eslint-disable-next-line no-console
71+ console . log ( stdout ) ;
72+ }
73+ callback ( ) ;
74+ } ) ;
75+ } else {
6776 callback ( ) ;
68- } ) ;
77+ }
6978 } ) ;
7079 }
7180}
7281
7382const isProduction = process . env . NODE_ENV === "production" ;
7483/* eslint-disable sort-keys */
75- const config = defineConfig ( {
84+ // eslint-disable-next-line max-lines-per-function
85+ const config = defineConfig ( ( env ) => ( {
7686 mode : isProduction ? "production" : "development" ,
7787 devtool : isProduction ? false : "source-map" ,
7888 entry : {
7989 "./chrome/js/index.js" : "./src/ts/index.ts" ,
8090 "./firefox/js/index.js" : "./src/ts/index.ts" ,
81- "../index.user.js" : "./src/ts/index.ts"
91+ ... ( env . updateUserScripts ? { "../index.user.js" : "./src/ts/index.ts" } : { } )
8292 } ,
8393 output : {
8494 filename : "[name]" ,
@@ -105,7 +115,7 @@ const config = defineConfig({
105115 extensions : [ ".ts" , ".js" ]
106116 } ,
107117 plugins : [
108- new RunCommandsPlugin ( ) ,
118+ new RunCommandsPlugin ( env ) ,
109119 new CopyRspackPlugin ( {
110120 patterns : [
111121 {
@@ -131,7 +141,7 @@ const config = defineConfig({
131141 ]
132142 } )
133143 ]
134- } ) ;
144+ } ) ) ;
135145/* eslint-enable sort-keys */
136146
137147export default config ;
0 commit comments