packages feed

elm-init 1.0.0.2 → 1.0.1.0

raw patch · 14 files changed

+100/−73 lines, 14 filesdep +time

Dependencies added: time

Files

+ README.md view
@@ -0,0 +1,27 @@+# elm-init [![Build Status](https://travis-ci.org/JustusAdam/elm-init.svg?branch=master)](https://travis-ci.org/JustusAdam/elm-init) [![Hackage version](https://img.shields.io/hackage/v/elm-init.svg)](https://hackage.haskell.org/package/elm-init)++Initialize a new empty [Elm](http://elm-lang.org) project.++## Features++Interactive setup tool for a new Elm project.++This tool basically helps you populate your "elm-package.json" file.++Including:++- License chooser (automatically adds license file)+- Version validator++## Install++Install the package from the [Hackage](https://hackage.haskell.org/package/elm-init) with `cabal install elm-init`.++## Use++Simply run++- `elm-init [DIRECTORY]`+- or `elm init [DIRECTORY]` if you have the elm platform installed++`DIRECTORY = '.'` if omitted. `DIRECTORY` need not exist, though needs to be a valid directory name.
elm-init.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                elm-init-version:             1.0.0.2+version:             1.0.1.0 synopsis:            Set up basic structure for an elm project description:   Initialize a new empty elm project with some basic scaffolding according to 'https://github.com/evancz/elm-architecture-tutorial'.@@ -21,14 +21,17 @@   Main.elm   licenses/Apache   licenses/BSD3+  licenses/GPLv2+  licenses/GPLv3   licenses/LGPL2   licenses/LGPL3   licenses/MIT-  licenses/GPLv3-  licenses/GPLv2   index.html +Extra-source-files:+  README.md + executable elm-init   main-is:             Main.hs   other-modules:@@ -46,7 +49,8 @@       aeson >= 0.8,       aeson-pretty >= 0.7,       text >= 1.2,-      containers >= 0.5+      containers >= 0.5,+      time   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:@@ -60,4 +64,4 @@   type:     git   branch:   master   location: git://github.com/JustusAdam/elm-init.git-  tag:      1.0.0.2+  tag:      1.0.1.0
resources/licenses/Apache view
@@ -1,4 +1,4 @@-Copyright [year] [name of copyright owner]+Copyright %d %s  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
resources/licenses/BSD3 view
@@ -1,4 +1,4 @@-Copyright (c) [year] [name of copyright owner]+Copyright (c) %d %s All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
resources/licenses/GPLv2 view
@@ -1,4 +1,4 @@-Copyright (C) [year] [name of copyright owner]+Copyright (C) %d %s  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
resources/licenses/GPLv3 view
@@ -1,4 +1,4 @@-Copyright (C) [year] [name of copyright owner]+Copyright (C) %d %s  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
resources/licenses/LGPL2 view
@@ -1,4 +1,4 @@-Copyright (C) [year] [name of copyright owner]+Copyright (C) %d %s  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
resources/licenses/LGPL3 view
@@ -1,4 +1,4 @@-Copyright (C) [year] [name of copyright owner]+Copyright (C) %d %s  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
resources/licenses/MIT view
@@ -1,4 +1,4 @@-Copyright (c) [year] [name of copyright owner]+Copyright (c) %d %s  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
src/ElmInit.hs view
@@ -7,9 +7,8 @@   , exists   , verifyElmVersion   , makePackage-  , flattenMaybe   ) where -import ElmInit.Interact-import ElmInit.Types-import ElmInit.Util+import           ElmInit.Interact+import           ElmInit.Types+import           ElmInit.Util
src/ElmInit/Interact.hs view
@@ -6,14 +6,14 @@   ) where  -import qualified Control.Arrow            as Arrow (first)-import           Control.Applicative      ((<$>), (<*>))-import           Data.Text                (append)-import           Data.Bool                (bool)-import           ElmInit.Util             (getOr, enumerate)-import           Data.Text                as Text (Text, intercalate, pack)-import           Data.Text.IO             as TextIO (getLine, putStrLn)-import           Prelude                  hiding (getLine, putStrLn)+import           Control.Applicative ((<$>), (<*>))+import qualified Control.Arrow       as Arrow (first)+import           Data.Bool           (bool)+import           Data.Text           (append)+import           Data.Text           as Text (Text, intercalate, pack)+import           Data.Text.IO        as TextIO (getLine, putStrLn)+import           ElmInit.Util        (enumerate, getOr)+import           Prelude             hiding (getLine, putStrLn)   askChoices :: Text -> Int -> [Text] -> IO Text
src/ElmInit/Types.hs view
@@ -12,13 +12,13 @@   ) where  -import           Data.Aeson                   as Aeson (ToJSON, object, (.=),-                                              toJSON, Value)-import           Control.Applicative          ((<*>), (<$>))+import           Control.Applicative          ((<$>), (<*>)) import           Control.Monad                ((<=<))-import           Data.Version                 (Version(Version), makeVersion,-                                              showVersion, parseVersion)-import           Data.Text                    (pack, Text)+import           Data.Aeson                   as Aeson (ToJSON, Value, object,+                                                        toJSON, (.=))+import           Data.Text                    (Text, pack)+import           Data.Version                 (Version (Version), makeVersion,+                                               parseVersion, showVersion) import           Text.ParserCombinators.ReadP (readP_to_S)  
src/ElmInit/Util.hs view
@@ -1,20 +1,15 @@ module ElmInit.Util-  ( flattenMaybe-  , exists+  ( exists   , getOr   , enumerate   ) where   import           Control.Applicative ((<$>), (<*>))-import           Data.Maybe          (fromMaybe)+import           Control.Exception   (IOException, catch) import           Data.Bool           (bool)-import           System.Directory    (doesFileExist, doesDirectoryExist)-import           Control.Exception   (catch, IOException)---flattenMaybe :: Maybe (Maybe a) -> Maybe a-flattenMaybe = fromMaybe Nothing+import           Data.Maybe          (fromMaybe)+import           System.Directory    (doesDirectoryExist, doesFileExist)   exists :: FilePath -> IO Bool
src/Main.hs view
@@ -4,31 +4,34 @@ module Main (main) where  -import           Control.Arrow            as Arrow (first) import           Control.Applicative      ((<$>), (<*>))+import           Control.Arrow            as Arrow (first)+import           Control.Monad            (join) import           Data.Aeson.Encode.Pretty (encodePretty) import           Data.Bool                (bool)-import qualified Data.ByteString          as ByteString (ByteString, hPut,)+import qualified Data.ByteString          as ByteString (ByteString, hPut) import qualified Data.ByteString.Char8    as CBS (pack, unpack) import qualified Data.ByteString.Lazy     as LBS (hPut)+import           Data.Char                (isUpper) import           Data.FileEmbed           (embedFile) import           Data.Text                as Text (Text, append, pack, unpack)-import           Data.Text.IO             as TextIO (getLine, putStrLn)-import           Prelude                  hiding (getLine, putStrLn)+import qualified Data.Text.IO             as TextIO (getLine, putStrLn)+import           Data.Time+import           Data.Version             (Version (..), makeVersion,+                                           showVersion)+import           ElmInit                  (CmdArgs (..), Result,+                                           UserDecisions (..), askChoices,+                                           askChoicesWithOther, exists,+                                           makePackage, verifyElmVersion)+import           Prelude                  hiding (putStrLn) import           System.Directory         (createDirectoryIfMissing,                                            doesDirectoryExist, doesFileExist,                                            getCurrentDirectory, makeAbsolute) import           System.Environment       (getArgs)-import           System.FilePath          (isValid, takeBaseName, (</>), takeExtension)+import           System.FilePath          (isValid, takeBaseName, takeExtension,+                                           (</>)) import           System.IO                (IOMode (WriteMode), withFile)-import           Data.Version             (Version(..), showVersion,-                                          makeVersion)-import           ElmInit                  (Result, UserDecisions(..),-                                          CmdArgs(..), askChoicesWithOther,-                                          exists, verifyElmVersion, makePackage,-                                          flattenMaybe, askChoices)-import          Text.Printf               (printf)-import          Data.Char                 (isUpper)+import           Text.Printf              (printf)   standardDirectories :: [FilePath]@@ -91,7 +94,7 @@     bool       (doesDirectoryExist wd >>=         bool-          (putStrLn "the chosen directory does not exist yet, shall I create it? [y/n]"+          (TextIO.putStrLn "the chosen directory does not exist yet, shall I create it? [y/N]"           >> getResp >>=             bool               (error "Project directory does not exist")  -- I'm so sorry@@ -102,14 +105,13 @@    where     getResp :: IO Bool-    getResp = flip elem ["y", "yes"] <$> getLine+    getResp = flip elem ["y", "yes"] <$> TextIO.getLine      makeDirs = createDirectoryIfMissing True wd   getUserDecisions :: FilePath -> IO UserDecisions-getUserDecisions wd =-  Default+getUserDecisions wd = Default   <$> askChoicesWithOther         "project name?"         0@@ -125,8 +127,8 @@         0         (verifyElmVersion . unpack)         [pack $ showVersion defaultProjectVersion]-  <*> (putStrLn "a quick summary" >> getLine)-  <*> (putStrLn "project repository url" >> getLine)+  <*> (TextIO.putStrLn "a quick summary" >> TextIO.getLine)+  <*> (TextIO.putStrLn "project repository url" >> TextIO.getLine)   <*> askChoicesWithOther         "choose a license"         0@@ -177,7 +179,7 @@   let mainModule = takeBaseName mfn   mainFileRes <- mkFile (wd  </> sourceF </> mfn) $ Just $ mainFile mainModule   indexFileRes <- if makeIndex-    then  mkFile (wd </> "index.html") $ Just $ indexHtml mainModule+    then mkFile (wd </> "index.html") $ Just $ indexHtml mainModule     else return $ return ()   others <- mkFiles $ flip map standardSourceFiles $ Arrow.first ((wd </> sourceF) </>)   return $ mainFileRes:indexFileRes:others@@ -195,19 +197,19 @@     . flip LBS.hPut . encodePretty . makePackage  ---putLicense :: FilePath -> Text -> IO Result-putLicense wd =-  maybe-    (return $ Left "License file not found")-    (fmap-      Right-      . withFile-          (wd </> "LICENSE")-          WriteMode-      . flip ByteString.hPut)-  . flattenMaybe . flip lookup standardLicenses+putLicense :: FilePath -> Text -> IO ()+putLicense wd name =+  case join $ lookup name standardLicenses of+    Nothing -> return ()+    Just contents -> do+      TextIO.putStrLn "The project owner(s): (for the license)"+      authors <- getLine+      (year, _, _) <- toGregorian . utctDay <$> getCurrentTime+      writeFile (wd </> "LICENSE") $+        printf (CBS.unpack contents) year $+          if null authors+            then "[project owners]"+            else authors   main :: IO ()@@ -235,4 +237,4 @@   _         <- putLicense wd (license decisions)    -- report all errors-  mapM_ (either putStrLn return) (resStatic ++ resSource)+  mapM_ (either TextIO.putStrLn return) (resStatic ++ resSource)