Fix puppeteer config to be portable across directories
- Embed puppeteer configuration in Mermaid module - Create temporary config files instead of relying on external file - Remove standalone puppeteer-config.json file - Ensures docster works from any directory without config dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
4ae2321cfd
commit
7d2b407908
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"args": ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
||||||
}
|
|
||||||
@ -16,8 +16,10 @@ import qualified Data.Text as T
|
|||||||
import qualified Data.Text.IO as TIO
|
import qualified Data.Text.IO as TIO
|
||||||
import Data.Hashable (hash)
|
import Data.Hashable (hash)
|
||||||
import System.FilePath (takeFileName, (</>))
|
import System.FilePath (takeFileName, (</>))
|
||||||
import System.Directory (removeFile)
|
import System.Directory (removeFile, getTemporaryDirectory)
|
||||||
import System.Process (callProcess)
|
import System.Process (callProcess)
|
||||||
|
import System.IO (hClose)
|
||||||
|
import System.IO.Temp (openTempFile)
|
||||||
import Control.Exception (bracket, catch, SomeException)
|
import Control.Exception (bracket, catch, SomeException)
|
||||||
|
|
||||||
-- | Application constants
|
-- | Application constants
|
||||||
@ -77,17 +79,30 @@ generateDiagramPaths (DiagramConfig (SourceDir sourceDir) format) (DiagramId dia
|
|||||||
PDF -> let pngFile = sourceDir </> diagIdStr <> ".png"
|
PDF -> let pngFile = sourceDir </> diagIdStr <> ".png"
|
||||||
in (pngFile, T.pack pngFile)
|
in (pngFile, T.pack pngFile)
|
||||||
|
|
||||||
|
-- | Puppeteer configuration content for disabling sandbox
|
||||||
|
puppeteerConfigContent :: Text
|
||||||
|
puppeteerConfigContent = "{\n \"args\": [\"--no-sandbox\", \"--disable-setuid-sandbox\"]\n}"
|
||||||
|
|
||||||
-- | Call mermaid CLI process with appropriate arguments
|
-- | Call mermaid CLI process with appropriate arguments
|
||||||
callMermaidProcess :: OutputFormat -> FilePath -> FilePath -> IO (Either DocsterError ())
|
callMermaidProcess :: OutputFormat -> FilePath -> FilePath -> IO (Either DocsterError ())
|
||||||
callMermaidProcess format mmdFile outputFile = do
|
callMermaidProcess format mmdFile outputFile = do
|
||||||
let baseArgs = case format of
|
let baseArgs = case format of
|
||||||
HTML -> ["-i", mmdFile, "-o", outputFile]
|
HTML -> ["-i", mmdFile, "-o", outputFile]
|
||||||
PDF -> ["-i", mmdFile, "-o", outputFile, "--scale", "3"]
|
PDF -> ["-i", mmdFile, "-o", outputFile, "--scale", "3"]
|
||||||
args = baseArgs ++ ["--puppeteerConfigFile", "puppeteer-config.json"]
|
|
||||||
|
|
||||||
result <- catch
|
-- Create temporary puppeteer config file
|
||||||
(callProcess (T.unpack mermaidCommand) args >> return (Right ()))
|
result <- bracket
|
||||||
(\(e :: SomeException) -> return $ Left $ ProcessError $ "Mermaid process failed: " <> T.pack (show e))
|
(do tempDir <- getTemporaryDirectory
|
||||||
|
(configPath, configHandle) <- openTempFile tempDir "puppeteer-config.json"
|
||||||
|
hClose configHandle
|
||||||
|
TIO.writeFile configPath puppeteerConfigContent
|
||||||
|
return configPath)
|
||||||
|
(\configPath -> removeFile configPath `catch` \(_ :: SomeException) -> return ())
|
||||||
|
(\configPath -> do
|
||||||
|
let args = baseArgs ++ ["--puppeteerConfigFile", configPath]
|
||||||
|
catch
|
||||||
|
(callProcess (T.unpack mermaidCommand) args >> return (Right ()))
|
||||||
|
(\(e :: SomeException) -> return $ Left $ ProcessError $ "Mermaid process failed: " <> T.pack (show e)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
-- | Create Pandoc image block from image path
|
-- | Create Pandoc image block from image path
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user