aeson-typescript 0.1.0.2 → 0.1.0.3
raw patch · 5 files changed
+52/−3 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- aeson-typescript.cabal +3/−2
- src/Data/Aeson/TypeScript/Instances.hs +6/−0
- src/Data/Aeson/TypeScript/TH.hs +16/−0
- test/Util.hs +16/−1
- test/assets/npm_install.sh +11/−0
aeson-typescript.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: b86c36fc20ac6e32d044e63a6caa18dddf3941b36e79c3028a3a7f6ba2013073+-- hash: 642ba0d728cb3be28a4296b85b360f01995570c1a66ec3a36bfb1432d2095f58 name: aeson-typescript-version: 0.1.0.2+version: 0.1.0.3 synopsis: Generate TypeScript definition files from your ADTs description: Please see the README on Github at <https://github.com/codedownio/aeson-typescript#readme> category: Text, Web, JSON@@ -23,6 +23,7 @@ extra-source-files: ChangeLog.md README.md+ test/assets/npm_install.sh test/assets/package.json test/assets/yarn.lock test/assets/yarn_install.sh
src/Data/Aeson/TypeScript/Instances.hs view
@@ -38,6 +38,12 @@ instance TypeScript Integer where getTypeScriptType _ = "number" +instance TypeScript Float where+ getTypeScriptType _ = "number"++instance TypeScript Double where+ getTypeScriptType _ = "number"+ instance TypeScript Bool where getTypeScriptType _ = "boolean"
src/Data/Aeson/TypeScript/TH.hs view
@@ -80,6 +80,7 @@ module Data.Aeson.TypeScript.Instances ) where +import Control.Monad import Data.Aeson as A import Data.Aeson.TypeScript.Formatting import Data.Aeson.TypeScript.Instances ()@@ -150,6 +151,8 @@ deriveTypeScript options name = do datatypeInfo@(DatatypeInfo {..}) <- reifyDatatype name + assertExtensionsTurnedOn datatypeInfo+ let getFreeVariableName (SigT (VarT name) kind) = Just name getFreeVariableName typ = Nothing @@ -332,6 +335,19 @@ getTagSingleConstructors options = tagSingleConstructors options #else getTagSingleConstructors options = False+#endif++-- Between Template Haskell 2.10 and 2.11, the ability to look up which extensions are turned on was added+assertExtensionsTurnedOn :: DatatypeInfo -> Q ()+#if MIN_VERSION_template_haskell(2,11,0)+assertExtensionsTurnedOn (DatatypeInfo {..}) = do+ -- Check that necessary language extensions are turned on+ scopedTypeVariablesEnabled <- isExtEnabled ScopedTypeVariables+ kindSignaturesEnabled <- isExtEnabled KindSignatures+ when (not scopedTypeVariablesEnabled) $ error [i|The ScopedTypeVariables extension is required; please enable it before calling deriveTypeScript. (For example: put {-# LANGUAGE ScopedTypeVariables #-} at the top of the file.)|]+ when ((not kindSignaturesEnabled) && (length datatypeVars > 0)) $ error [i|The KindSignatures extension is required since type #{datatypeName} is a higher order type; please enable it before calling deriveTypeScript. (For example: put {-# LANGUAGE KindSignatures #-} at the top of the file.)|]+#else+assertExtensionsTurnedOn _ = return () #endif -- Older versions of Aeson don't have an Eq instance for SumEncoding so we do this
test/Util.hs view
@@ -19,6 +19,7 @@ import System.IO.Temp import System.Process +npmInstallScript = "test/assets/npm_install.sh" yarnInstallScript = "test/assets/yarn_install.sh" localTSC = "test/assets/node_modules/.bin/tsc" @@ -83,8 +84,11 @@ ensureTSCExists :: IO () ensureTSCExists = doesFileExist localTSC >>= \exists -> when (not exists) $ void $ do cwd <- getCurrentDirectory++ installScript <- chooseInstallScript+ putStrLn [i|Invoking yarn to install tsc compiler (make sure yarn is installed). CWD is #{cwd}|]- (exitCode, stdout, stderr) <- readProcessWithExitCode yarnInstallScript [] ""+ (exitCode, stdout, stderr) <- readProcessWithExitCode installScript [] "" when (exitCode /= ExitSuccess) $ putStrLn [i|Error installing yarn: '#{stderr}', '#{stdout}'|] @@ -95,3 +99,14 @@ #else setTagSingleConstructors = id #endif++chooseInstallScript :: IO String+chooseInstallScript = do+ yarn <- findExecutable "yarn"+ case yarn of+ Just _ -> return yarnInstallScript+ Nothing -> do+ npm <- findExecutable "npm"+ case npm of+ Just _ -> return npmInstallScript+ Nothing -> error [i|Couldn't find either yarn or npm; one of them is needed to install a TypeScript compiler.|]
+ test/assets/npm_install.sh view
@@ -0,0 +1,11 @@+#!/bin/bash++# This helper script will run "npm install" in the directory it's in+# Useful because older versions of System.Process don't have nice things like readCreateProcess++SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"++set -e++cd $SCRIPTDIR+npm install