mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-24 17:44:21 +03:00
External code paths now again use StrongPath.
This commit is contained in:
parent
391a045164
commit
e115ece29a
@ -60,7 +60,7 @@ getImportDetailsForOperationJsFn
|
||||
getImportDetailsForOperationJsFn operation relPathToExtCodeDir = (importIdentifier, importStmt)
|
||||
where
|
||||
importStmt = "import " ++ importWhat ++ " from '" ++ importFrom ++ "'"
|
||||
importFrom = relPathToExtCodeDir ++ P.toFilePath (Wasp.JsImport._from jsImport)
|
||||
importFrom = relPathToExtCodeDir ++ SP.toFilePath (Wasp.JsImport._from jsImport)
|
||||
(importIdentifier, importWhat) =
|
||||
case (Wasp.JsImport._defaultImport jsImport, Wasp.JsImport._namedImports jsImport) of
|
||||
(Just defaultImport, []) -> (defaultImport, defaultImport)
|
||||
|
@ -2,23 +2,23 @@ module Generator.WebAppGenerator.RouterGenerator
|
||||
( generateRouter
|
||||
) where
|
||||
|
||||
import Data.Aeson (ToJSON(..), (.=), object)
|
||||
import qualified Path as P
|
||||
import Data.Aeson (ToJSON (..), object, (.=))
|
||||
import qualified Path as P
|
||||
|
||||
import StrongPath ((</>))
|
||||
|
||||
import Wasp (Wasp)
|
||||
import qualified Wasp
|
||||
import qualified Wasp.Route
|
||||
import qualified Wasp.Page
|
||||
import qualified Wasp.JsImport
|
||||
|
||||
import Generator.FileDraft (FileDraft)
|
||||
import Generator.WebAppGenerator.Common (asTmplFile, asWebAppSrcFile)
|
||||
import Generator.FileDraft (FileDraft)
|
||||
import Generator.WebAppGenerator.Common (asTmplFile, asWebAppSrcFile)
|
||||
import qualified Generator.WebAppGenerator.Common as C
|
||||
import StrongPath ((</>))
|
||||
import qualified StrongPath as SP
|
||||
import Wasp (Wasp)
|
||||
import qualified Wasp
|
||||
import qualified Wasp.JsImport
|
||||
import qualified Wasp.Page
|
||||
import qualified Wasp.Route
|
||||
|
||||
|
||||
data RouterTemplateData = RouterTemplateData
|
||||
{ _routes :: ![Wasp.Route.Route]
|
||||
{ _routes :: ![Wasp.Route.Route]
|
||||
, _pagesToImport :: ![PageTemplateData]
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ createRouterTemplateData wasp = RouterTemplateData
|
||||
|
||||
createPageTemplateData :: Wasp.Page.Page -> PageTemplateData
|
||||
createPageTemplateData page = PageTemplateData
|
||||
{ _importFrom = relPathToExtSrcDir ++ P.toFilePath (Wasp.JsImport._from pageComponent)
|
||||
{ _importFrom = relPathToExtSrcDir ++ SP.toFilePath (Wasp.JsImport._from pageComponent)
|
||||
, _importWhat = case Wasp.JsImport._namedImports pageComponent of
|
||||
-- If no named imports, we go with the default import.
|
||||
[] -> pageName
|
||||
|
@ -2,19 +2,22 @@ module Parser.ExternalCode
|
||||
( extCodeFilePathString
|
||||
) where
|
||||
|
||||
import Text.Parsec (unexpected)
|
||||
import Text.Parsec.String (Parser)
|
||||
import qualified Path.Posix as PPosix
|
||||
import qualified Path.Posix as PPosix
|
||||
import Text.Parsec (unexpected)
|
||||
import Text.Parsec.String (Parser)
|
||||
|
||||
import ExternalCode (SourceExternalCodeDir)
|
||||
import qualified Parser.Common
|
||||
import StrongPath (File, Path', Posix, Rel)
|
||||
import qualified StrongPath as SP
|
||||
|
||||
|
||||
-- Parses string literal that is file path to file in source external code dir.
|
||||
-- Returns file path relative to the external code dir.
|
||||
-- Example of input: "@ext/some/file.txt". Output would be: "some/file.txt".
|
||||
extCodeFilePathString :: Parser (PPosix.Path PPosix.Rel PPosix.File)
|
||||
extCodeFilePathString :: Parser (Path' Posix (Rel SourceExternalCodeDir) File)
|
||||
extCodeFilePathString = do
|
||||
path <- Parser.Common.relPosixFilePathString
|
||||
maybe (unexpected $ "string \"" ++ (show path) ++ "\": External code file path should start with \"@ext/\".")
|
||||
return
|
||||
maybe (unexpected $ "string \"" ++ show path ++ "\": External code file path should start with \"@ext/\".")
|
||||
(return . SP.fromPathRelFileP)
|
||||
(PPosix.stripProperPrefix [PPosix.reldir|@ext|] path)
|
||||
|
@ -2,21 +2,23 @@ module Wasp.JsImport
|
||||
( JsImport(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson (ToJSON (..), object, (.=))
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Aeson (ToJSON (..), object, (.=))
|
||||
|
||||
import ExternalCode (SourceExternalCodeDir)
|
||||
import StrongPath (File, Path', Posix, Rel)
|
||||
import qualified StrongPath as SP
|
||||
|
||||
|
||||
-- | Represents javascript import -> "import <what> from <from>".
|
||||
data JsImport = JsImport
|
||||
{ _defaultImport :: !(Maybe String)
|
||||
, _namedImports :: ![String]
|
||||
-- Relative to source external code dir.
|
||||
, _from :: !(PPosix.Path PPosix.Rel PPosix.File)
|
||||
, _from :: Path' Posix (Rel SourceExternalCodeDir) File
|
||||
} deriving (Show, Eq)
|
||||
|
||||
instance ToJSON JsImport where
|
||||
toJSON jsImport = object
|
||||
[ "defaultImport" .= _defaultImport jsImport
|
||||
, "namedImports" .= _namedImports jsImport
|
||||
, "from" .= PPosix.toFilePath (_from jsImport)
|
||||
, "from" .= SP.toFilePath (_from jsImport)
|
||||
]
|
||||
|
@ -2,15 +2,17 @@ module Wasp.Style
|
||||
( Style(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson (ToJSON(..))
|
||||
import Data.Text (Text)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Aeson (ToJSON (..))
|
||||
import Data.Text (Text)
|
||||
|
||||
import ExternalCode (SourceExternalCodeDir)
|
||||
import StrongPath (File, Path', Posix, Rel, toFilePath)
|
||||
|
||||
|
||||
data Style = ExtCodeCssFile !(PPosix.Path PPosix.Rel PPosix.File)
|
||||
data Style = ExtCodeCssFile !(Path' Posix (Rel SourceExternalCodeDir) File)
|
||||
| CssCode !Text
|
||||
deriving (Show, Eq)
|
||||
|
||||
instance ToJSON Style where
|
||||
toJSON (ExtCodeCssFile path) = toJSON $ PPosix.toFilePath path
|
||||
toJSON (CssCode code) = toJSON code
|
||||
toJSON (ExtCodeCssFile path) = toJSON $ toFilePath path
|
||||
toJSON (CssCode code) = toJSON code
|
||||
|
@ -1,12 +1,13 @@
|
||||
module Parser.ActionTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Action (action)
|
||||
import Parser.Action (action)
|
||||
import Parser.Common (runWaspParser)
|
||||
import qualified StrongPath as SP
|
||||
import qualified Wasp.Action
|
||||
import qualified Wasp.JsImport
|
||||
|
||||
@ -23,7 +24,7 @@ spec_parseAction =
|
||||
it "When given a valid action declaration, returns correct AST" $ do
|
||||
let testActionName = "myAction"
|
||||
testActionJsFunctionName = "myJsAction"
|
||||
testActionJsFunctionFrom = [PPosix.relfile|some/path|]
|
||||
testActionJsFunctionFrom = SP.fromPathRelFileP [PPosix.relfile|some/path|]
|
||||
let testAction = Wasp.Action.Action
|
||||
{ Wasp.Action._name = testActionName
|
||||
, Wasp.Action._jsFunction = Wasp.JsImport.JsImport
|
||||
|
@ -1,12 +1,13 @@
|
||||
module Parser.ExternalCodeTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import Parser.ExternalCode (extCodeFilePathString)
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.ExternalCode (extCodeFilePathString)
|
||||
import qualified StrongPath as SP
|
||||
|
||||
|
||||
spec_ParserExternalCode :: Spec
|
||||
@ -14,7 +15,7 @@ spec_ParserExternalCode = do
|
||||
describe "Parsing external code file path string" $ do
|
||||
it "Correctly parses external code path in double quotes" $ do
|
||||
runWaspParser extCodeFilePathString "\"@ext/foo/bar.txt\""
|
||||
`shouldBe` Right [PPosix.relfile|foo/bar.txt|]
|
||||
`shouldBe` Right (SP.fromPathRelFileP [PPosix.relfile|foo/bar.txt|])
|
||||
|
||||
it "When path does not start with @ext/, returns Left" $ do
|
||||
isLeft (runWaspParser extCodeFilePathString "\"@ext2/foo/bar.txt\"") `shouldBe` True
|
||||
|
@ -1,32 +1,35 @@
|
||||
module Parser.JsImportTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either (isLeft)
|
||||
import Path.Posix (relfile)
|
||||
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.JsImport (jsImport)
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.JsImport (jsImport)
|
||||
import qualified StrongPath as SP
|
||||
import qualified Wasp
|
||||
|
||||
|
||||
spec_parseJsImport :: Spec
|
||||
spec_parseJsImport = do
|
||||
let someFilePath = SP.fromPathRelFileP [relfile|some/file.js|]
|
||||
|
||||
it "Parses external code js import with default import correctly" $ do
|
||||
runWaspParser jsImport "import something from \"@ext/some/file.js\""
|
||||
`shouldBe` Right (Wasp.JsImport (Just "something") [] [PPosix.relfile|some/file.js|])
|
||||
`shouldBe` Right (Wasp.JsImport (Just "something") [] someFilePath)
|
||||
|
||||
it "Parses correctly when there is whitespace up front" $ do
|
||||
runWaspParser jsImport " import something from \"@ext/some/file.js\""
|
||||
`shouldBe` Right (Wasp.JsImport (Just "something") [] [PPosix.relfile|some/file.js|])
|
||||
`shouldBe` Right (Wasp.JsImport (Just "something") [] someFilePath)
|
||||
|
||||
it "Parses correctly when 'from' is part of WHAT part" $ do
|
||||
runWaspParser jsImport "import somethingfrom from \"@ext/some/file.js\""
|
||||
`shouldBe` Right (Wasp.JsImport (Just "somethingfrom") [] [PPosix.relfile|some/file.js|])
|
||||
`shouldBe` Right (Wasp.JsImport (Just "somethingfrom") [] someFilePath)
|
||||
|
||||
it "Parses correctly when 'what' is a single named export" $ do
|
||||
runWaspParser jsImport "import { something } from \"@ext/some/file.js\""
|
||||
`shouldBe` Right (Wasp.JsImport Nothing ["something"] [PPosix.relfile|some/file.js|])
|
||||
`shouldBe` Right (Wasp.JsImport Nothing ["something"] someFilePath)
|
||||
|
||||
it "For now we don't support multiple named exports in WHAT part" $ do
|
||||
isLeft (runWaspParser jsImport "import { foo, bar } from \"@ext/some/file.js\"")
|
||||
|
@ -1,16 +1,17 @@
|
||||
module Parser.PageTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Page (page)
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Page (page)
|
||||
import qualified StrongPath as SP
|
||||
import qualified Wasp.JsImport
|
||||
import qualified Wasp.Page
|
||||
|
||||
|
||||
spec_parsePage :: Spec
|
||||
spec_parsePage =
|
||||
describe "Parsing page declaration" $ do
|
||||
@ -22,7 +23,7 @@ spec_parsePage =
|
||||
let expectedPageComponentImport = Wasp.JsImport.JsImport
|
||||
{ Wasp.JsImport._defaultImport = Just "Main"
|
||||
, Wasp.JsImport._namedImports = []
|
||||
, Wasp.JsImport._from = [PPosix.relfile|pages/Main|]
|
||||
, Wasp.JsImport._from = (SP.fromPathRelFileP [PPosix.relfile|pages/Main|])
|
||||
}
|
||||
|
||||
parsePage (
|
||||
|
@ -1,22 +1,22 @@
|
||||
module Parser.ParserTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Data.Either
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either
|
||||
import qualified Path.Posix as PPosix
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Parser
|
||||
import Wasp
|
||||
import Parser
|
||||
import qualified StrongPath as SP
|
||||
import Wasp
|
||||
import qualified Wasp.EntityPSL
|
||||
import qualified Wasp.JsCode
|
||||
import qualified Wasp.JsImport
|
||||
import qualified Wasp.Page
|
||||
import qualified Wasp.Query
|
||||
import qualified Wasp.Route as R
|
||||
|
||||
-- TODO(matija): old Entity stuff, to be removed.
|
||||
import qualified Wasp.EntityForm as EF
|
||||
import qualified Wasp.EntityList as EL
|
||||
|
||||
import qualified Wasp.Route as R
|
||||
import qualified Wasp.Page
|
||||
import qualified Wasp.JsCode
|
||||
import qualified Wasp.Query
|
||||
import qualified Wasp.JsImport
|
||||
import qualified Wasp.EntityPSL
|
||||
import qualified Wasp.EntityForm as EF
|
||||
import qualified Wasp.EntityList as EL
|
||||
|
||||
|
||||
spec_parseWasp :: Spec
|
||||
@ -43,7 +43,7 @@ spec_parseWasp =
|
||||
, Wasp.Page._component = Wasp.JsImport.JsImport
|
||||
{ Wasp.JsImport._defaultImport = Just "Landing"
|
||||
, Wasp.JsImport._namedImports = []
|
||||
, Wasp.JsImport._from = [PPosix.relfile|pages/Landing|]
|
||||
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Landing|]
|
||||
}
|
||||
}
|
||||
, WaspElementRoute $ R.Route
|
||||
@ -55,7 +55,7 @@ spec_parseWasp =
|
||||
, Wasp.Page._component = Wasp.JsImport.JsImport
|
||||
{ Wasp.JsImport._defaultImport = Just "Test"
|
||||
, Wasp.JsImport._namedImports = []
|
||||
, Wasp.JsImport._from = [PPosix.relfile|pages/Test|]
|
||||
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|pages/Test|]
|
||||
}
|
||||
}
|
||||
, WaspElementEntityPSL $ Wasp.EntityPSL.EntityPSL
|
||||
@ -124,9 +124,9 @@ spec_parseWasp =
|
||||
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
|
||||
{ Wasp.JsImport._defaultImport = Nothing
|
||||
, Wasp.JsImport._namedImports = [ "myJsQuery" ]
|
||||
, Wasp.JsImport._from = [PPosix.relfile|some/path|]
|
||||
, Wasp.JsImport._from = SP.fromPathRelFileP [PPosix.relfile|some/path|]
|
||||
}
|
||||
}
|
||||
]
|
||||
`setJsImports` [ JsImport (Just "something") [] [PPosix.relfile|some/file|] ]
|
||||
`setJsImports` [ JsImport (Just "something") [] (SP.fromPathRelFileP [PPosix.relfile|some/file|]) ]
|
||||
)
|
||||
|
@ -1,14 +1,16 @@
|
||||
module Parser.QueryTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Query (query)
|
||||
import qualified Wasp.Query
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Query (query)
|
||||
import qualified StrongPath as SP
|
||||
import qualified Wasp.JsImport
|
||||
import qualified Wasp.Query
|
||||
|
||||
|
||||
spec_parseQuery :: Spec
|
||||
spec_parseQuery =
|
||||
@ -18,7 +20,7 @@ spec_parseQuery =
|
||||
it "When given a valid query declaration, returns correct AST" $ do
|
||||
let testQueryName = "myQuery"
|
||||
testQueryJsFunctionName = "myJsQuery"
|
||||
testQueryJsFunctionFrom = [PPosix.relfile|some/path|]
|
||||
testQueryJsFunctionFrom = SP.fromPathRelFileP [PPosix.relfile|some/path|]
|
||||
let testQuery = Wasp.Query.Query
|
||||
{ Wasp.Query._name = testQueryName
|
||||
, Wasp.Query._jsFunction = Wasp.JsImport.JsImport
|
||||
|
@ -1,12 +1,13 @@
|
||||
module Parser.StyleTest where
|
||||
|
||||
import Test.Tasty.Hspec
|
||||
import Test.Tasty.Hspec
|
||||
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
import Data.Either (isLeft)
|
||||
import qualified Path.Posix as PPosix
|
||||
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Style (style)
|
||||
import Parser.Common (runWaspParser)
|
||||
import Parser.Style (style)
|
||||
import qualified StrongPath as SP
|
||||
import qualified Wasp.Style
|
||||
|
||||
|
||||
@ -14,7 +15,7 @@ spec_parseStyle :: Spec
|
||||
spec_parseStyle = do
|
||||
it "Parses external code file path correctly" $ do
|
||||
runWaspParser style "\"@ext/some/file.css\""
|
||||
`shouldBe` Right (Wasp.Style.ExtCodeCssFile [PPosix.relfile|some/file.css|])
|
||||
`shouldBe` Right (Wasp.Style.ExtCodeCssFile (SP.fromPathRelFileP [PPosix.relfile|some/file.css|]))
|
||||
|
||||
it "Parses css closure correctly" $ do
|
||||
runWaspParser style "{=css Some css code css=}"
|
||||
|
Loading…
Reference in New Issue
Block a user