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" ;
28import { map } from "@core/iterutil/map" ;
39import { flatMap } from "@core/iterutil/async/flat-map" ;
4-
5- const decoder = new TextDecoder ( ) ;
10+ import { doc } from "@deno/doc" ;
611
712const excludes = [
813 "mod.ts" ,
@@ -11,47 +16,6 @@ const excludes = [
1116 "_*.ts" ,
1217] ;
1318
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-
5519async function * iterModules ( path : string ) : AsyncIterable < string > {
5620 const patterns = excludes . map ( ( p ) => globToRegExp ( p ) ) ;
5721 for await ( const entry of Deno . readDir ( path ) ) {
@@ -66,15 +30,16 @@ async function generateModTs(
6630) : Promise < void > {
6731 const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
6832 const exports = ( await Array . fromAsync (
69- flatMap ( iterModules ( path ) , ( x ) => listDenoDocEntries ( x ) ) ,
33+ flatMap ( iterModules ( path ) , ( x ) => doc ( toFileUrl ( x ) . href ) ) ,
7034 ) )
35+ . filter ( ( x ) => ! ! x . jsDoc ?. doc )
7136 . filter ( ( x ) => x . kind === "function" )
7237 . filter ( ( x ) => x . declarationKind === "export" )
7338 . filter ( ( x ) => x . name . startsWith ( namespace ) )
7439 . map ( ( x ) => ( {
7540 path : relative ( path , fromFileUrl ( x . location . filename ) ) ,
7641 name : x . name ,
77- doc : x . jsDoc . doc ,
42+ doc : x . jsDoc ! . doc ! ,
7843 } ) )
7944 . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
8045 const lines = [
0 commit comments