@@ -16,12 +16,11 @@ let TMP_DIR;
16
16
try {
17
17
TMP_DIR = os . tmpdir ( ) ;
18
18
} catch ( e ) {
19
- // Cross-platform fallback for temp directory
20
19
if ( process . platform === 'win32' ) {
21
20
TMP_DIR = process . env . TEMP || process . env . TMP || 'C:\\Windows\\Temp' ;
22
21
} else {
23
22
TMP_DIR = '/tmp' ;
24
- }
23
+ } //maybe we can consider to use node_modules/.cache/adminforth here instead of tmp
25
24
}
26
25
27
26
function stripAnsiCodes ( str ) {
@@ -67,11 +66,7 @@ function hashify(obj) {
67
66
function notifyWatcherIssue ( limit ) {
68
67
console . log ( 'Ran out of file handles after watching %s files.' , limit ) ;
69
68
console . log ( 'Falling back to polling which uses more CPU.' ) ;
70
- if ( process . platform === 'win32' ) {
71
- console . log ( 'On Windows, this is usually handled automatically by the system.' ) ;
72
- } else {
73
- console . log ( 'Run ulimit -n 10000 to increase the limit for open files.' ) ;
74
- }
69
+ console . log ( 'Run ulimit -n 10000 to increase the limit for open files.' ) ;
75
70
}
76
71
77
72
class CodeInjector implements ICodeInjector {
@@ -83,14 +78,11 @@ class CodeInjector implements ICodeInjector {
83
78
devServerPort : number = null ;
84
79
85
80
spaTmpPath ( ) : string {
86
- const brandSlug = this . adminforth . config . customization ?. brandNameSlug ;
87
- process . env . HEAVY_DEBUG && console . log ( `🔧 spaTmpPath() - brandSlug: "${ brandSlug } ", TMP_DIR: "${ TMP_DIR } "` ) ;
81
+ const brandSlug = this . adminforth . config . customization . brandNameSlug
88
82
if ( ! brandSlug ) {
89
83
throw new Error ( 'brandSlug is empty, but it should be populated at least by config Validator ' ) ;
90
84
}
91
- const fullPath = path . join ( TMP_DIR , 'adminforth' , brandSlug , 'spa_tmp' ) ;
92
- process . env . HEAVY_DEBUG && console . log ( `🔧 spaTmpPath() result: "${ fullPath } "` ) ;
93
- return fullPath ;
85
+ return path . join ( TMP_DIR , 'adminforth' , brandSlug , 'spa_tmp' ) ;
94
86
}
95
87
96
88
cleanup ( ) {
@@ -124,7 +116,7 @@ class CodeInjector implements ICodeInjector {
124
116
envOverrides ?: { [ key : string ] : string }
125
117
} ) {
126
118
const nodeBinary = process . execPath ; // Path to the Node.js binary running this script
127
- const npmPath = path . join ( path . dirname ( nodeBinary ) , process . platform === 'win32' ? ' npm.cmd' : 'npm' ) ; // Cross-platform npm executable
119
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , ' npm' ) ; // Path to the npm executable
128
120
const env = {
129
121
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
130
122
FORCE_COLOR : '1' ,
@@ -135,13 +127,7 @@ class CodeInjector implements ICodeInjector {
135
127
console . log ( `⚙️ exec: npm ${ command } ` ) ;
136
128
process . env . HEAVY_DEBUG && console . log ( `🪲 npm ${ command } cwd:` , cwd ) ;
137
129
process . env . HEAVY_DEBUG && console . time ( `npm ${ command } done in` ) ;
138
-
139
- // Cross-platform command execution
140
- const commandToExecute = process . platform === 'win32'
141
- ? `"${ nodeBinary } " "${ npmPath } " ${ command } `
142
- : `${ nodeBinary } ${ npmPath } ${ command } ` ;
143
-
144
- const { stdout : out , stderr : err } = await execAsync ( commandToExecute , {
130
+ const { stdout : out , stderr : err } = await execAsync ( `${ nodeBinary } ${ npmPath } ${ command } ` , {
145
131
cwd,
146
132
env,
147
133
} ) ;
@@ -237,18 +223,12 @@ class CodeInjector implements ICodeInjector {
237
223
238
224
async prepareSources ( ) {
239
225
// collects all files and folders into SPA_TMP_DIR
240
- process . env . HEAVY_DEBUG && console . log ( `🔧 prepareSources() started` ) ;
241
226
242
227
// check spa tmp folder exists and create if not
243
228
try {
244
- process . env . HEAVY_DEBUG && console . log ( `🔧 Checking if spaTmpPath exists: ${ this . spaTmpPath ( ) } ` ) ;
245
229
await fs . promises . access ( this . spaTmpPath ( ) , fs . constants . F_OK ) ;
246
- process . env . HEAVY_DEBUG && console . log ( `🔧 spaTmpPath already exists` ) ;
247
230
} catch ( e ) {
248
- process . env . HEAVY_DEBUG && console . log ( `🔧 spaTmpPath doesn't exist, creating directory: ${ this . spaTmpPath ( ) } ` ) ;
249
- await fs . promises . mkdir ( this . spaTmpPath ( ) , { recursive : true } ) ;
250
- process . env . HEAVY_DEBUG && console . log ( `🔧 Successfully created spaTmpPath directory` ) ;
251
-
231
+ await fs . promises . mkdir ( this . spaTmpPath ( ) , { recursive : true } ) ;
252
232
}
253
233
254
234
const icons = [ ] ;
@@ -341,14 +321,9 @@ class CodeInjector implements ICodeInjector {
341
321
342
322
await fsExtra . copy ( spaDir , this . spaTmpPath ( ) , {
343
323
filter : ( src ) => {
344
- // Cross-platform path filtering for adminforth/* used for local development and /dist/* used for production
345
- const adminforthSpaNodeModules = path . join ( 'adminforth' , 'spa' , 'node_modules' ) ;
346
- const adminforthSpaDist = path . join ( 'adminforth' , 'spa' , 'dist' ) ;
347
- const distSpaNodeModules = path . join ( 'dist' , 'spa' , 'node_modules' ) ;
348
- const distSpaDist = path . join ( 'dist' , 'spa' , 'dist' ) ;
349
-
350
- const filterPasses = ! src . includes ( adminforthSpaNodeModules ) && ! src . includes ( adminforthSpaDist )
351
- && ! src . includes ( distSpaNodeModules ) && ! src . includes ( distSpaDist ) ;
324
+ // /adminforth/* used for local development and /dist/* used for production
325
+ const filterPasses = ! src . includes ( '/adminforth/spa/node_modules' ) && ! src . includes ( '/adminforth/spa/dist' )
326
+ && ! src . includes ( '/dist/spa/node_modules' ) && ! src . includes ( '/dist/spa/dist' ) ;
352
327
if ( process . env . HEAVY_DEBUG && ! filterPasses ) {
353
328
console . log ( '🪲⚙️ fsExtra.copy filtered out' , src ) ;
354
329
}
@@ -543,9 +518,9 @@ class CodeInjector implements ICodeInjector {
543
518
// we dont't need to add baseUrl in front of assets here, because it is already added by Vite/Vue
544
519
indexHtmlContent = indexHtmlContent . replace (
545
520
'/* IMPORTANT:ADMINFORTH FAVICON */' ,
546
- this . adminforth . config . customization . favicon ?. replace ( '@@/' , ' /assets/' )
521
+ this . adminforth . config . customization . favicon ?. replace ( '@@/' , ` /assets/` )
547
522
||
548
- ' /assets/favicon.png'
523
+ ` /assets/favicon.png`
549
524
) ;
550
525
await fs . promises . writeFile ( indexHtmlPath , indexHtmlContent ) ;
551
526
@@ -818,12 +793,7 @@ class CodeInjector implements ICodeInjector {
818
793
console . log ( `${ this . adminforth . formatAdminForth ( ) } Bundling ${ hotReload ? 'and listening for changes (🔥 Hotreload)' : ' (no hot reload)' } ` ) ;
819
794
this . adminforth . runningHotReload = hotReload ;
820
795
821
- process . env . HEAVY_DEBUG && console . log ( `🔧 Starting prepareSources() - Platform: ${ process . platform } , TMP_DIR: ${ TMP_DIR } ` ) ;
822
- process . env . HEAVY_DEBUG && console . log ( `🔧 spaTmpPath: ${ this . spaTmpPath ( ) } ` ) ;
823
-
824
796
await this . prepareSources ( ) ;
825
- process . env . HEAVY_DEBUG && console . log ( `🔧 prepareSources() completed successfully` ) ;
826
-
827
797
828
798
if ( hotReload ) {
829
799
await Promise . all ( [
@@ -902,14 +872,14 @@ class CodeInjector implements ICodeInjector {
902
872
const command = 'run dev' ;
903
873
console . log ( `⚙️ spawn: npm ${ command } ...` ) ;
904
874
const nodeBinary = process . execPath ;
905
- const npmPath = path . join ( path . dirname ( nodeBinary ) , process . platform === 'win32' ? 'npm.cmd' : 'npm' ) ;
875
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , 'npm' ) ;
906
876
const env = {
907
877
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
908
878
FORCE_COLOR : '1' ,
909
879
...process . env ,
910
880
} ;
911
881
912
- const devServer = spawn ( nodeBinary , [ npmPath , ...command . split ( ' ' ) ] , {
882
+ const devServer = spawn ( ` ${ nodeBinary } ` , [ ` ${ npmPath } ` , ...command . split ( ' ' ) ] , {
913
883
cwd,
914
884
env,
915
885
} ) ;
0 commit comments