WriteExportList.php

<?php

namespace Tlf\Scrawl\Ext\DefaultExt;

//exports is not the right name.
// but this is an 'export' extension which writes to file EVERYTHING in scrawl->output (or so is the idea)
// this thing needs some configs to determine what to output
// thats gotta go through scrawl?
class WriteExportList extends \Tlf\Scrawl\ExtensionType\DefaultExt {


    public function onPreWriteFiles(){
        $this->writeExportIndexFiles();
    }

    public function writeExportIndexFiles(){
        $keyList = $this->scrawl->getOutputs('key'); 

        $name = "keys";

        $phpExports = "<?php\nreturn ".var_export($keyList,true)."\n?>";
        $this->scrawl->addOutput('file', 'exports/'.$name.'.php', $phpExports);


        //@TODO add a nice little header to the md file so someone not familiar with this lib still knows whats up.
        $mdOutput = '';
        foreach ($keyList??[] as $key=>$output){
            $mdOutput .= "\n# ".$key."\n".$output."\n\n";
        }

        $this->scrawl->addOutput('file', 'exports/'.$name.'.md', $mdOutput);
    
    }

}