@@ -7,21 +7,23 @@ import { camelToUpperSnake, getCrossVar, isApp, isDev, isNode, isTest, runHooks,
7
7
import { version as fictionVersion } from '../package.json'
8
8
import type { RunVars } from '../inject'
9
9
import { compileApplication } from './entry'
10
- import type * as types from './types'
10
+
11
11
import type { CliCommand } from './commands'
12
12
import { standardAppCommands } from './commands'
13
13
import { done } from './utils'
14
14
import { generateStaticConfig } from './generate'
15
15
import { commonServerOnlyModules } from './serverOnly'
16
16
import { EnvVar , envConfig , vars } from './onImport'
17
+ import type { CliOptions , CliVars , ServerModuleDef , ServiceConfig } from './types'
18
+ import type { FictionEnvHookDictionary } from './hooks'
17
19
18
20
export { envConfig , vars , EnvVar }
19
21
export * from './types'
20
22
export * from './entry'
21
23
export * from './commands'
22
24
23
25
export interface FictionControlSettings {
24
- hooks ?: HookType < types . FictionEnvHookDictionary > [ ]
26
+ hooks ?: HookType < FictionEnvHookDictionary > [ ]
25
27
envFiles ?: string [ ]
26
28
envFilesProd ?: string [ ]
27
29
env ?: Record < string , string >
@@ -36,7 +38,7 @@ export interface FictionControlSettings {
36
38
isApp ?: boolean
37
39
isTest ?: boolean
38
40
version ?: string
39
- serverOnlyModules ?: types . ServerModuleDef [ ]
41
+ serverOnlyModules ?: ServerModuleDef [ ]
40
42
uiPaths ?: string [ ]
41
43
meta ?: { version ?: string , app ?: { name ?: string , email ?: string , url ?: string , domain ?: string } }
42
44
}
@@ -86,6 +88,14 @@ export class FictionEnv<
86
88
// the services are then accessed via useService provide
87
89
service = vue . shallowRef < { runVars ?: Partial < RunVars > , [ key : string ] : unknown } > ( { } )
88
90
91
+ runHooks < T extends keyof FictionEnvHookDictionary > ( hook : T , ...args : FictionEnvHookDictionary [ T ] [ 'args' ] ) {
92
+ return runHooks < FictionEnvHookDictionary , T > ( { list : this . hooks , hook, args } )
93
+ }
94
+
95
+ public addHook < T extends HookType < FictionEnvHookDictionary > > ( hook : T ) : void {
96
+ this . hooks . push ( hook )
97
+ }
98
+
89
99
constructor ( settings : FictionControlSettings ) {
90
100
super ( 'env' , settings )
91
101
@@ -147,7 +157,7 @@ export class FictionEnv<
147
157
}
148
158
149
159
commandName = vue . ref ( getCrossVar ( 'COMMAND' ) || '' )
150
- commandOpts = vue . ref ( JSON . parse ( getCrossVar ( 'COMMAND_OPTS' ) || '{}' ) as types . CliOptions )
160
+ commandOpts = vue . ref ( JSON . parse ( getCrossVar ( 'COMMAND_OPTS' ) || '{}' ) as CliOptions )
151
161
152
162
currentCommand = vue . computed ( ( ) => {
153
163
if ( ! this . commandName . value )
@@ -291,17 +301,13 @@ export class FictionEnv<
291
301
await generateStaticConfig ( this )
292
302
}
293
303
294
- public addHook ( hook : HookType < types . FictionEnvHookDictionary > ) : void {
295
- this . hooks . push ( hook )
296
- }
297
-
298
304
onCommand (
299
305
commands : string [ ] ,
300
- callback : ( command : string , options : types . CliOptions ) => Promise < void > ,
306
+ callback : ( command : string , options : CliOptions ) => Promise < void > ,
301
307
) : void {
302
308
this . hooks . push ( {
303
309
hook : 'runCommand' ,
304
- callback : async ( command : string , opts : types . CliOptions ) => {
310
+ callback : async ( command : string , opts : CliOptions ) => {
305
311
if ( commands . includes ( command ) )
306
312
await callback ( command , opts )
307
313
} ,
@@ -314,8 +320,8 @@ export class FictionEnv<
314
320
*/
315
321
async crossRunCommand ( args : {
316
322
context : 'node' | 'app'
317
- serviceConfig : types . ServiceConfig
318
- cliVars ?: Partial < types . CliVars >
323
+ serviceConfig : ServiceConfig
324
+ cliVars ?: Partial < CliVars >
319
325
runVars ?: Partial < RunVars >
320
326
} ) {
321
327
const { context, serviceConfig, cliVars, runVars } = args
@@ -326,17 +332,13 @@ export class FictionEnv<
326
332
327
333
const options = { command : cmd ?. command , ...cmd ?. options }
328
334
329
- await runHooks < types . FictionEnvHookDictionary > ( {
330
- list : this . hooks ,
331
- hook : 'runCommand' ,
332
- args : [ options . command || 'not_set' , options ] ,
333
- } )
335
+ await runHooks ( { list : this . hooks , hook : 'runCommand' , args : [ options . command || 'not_set' , options ] } )
334
336
335
337
if ( serviceConfig ?. runCommand )
336
338
await serviceConfig . runCommand ( { context, command : options . command || 'not_set' , options, cliVars, runVars } )
337
339
}
338
340
339
- async serverRunCurrentCommand ( args : { serviceConfig : types . ServiceConfig , cliVars : Partial < types . CliVars > } ) : Promise < void > {
341
+ async serverRunCurrentCommand ( args : { serviceConfig : ServiceConfig , cliVars : Partial < CliVars > } ) : Promise < void > {
340
342
const { serviceConfig, cliVars } = args
341
343
342
344
const cliCommand = this . currentCommand . value
0 commit comments