44
55import { Path } from "@effect/platform-node"
66import chalk from "chalk"
7- import { Console , Effect , Layer , Logger , LogLevel , ReadonlyArray , String } from "effect"
7+ import { Console , Effect , Layer , Logger , LogLevel , pipe , ReadonlyArray , String } from "effect"
88import * as ChildProcess from "./CommandExecutor.js"
99import * as Config from "./Config.js"
10- import type * as Domain from "./Domain.js"
10+ import * as Domain from "./Domain.js"
1111import * as FileSystem from "./FileSystem.js"
1212import { SimpleLogger } from "./Logger.js"
13- import { printModule } from "./Markdown.js"
13+ import { printModule , printPrintableForAI } from "./Markdown.js"
1414import * as Parser from "./Parser.js"
1515import * as Process from "./Process.js"
1616
@@ -289,7 +289,8 @@ const getMarkdown = (modules: ReadonlyArray<Domain.Module>) =>
289289 const index = yield * _ ( getMarkdownIndex )
290290 const yml = yield * _ ( getMarkdownConfigYML )
291291 const moduleFiles = yield * _ ( getModuleMarkdownFiles ( modules ) )
292- return [ homepage , index , yml , ...moduleFiles ]
292+ const aiFiles = yield * _ ( maybeGetAIMarkdownFiles ( modules ) )
293+ return [ homepage , index , yml , ...moduleFiles , ...aiFiles ]
293294 } )
294295
295296const getMarkdownHomepage = Effect . gen ( function * ( _ ) {
@@ -388,6 +389,14 @@ const getModuleMarkdownOutputPath = (module: Domain.Module) =>
388389 `${ module . path . slice ( 1 ) . join ( path . sep ) } .md`
389390 ) ) )
390391
392+ const getAIMarkdownOutputPath = ( module : Domain . Module , printable : Domain . Printable ) =>
393+ Effect . map ( Effect . all ( [ Config . Config , Path . Path ] ) , ( [ config , path ] ) =>
394+ path . join (
395+ config . outDir ,
396+ "ai" ,
397+ `${ module . path . slice ( 1 ) . join ( "-" ) . replace ( / \. t s $ / , "" ) } -${ printable . name } .md`
398+ ) )
399+
391400const getModuleMarkdownFiles = ( modules : ReadonlyArray < Domain . Module > ) =>
392401 Effect . forEach ( modules , ( module , order ) =>
393402 Effect . gen ( function * ( _ ) {
@@ -396,6 +405,34 @@ const getModuleMarkdownFiles = (modules: ReadonlyArray<Domain.Module>) =>
396405 return FileSystem . createFile ( outputPath , content , true )
397406 } ) )
398407
408+ const getAIMarkdownFiles = ( projectName : string , modules : ReadonlyArray < Domain . Module > ) =>
409+ Effect . gen ( function * ( _ ) {
410+ const aiModules = pipe (
411+ modules ,
412+ ReadonlyArray . flatMap ( ( module ) =>
413+ pipe (
414+ Domain . printablesFromModule ( module ) ,
415+ ReadonlyArray . map ( ( printable ) => ( { module, printable } ) )
416+ )
417+ ) ,
418+ ReadonlyArray . filter ( ( { printable } ) => printable . description . _tag === "Some" )
419+ )
420+
421+ return yield * _ ( Effect . forEach ( aiModules , ( { module, printable } ) =>
422+ Effect . gen ( function * ( _ ) {
423+ const outputPath = yield * _ ( getAIMarkdownOutputPath ( module , printable ) )
424+ const content = yield * _ ( printPrintableForAI ( projectName , module , printable ) )
425+ return FileSystem . createFile ( outputPath , content , true )
426+ } ) ) )
427+ } )
428+
429+ const maybeGetAIMarkdownFiles = ( modules : ReadonlyArray < Domain . Module > ) =>
430+ Effect . flatMap (
431+ Config . Config ,
432+ ( config ) =>
433+ config . enableAI ? getAIMarkdownFiles ( config . projectName , modules ) : Effect . succeed ( [ ] )
434+ )
435+
399436const writeMarkdown = ( files : ReadonlyArray < FileSystem . File > ) =>
400437 Effect . gen ( function * ( _ ) {
401438 const config = yield * _ ( Config . Config )
0 commit comments