packages feed

desert (empty) → 0.1.0.0

raw patch · 7 files changed

+229/−0 lines, 7 filesdep +basedep +bytestringdep +desertsetup-changed

Dependencies added: base, bytestring, desert, directory, filepath, hspec, http-conduit, process, shake, transformers

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2016++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 Author name here 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,31 @@+module Main where++import New+import Build+import Data.List (intercalate)+import Data.Char+import System.Environment (getArgs)++newtype Command = Command { unCommand :: String }+newtype CommandArgs = CommandArgs { unCommandArgs :: [String] }++runPlugin :: Command -> CommandArgs -> IO ()+runPlugin c a = do+  let command = unCommand c+      args = unCommandArgs a+      plugin = case toLower `fmap` command of+        "new" -> new+        p -> error $ "not support plugin: " ++ p++  putStrLn $ "Calling " ++ command ++ " with [" ++ intercalate " " args ++ "]."+  run plugin args++main :: IO ()+main = do+  args <- getArgs+  case args of+    [] -> build+    [cmd] | cmd `elem` ["clean", "run", "test"] -> build+    (command:otherargs) -> runPlugin (Command command)+                                    (CommandArgs otherargs)+
+ desert.cabal view
@@ -0,0 +1,51 @@+name:                desert+version:             0.1.0.0+synopsis:            a simple build tool for OCaml projects+description:         Please see README.md+homepage:            https://github.com/zjhmale/desert+license:             BSD3+license-file:        LICENSE+author:              zjhmale+maintainer:          zjhmale@gmail.com+copyright:           2016 zjhmale+category:            Language+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Build+                     , New+  build-depends:       base >= 4.7 && < 5+                     , bytestring >= 0.10.4.0+                     , directory >= 1.2.1.0+                     , filepath >= 1.3.0.2+                     , process+                     , transformers+                     , http-conduit+                     , shake+  default-language:    Haskell2010+  ghc-options:         -Wall++executable desert+  hs-source-dirs:      app+  main-is:             Main.hs+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall+  build-depends:       base+                     , desert+  default-language:    Haskell2010++test-suite desert-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , desert+                     , hspec+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/zjhmale/desert
+ src/Build.hs view
@@ -0,0 +1,35 @@+module Build where++import Development.Shake++mlFiles :: [String]+mlFiles = ["//*.ml", "//*.mli", "//*.mll", "//*.mly"]++build :: IO ()+build = shakeArgs shakeOptions{shakeFiles="_build"} $ do+  want ["_build/bin/main"]+  want ["_build/bin/test"]++  phony "clean" $ do+    putNormal "Cleaning files in _build"+    removeFilesAfter "_build" ["//*"]++  phony "run" $ do+    cmd "_build/bin/main"++  phony "test" $ do+    cmd "_build/bin/test"++  "_build/bin/main" %> \_ -> do+    cs <- getDirectoryFiles "" mlFiles+    need cs+    () <- cmd "ocamlbuild -use-ocamlfind main.native"+    () <- cmd "mkdir -p _build/bin"+    cmd "mv main.native _build/bin/main"++  "_build/bin/test" %> \_ -> do+    cs <- getDirectoryFiles "" mlFiles+    need cs+    () <- cmd "ocamlbuild -use-ocamlfind -package oUnit test.native"+    () <- cmd "mkdir -p _build/bin"+    cmd "mv test.native _build/bin/test"
+ src/New.hs view
@@ -0,0 +1,79 @@+module New where++import qualified Data.ByteString.Lazy as L+import Data.List (intercalate)+import Network.HTTP.Conduit (simpleHttp)+import System.Directory+import System.FilePath+import System.Process++data DesertPlugin = DesertPlugin { run :: [String] -> IO () }++new :: DesertPlugin+new = DesertPlugin $ \args -> do+  let packageName = head args++  putStrLn $ "Creating new project named " ++ packageName++  alreadyExists <- doesDirectoryExist packageName+  if (not alreadyExists) then createDirectory packageName else return ()++  setCurrentDirectory packageName++  let sourceDir = "src"+      testDir = "test"+      mainFilePath = sourceDir </> "main.ml"+      libHeaderFilePath = sourceDir </> "lib.mli"+      libFilePath = sourceDir </> "lib.ml"+      testFilePath = testDir </> "test.ml"+      readmeFilePath = "README.md" --File path is filename in current dir+      tagFilePath = "_tags"++  createDirectoryIfMissing True sourceDir+  createDirectoryIfMissing True testDir++  writeFile mainFilePath $ intercalate "\n"+    ["open Lib",+     "",+     "let _ = Printf.printf \"hello, we get: %s\\n\" (str_of_t (succ (succ one_t)));"+    ]++  writeFile libHeaderFilePath $ intercalate "\n"+    ["type t",+     "",+     "val one_t : t",+     "val succ : t -> t",+     "val str_of_t : t -> string"+    ]++  writeFile libFilePath $ intercalate "\n"+    ["type t = int",+     "",+     "let one_t = 1",+     "let succ i = i+1",+     "let str_of_t = string_of_int"+    ]++  writeFile testFilePath $ intercalate "\n"+    ["open OUnit",+     "open Lib",+     "",+     "let suite = \"OUnit tests...\" >:::  [\"Fix me\" >:: (fun () -> assert_equal \"1\" (str_of_t (succ (succ one_t))))]",+     "",+     "let _ = run_test_tt_main suite"+    ]++  writeFile tagFilePath $ intercalate "\n"+    ["<src/**>: include",+     "<test/**>: include",+     "<test/**>: package(oUnit)"+    ]++  writeFile readmeFilePath $ intercalate "\n"+    ["#" ++ packageName ++ "!"]++  _ <- rawSystem "git" ["init"]++  simpleHttp "https://raw.githubusercontent.com/github/gitignore/master/OCaml.gitignore" >>= L.writeFile ".gitignore"++  return ()
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}