@@ -6,7 +6,7 @@ import process from 'node:process'
6
6
import { slash , throttle , toArray } from '@antfu/utils'
7
7
import Debug from 'debug'
8
8
import { DIRECTIVE_IMPORT_PREFIX } from './constants'
9
- import { writeDeclaration } from './declaration'
9
+ import { writeComponentsJson , writeDeclaration } from './declaration'
10
10
import { searchComponents } from './fs/glob'
11
11
import { resolveOptions } from './options'
12
12
import transformer from './transformer'
@@ -34,13 +34,24 @@ export class Context {
34
34
root = process . cwd ( )
35
35
sourcemap : string | boolean = true
36
36
alias : Record < string , string > = { }
37
+ dumpComponentsInfoPath : string | undefined
37
38
38
39
constructor (
39
40
private rawOptions : Options ,
40
41
) {
41
42
this . options = resolveOptions ( rawOptions , this . root )
42
43
this . sourcemap = rawOptions . sourcemap ?? true
43
44
this . generateDeclaration = throttle ( 500 , this . _generateDeclaration . bind ( this ) , { noLeading : false } )
45
+
46
+ if ( this . options . dumpComponentsInfo ) {
47
+ const dumpComponentsInfo = this . options . dumpComponentsInfo === true
48
+ ? './.components-info.json'
49
+ : this . options . dumpComponentsInfo ?? false
50
+
51
+ this . dumpComponentsInfoPath = dumpComponentsInfo
52
+ this . generateComponentsJson = throttle ( 500 , this . _generateComponentsJson . bind ( this ) , { noLeading : false } )
53
+ }
54
+
44
55
this . setTransformer ( this . options . transformer )
45
56
}
46
57
@@ -169,6 +180,7 @@ export class Context {
169
180
170
181
onUpdate ( path : string ) {
171
182
this . generateDeclaration ( )
183
+ this . generateComponentsJson ( )
172
184
173
185
if ( ! this . _server )
174
186
return
@@ -288,14 +300,26 @@ export class Context {
288
300
if ( ! this . options . dts )
289
301
return
290
302
291
- debug . declaration ( 'generating' )
303
+ debug . declaration ( 'generating dts ' )
292
304
return writeDeclaration ( this , this . options . dts , removeUnused )
293
305
}
294
306
295
307
generateDeclaration ( removeUnused = ! this . _server ) : void {
296
308
this . _generateDeclaration ( removeUnused )
297
309
}
298
310
311
+ _generateComponentsJson ( removeUnused = ! this . _server ) {
312
+ if ( ! Object . keys ( this . _componentNameMap ) . length )
313
+ return
314
+
315
+ debug . components ( 'generating components-info' )
316
+ return writeComponentsJson ( this , removeUnused )
317
+ }
318
+
319
+ generateComponentsJson ( removeUnused = ! this . _server ) : void {
320
+ this . _generateComponentsJson ( removeUnused )
321
+ }
322
+
299
323
get componentNameMap ( ) {
300
324
return this . _componentNameMap
301
325
}
0 commit comments