@@ -0,0 +1,167 @@
22+import Data.Either (Either(..))
23+import Data.Maybe (Maybe, maybe)
24+import Effect.Aff (Aff)
25+import Effect.Class (liftEffect)
26+import Node.Buffer (Buffer)
27+import Node.Encoding (Encoding(..))
28+import Node.FS.Aff as FS
29+import Node.Path (FilePath)
30+import Node.Process as Process
34+-- | Error types for file operations
36+ ( fileNotFound :: { path :: FilePath }
37+ , fileReadError :: { path :: FilePath, message :: String }
38+ , fileWriteError :: { path :: FilePath, message :: String }
39+ , fileSystemError :: { message :: String }
43+-- | Error types for environment variable operations
45+ ( envNotFound :: { variable :: String }
49+-- | Read a file as a Buffer
53+ -> Om ctx (FileError err) Buffer
55+ result <- Om.fromAff $ FS.readFile path
58+-- | Read a file as text with UTF-8 encoding
62+ -> Om ctx (FileError err) String
63+readTextFile path = do
64+ result <- Om.fromAff $ FS.readTextFile UTF8 path
67+-- | Write a Buffer to a file
72+ -> Om ctx (FileError err) Unit
73+writeFile path buffer = do
74+ Om.fromAff $ FS.writeFile path buffer
76+-- | Write text to a file with UTF-8 encoding
81+ -> Om ctx (FileError err) Unit
82+writeTextFile path content = do
83+ Om.fromAff $ FS.writeTextFile UTF8 path content
85+-- | Append a Buffer to a file
90+ -> Om ctx (FileError err) Unit
91+appendFile path buffer = do
92+ Om.fromAff $ FS.appendFile path buffer
94+-- | Append text to a file with UTF-8 encoding
99+ -> Om ctx (FileError err) Unit
100+appendTextFile path content = do
101+ Om.fromAff $ FS.appendTextFile UTF8 path content
103+-- | Check if a file or directory exists
107+ -> Om ctx err Boolean
109+ (Om.fromAff $ FS.stat path $> true)
110+ # Om.handleErrors { exception: \_ -> pure false }
112+-- | Create a directory
116+ -> Om ctx (FileError err) Unit
118+ Om.fromAff $ FS.mkdir path
120+-- | Remove a directory
124+ -> Om ctx (FileError err) Unit
126+ Om.fromAff $ FS.rmdir path
132+ -> Om ctx (FileError err) Unit
134+ Om.fromAff $ FS.unlink path
136+-- | Get an environment variable, throwing an error if not found
140+ -> Om ctx (EnvError err) String
142+ value <- lookupEnv variable
143+ value # Om.note { envNotFound: { variable } }
145+-- | Look up an environment variable, returning Maybe
149+ -> Om ctx err (Maybe String)
150+lookupEnv variable = do
151+ Om.fromAff $ liftEffect $ Process.lookupEnv variable
153+-- | Set an environment variable
159+setEnv variable value = do
160+ Om.fromAff $ liftEffect $ Process.setEnv variable value
162+-- | Get the current working directory
165+ . Om ctx err FilePath
167+ Om.fromAff $ liftEffect $ Process.cwd