{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
module Text.TypeScript
(
tsc
, tscJSX
, typeScriptFile
, typeScriptJSXFile
, typeScriptFileReload
, typeScriptJSXFileReload
#ifdef TEST_EXPORT
, typeScriptSettings
, typeScriptJSXSettings
#endif
) where
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import Text.Shakespeare
import Text.Julius
typeScriptSettings :: Q ShakespeareSettings
typeScriptSettings :: Q ShakespeareSettings
typeScriptSettings = do
ShakespeareSettings
jsettings <- Q ShakespeareSettings
javascriptSettings
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ShakespeareSettings
jsettings { varChar :: Char
varChar = Char
'#'
, preConversion :: Maybe PreConvert
preConversion = forall a. a -> Maybe a
Just PreConvert {
preConvert :: PreConversion
preConvert = String -> [String] -> PreConversion
ReadProcess String
"sh" [String
"-c", String
"TMP_IN=$(mktemp XXXXXXXXXX.ts); TMP_OUT=$(mktemp XXXXXXXXXX.js); cat /dev/stdin > ${TMP_IN} && tsc --out ${TMP_OUT} ${TMP_IN} && cat ${TMP_OUT}; rm ${TMP_IN} && rm ${TMP_OUT}"]
, preEscapeIgnoreBalanced :: String
preEscapeIgnoreBalanced = String
"'\""
, preEscapeIgnoreLine :: String
preEscapeIgnoreLine = String
"//"
, wrapInsertion :: Maybe WrapInsertion
wrapInsertion = forall a. a -> Maybe a
Just WrapInsertion {
wrapInsertionIndent :: Maybe String
wrapInsertionIndent = forall a. Maybe a
Nothing
, wrapInsertionStartBegin :: String
wrapInsertionStartBegin = String
";(function("
, wrapInsertionSeparator :: String
wrapInsertionSeparator = String
", "
, wrapInsertionStartClose :: String
wrapInsertionStartClose = String
"){"
, wrapInsertionEnd :: String
wrapInsertionEnd = String
"})"
, wrapInsertionAddParens :: Bool
wrapInsertionAddParens = Bool
False
}
}
}
typeScriptJSXSettings :: Q ShakespeareSettings
typeScriptJSXSettings :: Q ShakespeareSettings
typeScriptJSXSettings = do
ShakespeareSettings
tsSettings <- Q ShakespeareSettings
typeScriptSettings
let rp :: PreConversion
rp = String -> [String] -> PreConversion
ReadProcess String
"sh" [String
"-c", String
"TMP_IN=$(mktemp XXXXXXXXXX.tsx); TMP_OUT=$(mktemp XXXXXXXXXX.js); cat /dev/stdin > ${TMP_IN} && tsc --module amd --jsx react --out ${TMP_OUT} ${TMP_IN} && cat ${TMP_OUT}; rm ${TMP_IN} && rm ${TMP_OUT}"]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ShakespeareSettings
tsSettings {
preConversion :: Maybe PreConvert
preConversion = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\PreConvert
pc -> PreConvert
pc { preConvert :: PreConversion
preConvert = PreConversion
rp }) (ShakespeareSettings -> Maybe PreConvert
preConversion ShakespeareSettings
tsSettings)
}
tsc :: QuasiQuoter
tsc :: QuasiQuoter
tsc = QuasiQuoter { quoteExp :: String -> Q Exp
quoteExp = \String
s -> do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
QuasiQuoter -> String -> Q Exp
quoteExp (ShakespeareSettings -> QuasiQuoter
shakespeare ShakespeareSettings
rs) String
s
}
tscJSX :: QuasiQuoter
tscJSX :: QuasiQuoter
tscJSX = QuasiQuoter { quoteExp :: String -> Q Exp
quoteExp = \String
s -> do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
QuasiQuoter -> String -> Q Exp
quoteExp (ShakespeareSettings -> QuasiQuoter
shakespeare ShakespeareSettings
rs) String
s
}
typeScriptFile :: FilePath -> Q Exp
typeScriptFile :: String -> Q Exp
typeScriptFile String
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
ShakespeareSettings -> String -> Q Exp
shakespeareFile ShakespeareSettings
rs String
fp
typeScriptJSXFile :: FilePath -> Q Exp
typeScriptJSXFile :: String -> Q Exp
typeScriptJSXFile String
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
ShakespeareSettings -> String -> Q Exp
shakespeareFile ShakespeareSettings
rs String
fp
typeScriptFileReload :: FilePath -> Q Exp
typeScriptFileReload :: String -> Q Exp
typeScriptFileReload String
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
ShakespeareSettings -> String -> Q Exp
shakespeareFileReload ShakespeareSettings
rs String
fp
typeScriptJSXFileReload :: FilePath -> Q Exp
typeScriptJSXFileReload :: String -> Q Exp
typeScriptJSXFileReload String
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
ShakespeareSettings -> String -> Q Exp
shakespeareFileReload ShakespeareSettings
rs String
fp