import{readFile}from"./file";importtype{PageSettings}from"./types/site";import{File}from"./file/classes";/** * Recursively build a website, starting with * the provided file and building all of its dependencies. */constbuildSiteFromFile=(file: File,settings: PageSettings,filesSeenSoFar: Set<string>)=>{if(filesSeenSoFar.has(file.path.toString()))return;filesSeenSoFar.add(file.path.toString());file.write(settings);file.dependencies(settings).map((dependencyFile)=>{buildSiteFromFile(dependencyFile,settings,filesSeenSoFar);});};/** * Build a site from a configuration. */constbuildFromPath=(settings: PageSettings)=>{const{ sourceDir, targetDir, ignorePaths }=settings;// Start off from the root, source dir,// Pootstrap the process by reading the root file as HTML.constdir=readFile(sourceDir.toString()+"/index.html",settings);console.log("Starting with",dir.path.toString());// If we've already seen a file path, we should ignore it.// Ignore paths the user is provided and the target dir --// the target dir could be a subdirectory of the source dir// and we don't want to build the site into itself.constfilePathsSeenSoFar=newSet([
...(ignorePaths??[]),
...(ignorePaths??[]).map((p)=>p+".html"),targetDir.toString(),// hardcode in the .git ignore path so i dont fuck upsourceDir+"/.git",sourceDir+"/.direnv",sourceDir+"/node_modules",targetDir.toString()+".html",targetDir.toString()+"/index.html",]);buildSiteFromFile(dir,settings,filePathsSeenSoFar);};export{buildFromPath};