1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-01 00:04:58 +03:00

Fix juvix init (#1835)

This commit is contained in:
janmasrovira 2023-02-10 17:53:23 +01:00 committed by GitHub
parent d15a5695fc
commit f897fc2cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 16 deletions

View File

@ -39,16 +39,17 @@ checkNotInProject =
say "You are already in a Juvix project"
embed exitFailure
getPackage :: forall r. (Members '[Embed IO] r) => Sem r Package
getPackage :: forall r. Members '[Embed IO] r => Sem r Package
getPackage = do
tproj <- getProjName
say "Tell me the version of your project [leave empty for 0.0.0]"
say "Write the version of your project [leave empty for 0.0.0]"
root <- getCurrentDir
let pkg = defaultPackage root (rootBuildDir root)
tversion :: SemVer <- getVersion
return
Package
pkg
{ _packageName = tproj,
_packageVersion = Ideal tversion,
_packageDependencies = mempty
_packageVersion = Ideal tversion
}
getProjName :: forall r. (Members '[Embed IO] r) => Sem r Text
@ -59,7 +60,7 @@ getProjName = do
Nothing -> mempty
Just d' -> " [leave empty for '" <> d' <> "']"
say
( "Tell me the name of your project"
( "Write the name of your project"
<> defMsg
<> " (lower case letters, numbers and dashes are allowed): "
)

View File

@ -14,7 +14,7 @@ module Juvix.Compiler.Pipeline.Package
)
where
import Data.Aeson (genericToEncoding)
import Data.Aeson (genericToEncoding, genericToJSON)
import Data.Aeson.BetterErrors
import Data.Aeson.TH
import Data.Kind qualified as GHC
@ -61,15 +61,16 @@ deriving stock instance Show RawPackage
deriving stock instance Show Package
rawPackageOptions :: Options
rawPackageOptions =
defaultOptions
{ fieldLabelModifier = over Lens._head toLower . dropPrefix "_package",
rejectUnknownFields = True
}
instance ToJSON RawPackage where
toEncoding = genericToEncoding options
where
options :: Options
options =
defaultOptions
{ fieldLabelModifier = over Lens._head toLower . dropPrefix "_package",
rejectUnknownFields = True
}
toJSON = genericToJSON rawPackageOptions
toEncoding = genericToEncoding rawPackageOptions
-- | TODO: is it a good idea to return the empty package if it fails to parse?
instance FromJSON RawPackage where
@ -93,7 +94,7 @@ rawDefaultPackage =
-- | Has the implicit stdlib dependency
defaultPackage :: Path Abs Dir -> Path Abs Dir -> Package
defaultPackage r buildDir = fromRight impossible . run . runError @Text . processPackage r buildDir $ rawDefaultPackage
defaultPackage root buildDir = fromRight impossible . run . runError @Text . processPackage root buildDir $ rawDefaultPackage
-- | Has no dependencies
emptyPackage :: Package

View File

@ -38,6 +38,7 @@ deriving stock instance Show RawDependency
deriving stock instance Show Dependency
instance ToJSON RawDependency where
toJSON (Dependency p) = toJSON (fromSomeDir p)
toEncoding (Dependency p) = toEncoding (fromSomeDir p)
instance FromJSON RawDependency where

View File

@ -0,0 +1,19 @@
working-directory: ./../../../tests/
tests:
- name: init
command:
shell:
- bash
script: |
mkdir tmp
cd tmp
juvix init
cat juvix.yaml
cd ..
rm -rf tmp
stdout:
contains:
"name: tmp"
stdin: "\n\n"
exit-status: 0