@@ -14,10 +14,10 @@ import chalk from "chalk"
1414import * as NodePath from "path"
1515import * as ChildProcess from "./ChildProcess"
1616import * as Config from "./Config"
17- import type * as Domain from "./Domain"
17+ import * as Domain from "./Domain"
1818import * as FileSystem from "./FileSystem"
1919import { SimpleLogger } from "./Logger"
20- import { printModule } from "./Markdown"
20+ import { printModule , printPrintableForAI } from "./Markdown"
2121import * as Parser from "./Parser"
2222import * as Process from "./Process"
2323
@@ -35,10 +35,8 @@ const readFiles = pipe(
3535 Effect . tap ( ( paths ) => Effect . logInfo ( chalk . bold ( `${ paths . length } module(s) found` ) ) ) ,
3636 Effect . flatMap (
3737 Effect . forEachPar ( ( path ) =>
38- Effect . map (
39- fileSystem . readFile ( path ) ,
40- ( content ) => FileSystem . makeFile ( path , content , false )
41- )
38+ Effect . map ( fileSystem . readFile ( path ) , ( content ) =>
39+ FileSystem . makeFile ( path , content , false ) )
4240 )
4341 )
4442 )
@@ -320,12 +318,9 @@ const getMarkdown = (modules: ReadonlyArray<Domain.Module>) =>
320318 Effect . bind ( "home" , ( ) => getHome ) ,
321319 Effect . bind ( "index" , ( ) => getModulesIndex ) ,
322320 Effect . bind ( "yml" , ( ) => getConfigYML ) ,
323- Effect . flatMap ( ( { home, index, yml } ) =>
324- pipe (
325- getModuleMarkdownFiles ( modules ) ,
326- Effect . map ( ( files ) => [ home , index , yml ] . concat ( files ) )
327- )
328- )
321+ Effect . bind ( "modules" , ( ) => getModuleMarkdownFiles ( modules ) ) ,
322+ Effect . bind ( "ai" , ( ) => maybeGetAIMarkdownFiles ( modules ) ) ,
323+ Effect . map ( ( { ai, home, index, modules, yml } ) => [ home , index , yml ] . concat ( modules ) . concat ( ai ) )
329324 )
330325
331326const getHome = pipe (
@@ -441,6 +436,14 @@ const getMarkdownOutputPath = (module: Domain.Module) =>
441436 `${ module . path . slice ( 1 ) . join ( NodePath . sep ) } .md`
442437 ) )
443438
439+ const getAIMarkdownOutputPath = ( module : Domain . Module , printable : Domain . Printable ) =>
440+ Effect . map ( Config . Config , ( config ) =>
441+ join (
442+ config . outDir ,
443+ "ai" ,
444+ `${ module . path . slice ( 1 ) . join ( "-" ) . replace ( / \. t s $ / , "" ) } -${ printable . name } .md`
445+ ) )
446+
444447const getModuleMarkdownFiles = ( modules : ReadonlyArray < Domain . Module > ) =>
445448 Effect . forEachWithIndex ( modules , ( module , order ) =>
446449 pipe (
@@ -450,6 +453,37 @@ const getModuleMarkdownFiles = (modules: ReadonlyArray<Domain.Module>) =>
450453 Effect . map ( ( { content, outputPath } ) => FileSystem . makeFile ( outputPath , content , true ) )
451454 ) )
452455
456+ const getAIMarkdownFiles = ( projectName : string , modules : ReadonlyArray < Domain . Module > ) =>
457+ pipe (
458+ modules ,
459+ ReadonlyArray . flatMap ( ( module ) =>
460+ pipe (
461+ Domain . printablesFromModule ( module ) ,
462+ ReadonlyArray . map ( ( printable ) => [ module , printable ] as const )
463+ )
464+ ) ,
465+ ReadonlyArray . filter ( ( [ , printable ] ) =>
466+ printable . description . _tag === "Some" &&
467+ ( printable . examples . length > 0 || printable . description . value . includes ( "```" ) ||
468+ printable . description . value . length >= 115 )
469+ ) ,
470+ Effect . forEach ( ( [ module , printable ] ) =>
471+ pipe (
472+ Effect . Do ( ) ,
473+ Effect . bind ( "outputPath" , ( ) => getAIMarkdownOutputPath ( module , printable ) ) ,
474+ Effect . let ( "content" , ( ) => printPrintableForAI ( projectName , module , printable ) ) ,
475+ Effect . map ( ( { content, outputPath } ) => FileSystem . makeFile ( outputPath , content , true ) )
476+ )
477+ )
478+ )
479+
480+ const maybeGetAIMarkdownFiles = ( modules : ReadonlyArray < Domain . Module > ) =>
481+ Effect . flatMap (
482+ Config . Config ,
483+ ( config ) =>
484+ config . enableAI ? getAIMarkdownFiles ( config . projectName , modules ) : Effect . succeed ( [ ] )
485+ )
486+
453487// -------------------------------------------------------------------------------------
454488// writeMarkdown
455489// -------------------------------------------------------------------------------------
0 commit comments