get the nearest elm.json
parent
cf0dda73b7
commit
6bb6ee6cf4
|
@ -59,7 +59,8 @@ executable elm-swapper
|
|||
|
||||
-- Other library packages from which modules are imported.
|
||||
build-depends: base ^>=4.12.0.0,
|
||||
directory ^>=1.3.3.0
|
||||
directory ^>=1.3.3.0,
|
||||
filepath ^>=1.4.2.1
|
||||
|
||||
-- Directories containing source files.
|
||||
hs-source-dirs: src
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{ mkDerivation, base, directory, stdenv }:
|
||||
{ mkDerivation, base, directory, filepath, stdenv }:
|
||||
mkDerivation {
|
||||
pname = "elm-swapper";
|
||||
version = "0.1.0.0";
|
||||
src = ./.;
|
||||
isLibrary = false;
|
||||
isExecutable = true;
|
||||
executableHaskellDepends = [ base directory ];
|
||||
executableHaskellDepends = [ base directory filepath ];
|
||||
description = "automatically dispatch to the right version of Elm";
|
||||
license = "unknown";
|
||||
hydraPlatforms = stdenv.lib.platforms.none;
|
||||
|
|
23
src/Main.hs
23
src/Main.hs
|
@ -1,8 +1,27 @@
|
|||
module Main where
|
||||
|
||||
import System.Directory
|
||||
import System.FilePath
|
||||
|
||||
nearestElmJson :: IO (Maybe FilePath)
|
||||
nearestElmJson =
|
||||
getCurrentDirectory >>= nearestElmJsonHelp
|
||||
|
||||
nearestElmJsonHelp :: FilePath -> IO (Maybe FilePath)
|
||||
nearestElmJsonHelp filepath = do
|
||||
let candidate = filepath </> "elm.json"
|
||||
exists <- doesFileExist candidate
|
||||
if exists then
|
||||
pure $ Just candidate
|
||||
else
|
||||
let next = takeDirectory filepath in
|
||||
|
||||
if next == filepath then
|
||||
pure Nothing
|
||||
else
|
||||
nearestElmJsonHelp next
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
here <- getCurrentDirectory
|
||||
putStrLn here
|
||||
elmJson <- nearestElmJson
|
||||
putStrLn (show elmJson)
|
||||
|
|
Loading…
Reference in New Issue