@@ -36,38 +36,32 @@ async function minifyDirectory(inputDir, outputDir) {
3636 fs . mkdirSync ( outputDir , { recursive : true } ) ;
3737 const dirents = fs . readdirSync ( inputDir , { recursive : true , withFileTypes : true } ) ;
3838 for ( const dirent of dirents ) {
39- if ( dirent . path . includes ( '/docs/output/' ) ) {
40- continue
39+ if ( ! dirent . isFile ( ) ) {
40+ continue ;
4141 }
42- if ( dirent . isFile ( ) ) {
43- const
44- inputPath = path . join ( dirent . path , dirent . name ) ,
45- relativePath = path . relative ( inputDir , inputPath ) ,
46- outputPath = path . join ( outputDir , relativePath ) ,
47- content = fs . readFileSync ( inputPath , 'utf8' ) ;
48- await minifyFile ( content , outputPath )
49- } else if ( dirent . name === 'resources' ) {
50- const
51- inputPath = path . join ( dirent . path , dirent . name ) ,
52- relativePath = path . relative ( inputDir , inputPath ) ,
53- outputPath = path . join ( outputDir , relativePath ) ;
54- fs . mkdirSync ( path . dirname ( outputPath ) , { recursive : true } ) ;
55- fs . copySync ( inputPath , outputPath ) ;
5642
57- // Exception for devindex app: Do not deploy the data folder.
58- if ( inputPath . replace ( / \\ / g, '/' ) . includes ( 'apps/devindex/resources' ) ) {
59- fs . removeSync ( path . join ( outputPath , 'data' ) ) ;
60- }
43+ const currentPath = dirent . parentPath || dirent . path ;
44+ const inputPath = path . join ( currentPath , dirent . name ) ;
45+ const normalizedInput = inputPath . replace ( / \\ / g, '/' ) ;
6146
62- const resourcesEntries = fs . readdirSync ( outputPath , { recursive : true , withFileTypes : true } ) ;
63- for ( const resource of resourcesEntries ) {
64- if ( resource . isFile ( ) && resource . name . endsWith ( '.json' ) ) {
65- const
66- resourcePath = path . join ( resource . path , resource . name ) ,
67- content = fs . readFileSync ( resourcePath , 'utf8' ) ;
68- fs . writeFileSync ( resourcePath , JSON . stringify ( JSON . parse ( content ) ) )
69- }
70- }
47+ if ( normalizedInput . includes ( '/docs/output/' ) ) {
48+ continue ;
49+ }
50+
51+ // Exception for devindex app: Do not deploy the data folder.
52+ if ( normalizedInput . includes ( '/apps/devindex/resources/data/' ) ) {
53+ continue ;
54+ }
55+
56+ const relativePath = path . relative ( inputDir , inputPath ) ;
57+ const outputPath = path . join ( outputDir , relativePath ) ;
58+
59+ if ( dirent . name . endsWith ( '.mjs' ) || dirent . name . endsWith ( '.json' ) || dirent . name . endsWith ( '.html' ) ) {
60+ const content = fs . readFileSync ( inputPath , 'utf8' ) ;
61+ await minifyFile ( content , outputPath ) ;
62+ } else if ( normalizedInput . includes ( '/resources/' ) ) {
63+ fs . mkdirSync ( path . dirname ( outputPath ) , { recursive : true } ) ;
64+ fs . copyFileSync ( inputPath , outputPath ) ;
7165 }
7266 }
7367 }
@@ -116,9 +110,12 @@ async function minifyFile(content, outputPath) {
116110 }
117111}
118112
119- const
120- swContent = fs . readFileSync ( path . resolve ( root , 'ServiceWorker.mjs' ) , 'utf8' ) ,
121- promises = [ minifyFile ( swContent , path . resolve ( root , outputBasePath , 'ServiceWorker.mjs' ) ) ] ;
113+ const promises = [ ] ;
114+ const swPath = path . resolve ( root , 'ServiceWorker.mjs' ) ;
115+
116+ if ( fs . existsSync ( swPath ) ) {
117+ promises . push ( minifyFile ( fs . readFileSync ( swPath , 'utf8' ) , path . resolve ( root , outputBasePath , 'ServiceWorker.mjs' ) ) ) ;
118+ }
122119
123120inputDirectories . forEach ( folder => {
124121 const outputPath = path . resolve ( root , outputBasePath , folder . replace ( 'node_modules/neo.mjs/' , '' ) ) ;
0 commit comments