module Formatters
  ( format
  ) where

import Prelude

import Data.Newtype as Newtype
import Data.String as String
import Language (Language)
import Language as Language
import VersionLoader (Version)

format :: Language -> Boolean -> Version -> String
format = case _ of
  Language.JavaScript -> formatJavaScript
  Language.PureScript -> formatPureScript
  Language.TypeScript -> formatJavaScript

formatJavaScript :: Boolean -> Version -> String
formatJavaScript noComment version =
  String.joinWith
    "\n"
    ( (if noComment
        then []
        else ["// Generated by @bouzuya/create-version-module"]) <>
      [ "const version = '" <> (Newtype.unwrap version) <> "';"
      , "export { version };"
      , ""
      ])

formatPureScript :: Boolean -> Version -> String
formatPureScript noComment version =
  String.joinWith
    "\n"
    ( (if noComment
        then []
        else ["-- Generated by @bouzuya/create-version-module"]) <>
      [ "module Version"
      , "  ( version"
      , "  ) where"
      , ""
      , "version :: String"
      , "version = \"" <> (Newtype.unwrap version) <> "\""
      , ""
      ])
