Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1047 #1048

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Add continuous integration via Github Actions. With cache.
* [Issue #991](https://github.com/AmpersandTarski/Ampersand/issues/991) CLI interface has changed. Changes are documented in Commands.md
* [Issue #1029](https://github.com/AmpersandTarski/Ampersand/issues/1029) Fixed detection of rules with same name.
* [Issue #1047](https://github.com/AmpersandTarski/Ampersand/issues/1047) Non-existing directory is generated automagically when required for output.

## v3.17.4 (13 september 2019)

Expand Down
5 changes: 4 additions & 1 deletion src/Ampersand/Commands/Devoutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import Ampersand.Misc.HasClasses
import Ampersand.Output.FSpec2SQL
import qualified RIO.Text as T
import RIO.Time
import System.FilePath ((</>), (-<.>))
import System.Directory
import System.FilePath
-- | Dumps diagnostic output for development purposes
--
devoutput :: (HasDirOutput env, HasRootFile env, HasLogFunc env)
Expand All @@ -33,6 +34,7 @@ doGenHaskell fSpec = do
now <- getCurrentTime
outputFile <- outputFile' <$> ask
logDebug $ "Generating Haskell source code for " <> display (T.pack $ name fSpec) <> "..."
liftIO $ createDirectoryIfMissing True (takeDirectory outputFile)
writeFileUtf8 outputFile (T.pack $ fSpec2Haskell env now fSpec)
logInfo $ "Haskell written into " <> display (T.pack outputFile)
where
Expand All @@ -44,6 +46,7 @@ doGenSQLdump fSpec = do
env <- ask
outputFile <- outputFile' <$> ask
logDebug $ "Generating SQL queries dumpfile for " <> display (T.pack $ name fSpec) <> "..."
liftIO $ createDirectoryIfMissing True (takeDirectory outputFile)
writeFileUtf8 outputFile (dumpSQLqueries env fSpec)
logInfo $ "SQL queries dumpfile written into " <> display (T.pack outputFile)
where
Expand Down
2 changes: 2 additions & 0 deletions src/Ampersand/Commands/ExportAsADL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Ampersand.Core.ShowAStruct
import Ampersand.FSpec
import Ampersand.Misc.HasClasses
import qualified RIO.Text as T
import System.Directory
import System.FilePath

-- | For importing and analysing data, Ampersand allows you to annotate an Excel spreadsheet (.xlsx) and turn it into an Ampersand model.
Expand All @@ -26,6 +27,7 @@ exportAsAdl :: (HasOutputFile env, HasDirOutput env, HasLogFunc env) => FSpec ->
exportAsAdl fSpec = do
env <- ask
logDebug $ "Generating data analysis script (ADL) for " <> display (T.pack $ name fSpec) <> "..."
liftIO $ createDirectoryIfMissing True (takeDirectory (outputFile' env))
writeFileUtf8 (outputFile' env) (T.pack $ showA ctx)
logInfo $ ".adl-file written to: " <> display (T.pack $ outputFile' env)
where outputFile' env = view dirOutputL env </> view outputfileL env
Expand Down
4 changes: 3 additions & 1 deletion src/Ampersand/Commands/Population.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import Ampersand.Misc.HasClasses
import Ampersand.FSpec(FSpec(..))
import Ampersand.Output.Population2Xlsx (fSpec2PopulationXlsx)
import Ampersand.Output.ToJSON.ToJson
import System.FilePath
import qualified RIO.ByteString.Lazy as BL
import qualified RIO.Text as T
import System.Directory
import System.FilePath
import Text.Pandoc.Class(runIO,getPOSIXTime) --TODO: Replace by RIO's getCurrentTime
import Text.Pandoc.Error(handleError)

Expand All @@ -33,6 +34,7 @@ population fSpec = do
case format of
XLSX -> do let outputFile = view dirOutputL env </> baseName env <> "_generated_pop" -<.> ".xlsx"
ct <- liftIO $ runIO getPOSIXTime >>= handleError
liftIO $ createDirectoryIfMissing True (takeDirectory outputFile)
BL.writeFile outputFile $ fSpec2PopulationXlsx ct fSpec
logInfo $ "Generated file: " <> display (T.pack outputFile)
JSON -> do let dir = view dirOutputL env
Expand Down
4 changes: 3 additions & 1 deletion src/Ampersand/Commands/Proof.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Ampersand.Basics
import Ampersand.Misc.HasClasses
import Ampersand.FSpec
import qualified RIO.Text as T
import System.FilePath ((</>), (-<.>))
import System.FilePath
import System.Directory
import Text.Pandoc (runIO,writeHtml5String,def,handleError)
import Text.Pandoc.Builder

Expand All @@ -27,6 +28,7 @@ proof fSpec = do
env <- ask
logInfo $ "Generating Proof for " <> display( T.pack $ name fSpec) <> " into " <> display(T.pack $ outputFile env) <> "..."
content <- liftIO $ (runIO (writeHtml5String def thePandoc)) >>= handleError
liftIO $ createDirectoryIfMissing True (takeDirectory (outputFile env))
writeFileUtf8 (outputFile env) content
logDebug "Proof written."
where
Expand Down
2 changes: 2 additions & 0 deletions src/Ampersand/Commands/Uml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Ampersand.Misc.HasClasses
import Ampersand.FSpec
import Ampersand.FSpec.GenerateUML
import qualified RIO.Text as T
import System.Directory
import System.FilePath
-- | Generate a UML output file from a project.
--
Expand All @@ -25,6 +26,7 @@ uml fSpec = do
env <- ask
outputFile <- outputFile' <$> ask
logDebug "Generating UML..."
liftIO $ createDirectoryIfMissing True (takeDirectory outputFile)
writeFileUtf8 outputFile $ generateUML env fSpec
logInfo ("Generated file: " <> display (T.pack outputFile) <> ".")
where outputFile' env = view dirOutputL env </> baseName env -<.> ".xmi"
Expand Down
8 changes: 6 additions & 2 deletions src/Ampersand/Output/PandocAux.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import RIO.Char hiding (Space)
import qualified RIO.Text as T
import qualified RIO.ByteString.Lazy as BL
import qualified RIO.Text.Partial as Partial (replace)
import System.FilePath -- (combine,addExtension,replaceExtension)
import System.Directory
import System.FilePath
import Text.Pandoc
import Text.Pandoc.Builder
import Text.Pandoc.PDF (makePDF)
Expand Down Expand Up @@ -149,6 +150,7 @@ writepandoc' env fSpec thePandoc = liftIO . runIOorExplode $ do
res <- f writerOptions thePandoc -- >>= handleError
let content :: LByteString
content = res
liftIO $ createDirectoryIfMissing True (takeDirectory (outputFile env))
BL.writeFile (outputFile env) content
TextWriter f -> case view fspecFormatL env of
Fpdf -> do
Expand All @@ -172,7 +174,9 @@ writepandoc' env fSpec thePandoc = liftIO . runIOorExplode $ do
FPandoc -> "native"
fmt -> map toLower . drop 1 . show $ fmt
writeFnBinary :: MonadIO m => FilePath -> BL.ByteString -> m()
writeFnBinary f = liftIO . BL.writeFile (UTF8.encodePath f)
writeFnBinary f bs = do
liftIO $ createDirectoryIfMissing True (takeDirectory f)
liftIO . BL.writeFile (UTF8.encodePath f) $ bs

writerOptions :: WriterOptions
writerOptions = def
Expand Down
1 change: 1 addition & 0 deletions src/Ampersand/Prototype/PHP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ executePHPStr phpStr = do
return "."
)
let phpPath = tempdir </> "tmpPhpQueryOfAmpersand" <.> "php"
liftIO $ createDirectoryIfMissing True (takeDirectory phpPath)
writeFileUtf8 phpPath phpStr

executePHP phpPath
Expand Down