@@ -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,44 @@ 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 ${ x . name . replace ( namespace , "" ) } } from "./${ x . path } ";` ;
4949 } ) ,
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" ,
5173 ...map ( ( new Set ( exports . map ( ( x ) => x . path ) ) ) . values ( ) , ( x ) => {
5274 return `export * from "./${ x } ";` ;
5375 } ) ,
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";` ,
7477 ] ;
7578 await Deno . writeTextFile ( join ( path , "mod.ts" ) , lines . join ( "\n" ) + "\n" ) ;
7679}
7780
7881async function main ( ) : Promise < void > {
7982 await generateModTs ( "is" ) ;
8083 await generateModTs ( "as" ) ;
84+ await generateExportsTs ( "is" ) ;
85+ await generateExportsTs ( "as" ) ;
8186}
8287
8388if ( import . meta. main ) {
0 commit comments