@@ -25,7 +25,7 @@ async function* iterModules(path: string): AsyncIterable<string> {
2525 }
2626}
2727
28- async function generateModTs (
28+ async function generateExportsTs (
2929 namespace : string ,
3030) : Promise < void > {
3131 const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
@@ -45,39 +45,49 @@ async function generateModTs(
4545 const lines = [
4646 "// NOTE: This file is generated by gen-mod.ts" ,
4747 ...exports . map ( ( x ) => {
48- return `import { ${ x . name } } from "./${ x . path } ";` ;
48+ return `export { ${ x . name } as ${
49+ x . name . replace ( namespace , "" )
50+ } } from "./${ x . path } ";`;
4951 } ) ,
50- "" ,
52+ ] ;
53+ await Deno . writeTextFile (
54+ join ( path , `${ namespace } .ts` ) ,
55+ lines . join ( "\n" ) + "\n" ,
56+ ) ;
57+ }
58+
59+ async function generateModTs (
60+ namespace : string ,
61+ ) : Promise < void > {
62+ const path = fromFileUrl ( import . meta. resolve ( `../${ namespace } /` ) ) ;
63+ const exports = ( await Array . fromAsync (
64+ flatMap ( iterModules ( path ) , ( x ) => doc ( toFileUrl ( x ) . href ) ) ,
65+ ) )
66+ . filter ( ( x ) => ! ! x . jsDoc ?. doc )
67+ . filter ( ( x ) => x . kind === "function" )
68+ . filter ( ( x ) => x . declarationKind === "export" )
69+ . filter ( ( x ) => x . name . startsWith ( namespace ) )
70+ . map ( ( x ) => ( {
71+ path : relative ( path , fromFileUrl ( x . location . filename ) ) ,
72+ name : x . name ,
73+ doc : x . jsDoc ! . doc ! ,
74+ } ) )
75+ . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
76+ const lines = [
77+ "// NOTE: This file is generated by gen-mod.ts" ,
5178 ...map ( ( new Set ( exports . map ( ( x ) => x . path ) ) ) . values ( ) , ( x ) => {
5279 return `export * from "./${ x } ";` ;
5380 } ) ,
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- "};" ,
81+ `export * as ${ namespace } from "./${ namespace } .ts";` ,
7482 ] ;
7583 await Deno . writeTextFile ( join ( path , "mod.ts" ) , lines . join ( "\n" ) + "\n" ) ;
7684}
7785
7886async function main ( ) : Promise < void > {
7987 await generateModTs ( "is" ) ;
8088 await generateModTs ( "as" ) ;
89+ await generateExportsTs ( "is" ) ;
90+ await generateExportsTs ( "as" ) ;
8191}
8292
8393if ( import . meta. main ) {
0 commit comments