@@ -4,32 +4,57 @@ const process = require("process");
44const fs = require ( "fs-extra" ) ;
55const path = require ( "path" ) ;
66
7- // Read target directory from dev config
7+ // Read target directories from dev config
88const devConfigPath = path . resolve ( __dirname , "../dev.json" ) ;
9- let targetRoot ;
9+ let targetDirs = [ ] ;
1010try {
1111 const devConfig = JSON . parse ( fs . readFileSync ( devConfigPath , "utf8" ) ) ;
12- targetRoot = devConfig . targetDir ;
13- if ( ! targetRoot ) {
14- throw new Error ( "targetDir not found in dev.json" ) ;
12+
13+ // Support both single targetDir and multiple targetDirs
14+ if ( devConfig . targetDirs && Array . isArray ( devConfig . targetDirs ) ) {
15+ targetDirs = devConfig . targetDirs ;
16+ } else if ( devConfig . targetDir ) {
17+ targetDirs = [ devConfig . targetDir ] ;
18+ } else {
19+ throw new Error ( "Neither targetDir nor targetDirs found in dev.json" ) ;
20+ }
21+
22+ if ( targetDirs . length === 0 ) {
23+ throw new Error ( "No target directories specified in dev.json" ) ;
1524 }
1625} catch ( err ) {
1726 console . error ( `Error reading dev.json: ${ err } ` ) ;
1827 process . exit ( 1 ) ;
1928}
2029
2130const sourceDir = path . resolve ( __dirname , "../dist" ) ;
22- const targetDir = path . join ( targetRoot , "dist" ) ;
2331
24- // Ensure target directory exists
25- fs . ensureDirSync ( targetDir ) ;
32+ // Copy files to all target directories
33+ let successCount = 0 ;
34+ let errorCount = 0 ;
2635
27- // Copy files from source to target, overwriting if exists
28- try {
29- fs . copySync ( sourceDir , targetDir , { overwrite : true } ) ;
30- console . log ( `Successfully copied build files from ${ sourceDir } to ${ targetDir } ` ) ;
31- } catch ( err ) {
32- console . error ( `Error copying build files: ${ err } ` ) ;
36+ for ( const targetDir of targetDirs ) {
37+ const fullTargetDir = path . join ( targetDir , "dist" ) ;
38+
39+ // Ensure target directory exists
40+ fs . ensureDirSync ( fullTargetDir ) ;
41+
42+ // Copy files from source to target, overwriting if exists
43+ try {
44+ fs . copySync ( sourceDir , fullTargetDir , { overwrite : true } ) ;
45+ console . log ( `✓ Successfully copied build files to ${ fullTargetDir } ` ) ;
46+ successCount ++ ;
47+ } catch ( err ) {
48+ console . error ( `✗ Error copying build files to ${ fullTargetDir } : ${ err } ` ) ;
49+ errorCount ++ ;
50+ }
51+ }
52+
53+ // Summary
54+ console . log ( `\nCopy operation completed:` ) ;
55+ console . log ( ` Success: ${ successCount } directories` ) ;
56+ if ( errorCount > 0 ) {
57+ console . log ( ` Errors: ${ errorCount } directories` ) ;
3358 process . exit ( 1 ) ;
3459}
3560
0 commit comments