@@ -25,7 +25,7 @@ async function* iterModules(path: string): AsyncIterable<string> {
25
25
}
26
26
}
27
27
28
- async function generateModTs (
28
+ async function generateExportsTs (
29
29
namespace : string ,
30
30
) : Promise < void > {
31
31
const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
@@ -45,39 +45,44 @@ async function generateModTs(
45
45
const lines = [
46
46
"// NOTE: This file is generated by gen-mod.ts" ,
47
47
...exports . map ( ( x ) => {
48
- return `import { ${ x . name } } from "./${ x . path } ";` ;
48
+ return `export { ${ x . name } as ${ x . name . replace ( namespace , "" ) } } from "./${ x . path } ";` ;
49
49
} ) ,
50
- "" ,
50
+ ] ;
51
+ await Deno . writeTextFile ( join ( path , `${ namespace } .ts` ) , lines . join ( "\n" ) + "\n" ) ;
52
+ }
53
+
54
+ async function generateModTs (
55
+ namespace : string ,
56
+ ) : Promise < void > {
57
+ const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
58
+ const exports = ( await Array . fromAsync (
59
+ flatMap ( iterModules ( path ) , ( x ) => doc ( toFileUrl ( x ) . href ) ) ,
60
+ ) )
61
+ . filter ( ( x ) => ! ! x . jsDoc ?. doc )
62
+ . filter ( ( x ) => x . kind === "function" )
63
+ . filter ( ( x ) => x . declarationKind === "export" )
64
+ . filter ( ( x ) => x . name . startsWith ( namespace ) )
65
+ . map ( ( x ) => ( {
66
+ path : relative ( path , fromFileUrl ( x . location . filename ) ) ,
67
+ name : x . name ,
68
+ doc : x . jsDoc ! . doc ! ,
69
+ } ) )
70
+ . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
71
+ const lines = [
72
+ "// NOTE: This file is generated by gen-mod.ts" ,
51
73
...map ( ( new Set ( exports . map ( ( x ) => x . path ) ) ) . values ( ) , ( x ) => {
52
74
return `export * from "./${ x } ";` ;
53
75
} ) ,
54
- "" ,
55
- "/**" ,
56
- ` * An object containing all the functions in ${ namespace } module.` ,
57
- " */" ,
58
- `export const ${ namespace } : {` ,
59
- ...exports . flatMap ( ( x ) => {
60
- return [
61
- " /**" ,
62
- ...x . doc . split ( "\n" ) . map ( ( line ) => ` * ${ line } ` . trimEnd ( ) ) ,
63
- " */" ,
64
- ` ${ x . name . replace ( namespace , "" ) } : typeof ${ x . name } ;` . trimEnd ( ) ,
65
- ] ;
66
- } ) ,
67
- "} = {" ,
68
- ...exports . flatMap ( ( x ) => {
69
- return [
70
- ` ${ x . name . replace ( namespace , "" ) } : ${ x . name } ,` . trimEnd ( ) ,
71
- ] ;
72
- } ) ,
73
- "};" ,
76
+ `export * as ${ namespace } from "./${ namespace } .ts";` ,
74
77
] ;
75
78
await Deno . writeTextFile ( join ( path , "mod.ts" ) , lines . join ( "\n" ) + "\n" ) ;
76
79
}
77
80
78
81
async function main ( ) : Promise < void > {
79
82
await generateModTs ( "is" ) ;
80
83
await generateModTs ( "as" ) ;
84
+ await generateExportsTs ( "is" ) ;
85
+ await generateExportsTs ( "as" ) ;
81
86
}
82
87
83
88
if ( import . meta. main ) {
0 commit comments