@@ -6,26 +6,26 @@ import type { Express } from 'express'
6
6
import { createHead } from '@unhead/vue'
7
7
import type { HookType } from '../utils'
8
8
import { initializeResetUi , safeDirname , vue } from '../utils'
9
- import type { FactorAppEntry , FactorEnv , ServiceConfig , ServiceList } from '../plugin-env'
10
- import { FactorPlugin } from '../plugin'
11
- import type { FactorBuild } from '../plugin-build'
12
- import type { FactorRouter } from '../plugin-router'
9
+ import type { FictionAppEntry , FictionEnv , ServiceConfig , ServiceList } from '../plugin-env'
10
+ import { FictionPlugin } from '../plugin'
11
+ import type { FictionBuild } from '../plugin-build'
12
+ import type { FictionRouter } from '../plugin-router'
13
13
import type { RunVars , StandardServices } from '../inject'
14
- import { FactorRender } from './plugin-render'
14
+ import { FictionRender } from './plugin-render'
15
15
import ElRoot from './ElRoot.vue'
16
- import type { FactorSitemap } from './sitemap'
16
+ import type { FictionSitemap } from './sitemap'
17
17
import type { SiteMapEntry } from './types'
18
18
19
19
type HookDictionary = {
20
- beforeAppMounted : { args : [ FactorAppEntry ] }
21
- appMounted : { args : [ FactorAppEntry ] }
20
+ beforeAppMounted : { args : [ FictionAppEntry ] }
21
+ appMounted : { args : [ FictionAppEntry ] }
22
22
afterAppSetup : { args : [ { service : ServiceList } ] }
23
23
viteConfig : { args : [ vite . InlineConfig [ ] ] }
24
24
headTags : { args : [ string , { pathname ?: string } ] }
25
25
htmlBody : { args : [ string , { pathname ?: string } ] }
26
26
}
27
27
28
- export interface FactorAppSettings {
28
+ export interface FictionAppSettings {
29
29
hooks ?: HookType < HookDictionary > [ ]
30
30
mode ?: 'production' | 'development'
31
31
isTest ?: boolean
@@ -34,9 +34,9 @@ export interface FactorAppSettings {
34
34
isLive ?: vue . Ref < boolean >
35
35
altHostnames ?: { dev : string , prod : string } [ ]
36
36
port : number
37
- factorEnv : FactorEnv
37
+ fictionEnv : FictionEnv
38
38
rootComponent ?: vue . Component
39
- factorRouter : FactorRouter
39
+ fictionRouter : FictionRouter
40
40
sitemaps ?: SiteMapEntry [ ]
41
41
uiPaths ?: string [ ]
42
42
tailwindConfig ?: Partial < TailwindConfig > [ ]
@@ -47,18 +47,18 @@ export interface FactorAppSettings {
47
47
[ key : string ] : unknown
48
48
}
49
49
50
- export class FactorApp extends FactorPlugin < FactorAppSettings > {
51
- isLive = this . settings . isLive ?? this . settings . factorEnv . isProd
50
+ export class FictionApp extends FictionPlugin < FictionAppSettings > {
51
+ isLive = this . settings . isLive ?? this . settings . fictionEnv . isProd
52
52
viteDevServer ?: vite . ViteDevServer
53
53
hooks = this . settings . hooks ?? [ ]
54
54
uiPaths = this . settings . uiPaths ?? [ ]
55
- factorRouter = this . settings . factorRouter
55
+ fictionRouter = this . settings . fictionRouter
56
56
isTest = this . settings . isTest || this . utils . isTest ( )
57
57
rootComponent = this . settings . rootComponent || ElRoot
58
- factorEnv = this . settings . factorEnv
59
- factorBuild ?: FactorBuild
60
- factorSitemap ?: FactorSitemap
61
- factorRender ?: FactorRender
58
+ fictionEnv = this . settings . fictionEnv
59
+ fictionBuild ?: FictionBuild
60
+ fictionSitemap ?: FictionSitemap
61
+ fictionRender ?: FictionRender
62
62
appName : string
63
63
appEmail : string
64
64
sitemaps = this . settings . sitemaps ?? [ ]
@@ -73,49 +73,49 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
73
73
return isLive ? this . liveUrl . value : this . localUrl
74
74
} )
75
75
76
- srcFolder = this . settings . srcFolder || this . factorEnv . cwd
76
+ srcFolder = this . settings . srcFolder || this . fictionEnv . cwd
77
77
mainIndexHtml = this . settings . mainIndexHtml || path . join ( this . srcFolder , 'index.html' )
78
78
publicFolder = this . settings . publicFolder || path . join ( this . srcFolder , 'public' )
79
79
80
80
appInstanceId = this . settings . appInstanceId || 'app'
81
81
root = safeDirname ( import . meta. url )
82
82
83
- constructor ( settings : FactorAppSettings ) {
83
+ constructor ( settings : FictionAppSettings ) {
84
84
super ( 'app' , settings )
85
85
86
- this . appEmail = this . factorEnv . appEmail
87
- this . appName = this . factorEnv . appName
86
+ this . appEmail = this . fictionEnv . appEmail
87
+ this . appName = this . fictionEnv . appName
88
88
/**
89
89
* node application init
90
90
*/
91
- if ( ! this . factorEnv . isApp . value && this . factorEnv ?. cwd ) {
92
- this . factorRender = new FactorRender ( {
93
- factorApp : this ,
94
- factorEnv : this . factorEnv ,
95
- factorRouter : this . factorRouter ,
91
+ if ( ! this . fictionEnv . isApp . value && this . fictionEnv ?. cwd ) {
92
+ this . fictionRender = new FictionRender ( {
93
+ fictionApp : this ,
94
+ fictionEnv : this . fictionEnv ,
95
+ fictionRouter : this . fictionRouter ,
96
96
} )
97
97
}
98
98
99
99
this . addSchema ( )
100
100
}
101
101
102
102
addSchema ( ) {
103
- if ( this . factorEnv ) {
104
- this . factorEnv . addHook ( {
103
+ if ( this . fictionEnv ) {
104
+ this . fictionEnv . addHook ( {
105
105
hook : 'staticSchema' ,
106
106
callback : async ( existing ) => {
107
- const routeKeys = this . factorRouter . routes . value ?. map ( _ => _ . name ) . filter ( Boolean ) . sort ( )
107
+ const routeKeys = this . fictionRouter . routes . value ?. map ( _ => _ . name ) . filter ( Boolean ) . sort ( )
108
108
109
109
return { ...existing , routes : { enum : routeKeys , type : 'string' } , menus : { enum : [ '' ] , type : 'string' } }
110
110
} ,
111
111
} )
112
112
113
- this . factorEnv . addHook ( {
113
+ this . fictionEnv . addHook ( {
114
114
hook : 'staticConfig' ,
115
115
callback : (
116
116
schema : Record < string , unknown > ,
117
117
) : Record < string , unknown > => {
118
- return { ...schema , routes : this . factorRouter . routes . value ?. map ( ep => ( { key : ep . name , path : ep . path } ) ) }
118
+ return { ...schema , routes : this . fictionRouter . routes . value ?. map ( ep => ( { key : ep . name , path : ep . path } ) ) }
119
119
} ,
120
120
} )
121
121
}
@@ -139,28 +139,28 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
139
139
}
140
140
141
141
async buildApp ( options : { render ?: boolean , serve ?: boolean } = { } ) {
142
- if ( this . factorEnv . isApp . value )
142
+ if ( this . fictionEnv . isApp . value )
143
143
return
144
- return this . factorRender ?. buildApp ( options )
144
+ return this . fictionRender ?. buildApp ( options )
145
145
}
146
146
147
147
async serveStaticApp ( ) {
148
- if ( this . factorEnv . isApp . value )
148
+ if ( this . fictionEnv . isApp . value )
149
149
return
150
- return this . factorRender ?. serveStaticApp ( )
150
+ return this . fictionRender ?. serveStaticApp ( )
151
151
}
152
152
153
153
createVueApp = async ( args : {
154
154
renderRoute ?: string
155
155
runVars ?: Partial < RunVars >
156
156
service : ServiceList & Partial < StandardServices >
157
- } ) : Promise < FactorAppEntry > => {
157
+ } ) : Promise < FictionAppEntry > => {
158
158
const { renderRoute, service, runVars } = args
159
159
160
- const router = this . factorRouter . create ( { caller : `mountApp:${ this . appInstanceId } ` } )
160
+ const router = this . fictionRouter . create ( { caller : `mountApp:${ this . appInstanceId } ` } )
161
161
162
162
if ( renderRoute )
163
- await this . factorRouter . replace ( { path : renderRoute } , { id : 'mount' } )
163
+ await this . fictionRouter . replace ( { path : renderRoute } , { id : 'mount' } )
164
164
165
165
await this . utils . runHooks < HookDictionary , 'afterAppSetup' > ( {
166
166
list : this . hooks ,
@@ -172,8 +172,8 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
172
172
? vue . createSSRApp ( this . rootComponent )
173
173
: vue . createApp ( this . rootComponent )
174
174
175
- this . factorEnv . service . value = { ...this . factorEnv . service . value , ...service , runVars }
176
- app . provide ( 'service' , this . factorEnv . service )
175
+ this . fictionEnv . service . value = { ...this . fictionEnv . service . value , ...service , runVars }
176
+ app . provide ( 'service' , this . fictionEnv . service )
177
177
178
178
app . use ( router )
179
179
@@ -193,14 +193,14 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
193
193
runVars ?: Partial < RunVars >
194
194
service : ServiceList & Partial < StandardServices >
195
195
serviceConfig ?: ServiceConfig
196
- } ) : Promise < FactorAppEntry > {
196
+ } ) : Promise < FictionAppEntry > {
197
197
const { selector = '#app' , renderRoute, service, runVars, serviceConfig } = args
198
198
199
- await this . factorEnv . crossRunCommand ( { context : 'app' , serviceConfig, runVars } )
199
+ await this . fictionEnv . crossRunCommand ( { context : 'app' , serviceConfig, runVars } )
200
200
201
201
const entry = await this . createVueApp ( { renderRoute, runVars, service } )
202
202
203
- if ( typeof window !== 'undefined' && ! this . factorEnv . isSSR . value ) {
203
+ if ( typeof window !== 'undefined' && ! this . fictionEnv . isSSR . value ) {
204
204
await this . utils . runHooks < HookDictionary , 'beforeAppMounted' > ( {
205
205
list : this . hooks ,
206
206
hook : 'beforeAppMounted' ,
@@ -212,7 +212,7 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
212
212
if ( ! mountEl )
213
213
throw new Error ( `mountEl not found: ${ selector } ` )
214
214
215
- initializeResetUi ( this . factorRouter ) . catch ( console . error )
215
+ initializeResetUi ( this . fictionRouter ) . catch ( console . error )
216
216
entry . app . mount ( mountEl )
217
217
218
218
document . documentElement . style . opacity = '1'
@@ -250,11 +250,11 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
250
250
async ssrServerSetup (
251
251
args : { isProd ?: boolean , expressApp ?: Express } = { } ,
252
252
) : Promise < Express | undefined > {
253
- if ( this . factorEnv . isApp . value || ! this . factorRender )
253
+ if ( this . fictionEnv . isApp . value || ! this . fictionRender )
254
254
return
255
255
256
256
const { isProd = false , expressApp } = args
257
- const eApp = await this . factorRender . createExpressApp ( { isProd, expressApp } )
257
+ const eApp = await this . fictionRender . createExpressApp ( { isProd, expressApp } )
258
258
259
259
return eApp
260
260
}
@@ -263,11 +263,11 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
263
263
* This creates an endpoint server and ssr server on same port
264
264
* Allows production apps to serve on one instance
265
265
*/
266
- // async comboSsrServerCreate(args: { isProd?: boolean, factorServer: FactorServer, factorUser: FactorUser }) {
267
- // const { isProd = false, factorServer, factorUser } = args
268
- // factorServer .port.value = this.port
269
- // factorServer .useLocal.value = true
270
- // const srv = await factorServer .initServer({ factorUser })
266
+ // async comboSsrServerCreate(args: { isProd?: boolean, fictionServer: FictionServer, fictionUser: FictionUser }) {
267
+ // const { isProd = false, fictionServer, fictionUser } = args
268
+ // fictionServer .port.value = this.port
269
+ // fictionServer .useLocal.value = true
270
+ // const srv = await fictionServer .initServer({ fictionUser })
271
271
// await this.ssrServerSetup({ isProd, expressApp: srv?.expressApp })
272
272
// await srv?.run()
273
273
// this.logReady({ serveMode: 'comboSSR' })
@@ -277,7 +277,7 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
277
277
args : { isProd ?: boolean , expressApp ?: Express } = { } ,
278
278
) : Promise < http . Server | undefined > {
279
279
const { isProd = false , expressApp } = args
280
- if ( this . factorEnv . isApp . value || ! this . factorRender )
280
+ if ( this . fictionEnv . isApp . value || ! this . fictionRender )
281
281
return
282
282
283
283
const eApp = await this . ssrServerSetup ( { isProd, expressApp } )
@@ -295,6 +295,6 @@ export class FactorApp extends FactorPlugin<FactorAppSettings> {
295
295
this . log . info ( 'close app' )
296
296
this . appServer ?. close ( )
297
297
this . staticServer ?. close ( )
298
- await this . factorRender ?. viteDevServer ?. close ( )
298
+ await this . fictionRender ?. viteDevServer ?. close ( )
299
299
}
300
300
}
0 commit comments