stack-templatizer (empty) → 0.1.0.0
raw patch · 6 files changed
+172/−0 lines, 6 filesdep +basedep +bytestringdep +directorysetup-changed
Dependencies added: base, bytestring, directory, filepath
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- README.md +24/−0
- Setup.hs +2/−0
- src/Main.hs +65/−0
- stack-templatizer.cabal +46/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# CHANGELOG++## v0.1.0.0++* Initial Release
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Pavan Rikhi (c) 2020++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Pavan Rikhi nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,24 @@+# stack-templatizer++Stack Templatizer is a small application that lets you generate stack template+`hsfiles` from a folder.++Install or clone & build the project using `stack`:++```+# Install from Stack Nightly+stack install stack-templatizer --nightly++# Or build and install from source+git clone https://github.com/prikhi/stack-templatizer+cd stack-templatizer+stack install+```++Once installed, you can run `stack-templatizer my-template-folder` to generate+a `my-template-folder.hsfiles` stack template.+++# LICENSE++BSD-3-Clause
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Main.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TupleSections #-}+module Main where++import System.Directory ( listDirectory+ , doesDirectoryExist+ )+import System.Environment ( getArgs )+import System.Exit ( exitFailure )+import System.FilePath ( (</>) )++import qualified Data.ByteString.Lazy as LBS+import qualified Data.ByteString.Lazy.Char8 as LC++main :: IO ()+main = getArgs >>= \case+ [folderName] ->+ templatize folderName >>= LBS.writeFile (folderName ++ ".hsfiles")+ _ -> printHelp >> exitFailure+++printHelp :: IO ()+printHelp = mapM_+ putStrLn+ [ "stack-templatizer: Generate Stack Templates from a Folder"+ , ""+ , "Usage: stack-templatizer FOLDER_NAME"+ , ""+ , "The generated file will be named `<folder-name>.hsfiles`"+ ]+++templatize :: FilePath -> IO LBS.ByteString+templatize folder = do+ fileNames <- getFilesInDirectory folder+ namesAndContents <- mapM+ (\file -> (file, ) <$> LBS.readFile (folder </> file))+ fileNames+ return $ generateHFiles namesAndContents+++getFilesInDirectory :: FilePath -> IO [FilePath]+getFilesInDirectory baseDirectory = do+ basePaths <- listDirectory baseDirectory+ concat <$> mapM (recursiveList "") basePaths+ where+ recursiveList :: String -> FilePath -> IO [FilePath]+ recursiveList parentDir path = do+ let templatePath = parentDir </> path+ fullPath = baseDirectory </> templatePath+ isDirectory <- doesDirectoryExist fullPath+ if isDirectory+ then do+ files <- listDirectory fullPath+ concat <$> mapM (recursiveList templatePath) files+ else return [templatePath]+++generateHFiles :: [(FilePath, LBS.ByteString)] -> LBS.ByteString+generateHFiles = LBS.intercalate "\n" . map prefixName+ where+ prefixName :: (FilePath, LBS.ByteString) -> LBS.ByteString+ prefixName (file, contents) =+ "{-# START_FILE " <> LC.pack file <> " #-}\n" <> contents
+ stack-templatizer.cabal view
@@ -0,0 +1,46 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.33.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: f1451b06cd9492b434d22bd403c92534b61f1f9a09e0df1d4fd4a588e47c33e4++name: stack-templatizer+version: 0.1.0.0+synopsis: Generate a stack template from a folder.+description: @stack-templatizer@ is an application that generates a @.hsfiles@ stack+ template from a folder of template files.+ .+ You can install the application using @stack install stack-templatizer+ --resolver nightly@ or by cloning the repository and running @stack+ install@+category: Web+homepage: https://github.com/prikhi/stack-templatizer#readme+bug-reports: https://github.com/prikhi/stack-templatizer/issues+author: Pavan Rikhi+maintainer: pavan.rikhi@gmail.com+copyright: 2020 Pavan Rikhi+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ CHANGELOG.md++source-repository head+ type: git+ location: https://github.com/prikhi/stack-templatizer++executable stack-templatizer+ main-is: Main.hs+ other-modules:+ Paths_stack_templatizer+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , bytestring <1+ , directory >=1 && <2+ , filepath >=1 && <2+ default-language: Haskell2010