@@ -254,6 +254,15 @@ export default class Project {
254
254
}
255
255
await Promise . all ( [ outputDir , distDir ] . map ( dir => ensureDir ( dir ) ) )
256
256
257
+ // copy public files
258
+ const publicDir = path . join ( this . rootDir , 'public' )
259
+ if ( util . existsDir ( publicDir ) ) {
260
+ for await ( const { path : p } of walk ( publicDir , { includeDirs : false } ) ) {
261
+ const rp = path . resolve ( util . trimPrefix ( p , publicDir ) )
262
+ await Deno . copyFile ( p , path . join ( outputDir , rp ) )
263
+ }
264
+ }
265
+
257
266
// write modules
258
267
const { sourceMap } = this . config
259
268
await Promise . all ( Array . from ( outputModules ) . map ( ( moduleId ) => {
@@ -287,15 +296,6 @@ export default class Project {
287
296
await writeTextFile ( path . join ( outputDir , 'index.html' ) , this . getDefaultIndexHtml ( ) )
288
297
}
289
298
290
- // copy public files
291
- const publicDir = path . join ( this . rootDir , 'public' )
292
- if ( util . existsDir ( publicDir ) ) {
293
- for await ( const { path : p } of walk ( publicDir , { includeDirs : false } ) ) {
294
- const rp = path . resolve ( util . trimPrefix ( p , publicDir ) )
295
- await Deno . copyFile ( p , path . join ( outputDir , rp ) )
296
- }
297
- }
298
-
299
299
log . info ( `Done in ${ Math . round ( performance . now ( ) - start ) } ms` )
300
300
}
301
301
@@ -312,44 +312,63 @@ export default class Project {
312
312
Object . assign ( this . config . importMap , { imports : Object . assign ( { } , this . config . importMap . imports , imports ) } )
313
313
}
314
314
315
- const configFile = path . join ( this . rootDir , 'aleph.config.json' )
316
- if ( util . existsFile ( configFile ) ) {
317
- const {
318
- srcDir,
319
- ouputDir,
320
- baseUrl,
321
- ssr,
322
- buildTarget,
323
- sourceMap,
324
- defaultLocale
325
- } = JSON . parse ( await Deno . readTextFile ( configFile ) )
326
- if ( util . isNEString ( srcDir ) ) {
327
- Object . assign ( this . config , { srcDir : util . cleanPath ( srcDir ) } )
328
- }
329
- if ( util . isNEString ( ouputDir ) ) {
330
- Object . assign ( this . config , { ouputDir : util . cleanPath ( ouputDir ) } )
331
- }
332
- if ( util . isNEString ( baseUrl ) ) {
333
- Object . assign ( this . config , { baseUrl : util . cleanPath ( encodeURI ( baseUrl ) ) } )
334
- }
335
- if ( util . isNEString ( defaultLocale ) ) {
336
- Object . assign ( this . config , { defaultLocale } )
337
- }
338
- if ( typeof ssr === 'boolean' ) {
339
- Object . assign ( this . config , { ssr } )
340
- } else if ( util . isPlainObject ( ssr ) ) {
341
- const fallback = util . isNEString ( ssr . fallback ) ? ssr . fallback : '404.html'
342
- const include = util . isArray ( ssr . include ) ? ssr . include : [ ]
343
- const exclude = util . isArray ( ssr . exclude ) ? ssr . exclude : [ ]
344
- Object . assign ( this . config , { ssr : { fallback, include, exclude } } )
345
- }
346
- if ( / ^ e s ( 2 0 \d { 2 } | n e x t ) $ / i. test ( buildTarget ) ) {
347
- Object . assign ( this . config , { buildTarget : buildTarget . toLowerCase ( ) } )
348
- }
349
- if ( typeof sourceMap === 'boolean' ) {
350
- Object . assign ( this . config , { sourceMap } )
315
+ const config : Record < string , any > = { }
316
+ for await ( const { path : p } of walk ( this . srcDir , { includeDirs : false , exts : [ '.js' , '.mjs' , '.ts' , '.json' ] , skip : [ / \. d \. t s $ / i] , maxDepth : 1 } ) ) {
317
+ const name = path . basename ( p )
318
+ if ( name . split ( '.' ) [ 0 ] === 'config' ) {
319
+ if ( name . endsWith ( '.json' ) ) {
320
+ try {
321
+ const conf = JSON . parse ( await Deno . readTextFile ( p ) )
322
+ Object . assign ( config , conf )
323
+ log . debug ( name , config )
324
+ } catch ( e ) {
325
+ log . fatal ( 'parse config.json:' , e . message )
326
+ }
327
+ } else {
328
+ const { default : conf } = await import ( p )
329
+ if ( util . isPlainObject ( conf ) ) {
330
+ Object . assign ( config , conf )
331
+ log . debug ( name , config )
332
+ }
333
+ }
351
334
}
352
335
}
336
+
337
+ const {
338
+ srcDir,
339
+ ouputDir,
340
+ baseUrl,
341
+ ssr,
342
+ buildTarget,
343
+ sourceMap,
344
+ defaultLocale
345
+ } = config
346
+ if ( util . isNEString ( srcDir ) ) {
347
+ Object . assign ( this . config , { srcDir : util . cleanPath ( srcDir ) } )
348
+ }
349
+ if ( util . isNEString ( ouputDir ) ) {
350
+ Object . assign ( this . config , { ouputDir : util . cleanPath ( ouputDir ) } )
351
+ }
352
+ if ( util . isNEString ( baseUrl ) ) {
353
+ Object . assign ( this . config , { baseUrl : util . cleanPath ( encodeURI ( baseUrl ) ) } )
354
+ }
355
+ if ( util . isNEString ( defaultLocale ) ) {
356
+ Object . assign ( this . config , { defaultLocale } )
357
+ }
358
+ if ( typeof ssr === 'boolean' ) {
359
+ Object . assign ( this . config , { ssr } )
360
+ } else if ( util . isPlainObject ( ssr ) ) {
361
+ const fallback = util . isNEString ( ssr . fallback ) ? ssr . fallback : '404.html'
362
+ const include = util . isArray ( ssr . include ) ? ssr . include : [ ]
363
+ const exclude = util . isArray ( ssr . exclude ) ? ssr . exclude : [ ]
364
+ Object . assign ( this . config , { ssr : { fallback, include, exclude } } )
365
+ }
366
+ if ( / ^ e s ( 2 0 \d { 2 } | n e x t ) $ / i. test ( buildTarget ) ) {
367
+ Object . assign ( this . config , { buildTarget : buildTarget . toLowerCase ( ) } )
368
+ }
369
+ if ( typeof sourceMap === 'boolean' ) {
370
+ Object . assign ( this . config , { sourceMap } )
371
+ }
353
372
}
354
373
355
374
private async _init ( ) {
0 commit comments