@@ -51,17 +51,18 @@ interface RenderResult {
51
51
}
52
52
53
53
/**
54
- * A Project to manage the Aleph.js appliaction, features include:
55
- * - compile source files
54
+ * A Project to manage the Aleph.js appliaction.
55
+ * features include:
56
+ * - compile source codes
56
57
* - manage deps
57
58
* - apply plugins
58
59
* - watch file changes
59
60
* - call APIs
60
61
* - SSR/SSG
61
62
*/
62
63
export class Project {
63
- readonly mode : 'development' | 'production'
64
64
readonly appRoot : string
65
+ readonly mode : 'development' | 'production'
65
66
readonly config : Readonly < Required < Config > > & { __file ?: string }
66
67
readonly importMap : Readonly < { imports : Record < string , string > } >
67
68
readonly ready : Promise < void >
@@ -74,9 +75,9 @@ export class Project {
74
75
#rendered: Map < string , Map < string , RenderResult > > = new Map ( )
75
76
#postcssPlugins: Record < string , AcceptedPlugin > = { }
76
77
77
- constructor ( dir : string , mode : 'development' | 'production' , reload = false ) {
78
+ constructor ( appDir : string , mode : 'development' | 'production' , reload = false ) {
79
+ this . appRoot = path . resolve ( appDir )
78
80
this . mode = mode
79
- this . appRoot = dir
80
81
this . config = {
81
82
srcDir : '/' ,
82
83
outputDir : '/dist' ,
@@ -298,7 +299,7 @@ export class Project {
298
299
const outputDir = path . join ( this . srcDir , this . config . outputDir )
299
300
const distDir = path . join ( outputDir , '_aleph' )
300
301
const outputModules = new Set < string > ( )
301
- const lookup = async ( moduleID : string ) => {
302
+ const lookup = ( moduleID : string ) => {
302
303
if ( this . #modules. has ( moduleID ) && ! outputModules . has ( moduleID ) ) {
303
304
outputModules . add ( moduleID )
304
305
const { deps } = this . #modules. get ( moduleID ) !
@@ -380,7 +381,7 @@ export class Project {
380
381
// copy public assets
381
382
const publicDir = path . join ( this . appRoot , 'public' )
382
383
if ( existsDirSync ( publicDir ) ) {
383
- log . info ( colors . bold ( ' Public Assets' ) )
384
+ log . info ( colors . bold ( '- Public Assets' ) )
384
385
for await ( const { path : p } of walk ( publicDir , { includeDirs : false , skip : [ / \/ \. [ ^ \/ ] + ( $ | \/ ) / ] } ) ) {
385
386
const rp = util . trimPrefix ( p , publicDir )
386
387
const fp = path . join ( outputDir , rp )
@@ -536,17 +537,6 @@ export class Project {
536
537
Object . assign ( this , { buildID : this . mode + '.' + this . config . buildTarget } )
537
538
// update routing
538
539
this . #routing = new Routing ( [ ] , this . config . baseUrl , this . config . defaultLocale , this . config . locales )
539
- // inject ALEPH global variable
540
- Object . assign ( globalThis , {
541
- ALEPH : {
542
- ENV : {
543
- ...this . config . env ,
544
- __version : version ,
545
- __buildMode : this . mode ,
546
- __buildTarget : this . config . buildTarget ,
547
- } as AlephEnv
548
- }
549
- } )
550
540
}
551
541
552
542
private async _init ( reload : boolean ) {
@@ -565,6 +555,18 @@ export class Project {
565
555
await ensureDir ( this . buildDir )
566
556
}
567
557
558
+ // inject ALEPH global variable
559
+ Object . assign ( globalThis , {
560
+ ALEPH : {
561
+ ENV : {
562
+ ...this . config . env ,
563
+ __version : version ,
564
+ __buildMode : this . mode ,
565
+ __buildTarget : this . config . buildTarget ,
566
+ } as AlephEnv
567
+ }
568
+ } )
569
+
568
570
// change current work dir to appDoot
569
571
Deno . chdir ( this . appRoot )
570
572
@@ -1468,7 +1470,7 @@ export function injectHmr({ id, sourceFilePath, jsContent }: Module): string {
1468
1470
1469
1471
/** get relative the path of `to` to `from` */
1470
1472
function getRelativePath ( from : string , to : string ) : string {
1471
- let r = path . relative ( from , to )
1473
+ let r = path . relative ( from , to ) . split ( '\\' ) . join ( '/' )
1472
1474
if ( ! r . startsWith ( '.' ) && ! r . startsWith ( '/' ) ) {
1473
1475
r = './' + r
1474
1476
}
0 commit comments