1
- import { fromFileUrl , globToRegExp , join , relative } from "@std/path" ;
1
+ import {
2
+ fromFileUrl ,
3
+ globToRegExp ,
4
+ join ,
5
+ relative ,
6
+ toFileUrl ,
7
+ } from "@std/path" ;
2
8
import { map } from "@core/iterutil/map" ;
3
9
import { flatMap } from "@core/iterutil/async/flat-map" ;
4
-
5
- const decoder = new TextDecoder ( ) ;
10
+ import { doc } from "@deno/doc" ;
6
11
7
12
const excludes = [
8
13
"mod.ts" ,
@@ -11,47 +16,6 @@ const excludes = [
11
16
"_*.ts" ,
12
17
] ;
13
18
14
- type DenoDocEntry = {
15
- name : string ;
16
- location : {
17
- filename : string ;
18
- } ;
19
- declarationKind : string ;
20
- jsDoc : {
21
- doc : string ;
22
- } ;
23
- kind : string ;
24
- } ;
25
-
26
- function isDenoDocEntry ( x : unknown ) : x is DenoDocEntry {
27
- if ( x == null || typeof x !== "object" ) return false ;
28
- if ( typeof ( x as DenoDocEntry ) . name !== "string" ) return false ;
29
- if ( typeof ( x as DenoDocEntry ) . location !== "object" ) return false ;
30
- if ( typeof ( x as DenoDocEntry ) . location . filename !== "string" ) return false ;
31
- if ( typeof ( x as DenoDocEntry ) . declarationKind !== "string" ) return false ;
32
- if ( typeof ( x as DenoDocEntry ) . jsDoc !== "object" ) return false ;
33
- if ( typeof ( x as DenoDocEntry ) . jsDoc . doc !== "string" ) return false ;
34
- if ( typeof ( x as DenoDocEntry ) . kind !== "string" ) return false ;
35
- return true ;
36
- }
37
-
38
- async function listDenoDocEntries ( path : string ) : Promise < DenoDocEntry [ ] > {
39
- const cmd = new Deno . Command ( Deno . execPath ( ) , {
40
- args : [ "doc" , "--json" , path ] ,
41
- stdout : "piped" ,
42
- stderr : "piped" ,
43
- } ) ;
44
- const { success, stdout, stderr } = await cmd . output ( ) ;
45
- if ( ! success ) {
46
- throw new Error ( decoder . decode ( stderr ) ) ;
47
- }
48
- const json = JSON . parse ( decoder . decode ( stdout ) ) ;
49
- if ( ! Array . isArray ( json ) ) {
50
- throw new Error ( `Expected array but got ${ JSON . stringify ( json ) } ` ) ;
51
- }
52
- return json . filter ( isDenoDocEntry ) ;
53
- }
54
-
55
19
async function * iterModules ( path : string ) : AsyncIterable < string > {
56
20
const patterns = excludes . map ( ( p ) => globToRegExp ( p ) ) ;
57
21
for await ( const entry of Deno . readDir ( path ) ) {
@@ -66,15 +30,16 @@ async function generateModTs(
66
30
) : Promise < void > {
67
31
const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
68
32
const exports = ( await Array . fromAsync (
69
- flatMap ( iterModules ( path ) , ( x ) => listDenoDocEntries ( x ) ) ,
33
+ flatMap ( iterModules ( path ) , ( x ) => doc ( toFileUrl ( x ) . href ) ) ,
70
34
) )
35
+ . filter ( ( x ) => ! ! x . jsDoc ?. doc )
71
36
. filter ( ( x ) => x . kind === "function" )
72
37
. filter ( ( x ) => x . declarationKind === "export" )
73
38
. filter ( ( x ) => x . name . startsWith ( namespace ) )
74
39
. map ( ( x ) => ( {
75
40
path : relative ( path , fromFileUrl ( x . location . filename ) ) ,
76
41
name : x . name ,
77
- doc : x . jsDoc . doc ,
42
+ doc : x . jsDoc ! . doc ! ,
78
43
} ) )
79
44
. toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
80
45
const lines = [
0 commit comments