diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 26006b9fc..07ad92c41 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -37,7 +37,7 @@ jobs: - name: Test Code Gen run: | stack install --fast morpheus-graphql-code-gen - npm run code-gen:check + morpheus check hlint: runs-on: ubuntu-latest diff --git a/morpheus-graphql-code-gen/app/Main.hs b/morpheus-graphql-code-gen/app/Main.hs index a0130fb78..6679ba2b5 100644 --- a/morpheus-graphql-code-gen/app/Main.hs +++ b/morpheus-graphql-code-gen/app/Main.hs @@ -37,7 +37,7 @@ import Data.Version (showVersion) import qualified Paths_morpheus_graphql_code_gen as CLI import Relude hiding (ByteString) import System.Exit (ExitCode (..)) -import System.FilePath (normalise, ()) +import System.FilePath (dropFileName, normalise, ()) import System.FilePath.Glob (glob) currentVersion :: String @@ -46,14 +46,18 @@ currentVersion = showVersion CLI.version main :: IO () main = parseCLI >>= runApp +sourcesWithFallback :: [FilePath] -> IO [FilePath] +sourcesWithFallback [] = fmap (map dropFileName) (glob "**/code-gen.yaml") +sourcesWithFallback xs = pure xs + runApp :: App -> IO () runApp App {..} | version options = putStrLn currentVersion | otherwise = runOperation operations where runOperation About = putStrLn $ "Morpheus GraphQL CLI, version " <> currentVersion - runOperation (Build source) = processAll (scan . Context False) source - runOperation (Check source) = processAll (scan . Context True) source + runOperation (Build source) = sourcesWithFallback source >>= processAll False + runOperation (Check source) = sourcesWithFallback source >>= processAll True data Context = Context { isCheck :: Bool, @@ -62,9 +66,9 @@ data Context = Context type CommandResult = Bool -processAll :: (Traversable t, MonadIO m) => (a1 -> m Bool) -> t a1 -> m b -processAll f xs = do - res <- traverse f xs +processAll :: Bool -> [FilePath] -> IO b +processAll check xs = do + res <- traverse (scan . Context check) xs if and res then putStr "\x1b[32mOK\x1b[0m\n" >> exitSuccess else exitWith (ExitFailure 1) diff --git a/package.json b/package.json index 79e900162..5e145f98f 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,6 @@ "private": true, "scripts": { "check:spelling": "cspell --cache --no-progress '**/*.hs'", - "code-gen": "morpheus build morpheus-graphql-server/test examples/code-gen examples/code-gen-docs", - "code-gen:check": "morpheus check morpheus-graphql-server/test examples/code-gen examples/code-gen-docs", "lint": "curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s ." }, "devDependencies": { diff --git a/releasy.json b/releasy.json index 21ed99582..016219246 100644 --- a/releasy.json +++ b/releasy.json @@ -6,7 +6,8 @@ "core": "morpheus-graphql-core", "subscriptions": "morpheus-graphql-subscriptions", "tests": "morpheus-graphql-tests", - "app": "morpheus-graphql-app" + "app": "morpheus-graphql-app", + "codegen": "morpheus-graphql-code-gen" }, "pkg": "https://hackage.haskell.org/package/{{SCOPE}}", "version": "hconf version",