-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve CLI * update progDesc * nicer doc * update bower * purescript-optparse#v0.1.0
- Loading branch information
Showing
8 changed files
with
228 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
/deploy.js | ||
/compile.js | ||
/docs/_build/ | ||
chanterelle.js | ||
/chanterelle.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,116 @@ | ||
module Chanterelle | ||
( compileMain | ||
, deployMain | ||
) where | ||
module Chanterelle where | ||
|
||
import Prelude | ||
|
||
import Chanterelle.Compile (compileProject) | ||
import Chanterelle.Deploy (deploy) | ||
import Chanterelle.Internal.Logging (setLogLevel, readLogLevel) | ||
import Chanterelle.Internal.Types.Deploy (DeployM) | ||
import Effect (Effect) | ||
import Chanterelle.Internal.Codegen (generatePS) as Chanterelle | ||
import Chanterelle.Internal.Compile (compile) as Chanterelle | ||
import Chanterelle.Internal.Genesis (generateGenesis) | ||
import Chanterelle.Internal.Logging (LogLevel(..), log, logCompileError, logGenesisGenerationError, readLogLevel, setLogLevel) | ||
import Chanterelle.Internal.Types (DeployM, runCompileM) | ||
import Chanterelle.Internal.Types.Project (ChanterelleProject) | ||
import Chanterelle.Internal.Utils (jsonStringifyWithSpaces) | ||
import Chanterelle.Project (loadProject) | ||
import Control.Monad.Error.Class (try) | ||
import Data.Argonaut as A | ||
import Data.Either (Either(..)) | ||
import Data.Maybe (Maybe(..)) | ||
import Node.Yargs.Applicative (yarg, runY) | ||
import Node.Yargs.Setup (usage, defaultVersion, defaultHelp, example) | ||
|
||
compileMain | ||
:: Effect Unit | ||
compileMain = | ||
let setup = usage "$0 --log-level <level>" | ||
<> example "$0 --log-level debug" "Run the compile phase with the given log level." | ||
<> defaultVersion | ||
<> defaultHelp | ||
in runY setup $ go <$> yarg "log-level" [] Nothing (Left "info") false | ||
where | ||
go level = do | ||
setLogLevel $ readLogLevel level | ||
compileProject | ||
|
||
deployMain | ||
:: forall a. | ||
DeployM a | ||
-> Effect Unit | ||
deployMain deployScript = | ||
let setup = usage "$0 --log-level <level> --node-url <url> --timeout <seconds>" | ||
<> example "$0 --log-level debug" "Run the deployment script with the given log level, node url, and timeout" | ||
<> defaultVersion | ||
<> defaultHelp | ||
in runY setup $ go <$> yarg "log-level" [] Nothing (Left "info") false | ||
<*> yarg "node-url" [] Nothing (Left "http://localhost:8545") false | ||
<*> yarg "timeout" [] Nothing (Left 60) false | ||
import Data.Generic.Rep (class Generic) | ||
import Data.Generic.Rep.Show (genericShow) | ||
import Effect.Aff (Aff) | ||
import Effect.Class (liftEffect) | ||
import Node.Encoding (Encoding(..)) | ||
import Node.FS.Aff (writeTextFile) | ||
import Node.Path (resolve) | ||
import Node.Process (cwd) | ||
|
||
|
||
data SelectCLI a b = SelectCLI a | ||
data SelectPS a b = SelectPS b | ||
instance showSelectDeployM :: Show (SelectPS a (DeployM Unit)) where show (SelectPS _ ) = "<DeployM Unit>" | ||
instance showSelectDeployPath :: Show a => Show (SelectCLI a b) where show (SelectCLI a ) = show a | ||
|
||
type ArgsCLI = Args' SelectCLI | ||
type Args = Args' SelectPS | ||
data Args' s = Args' CommonOpts (Command s) | ||
derive instance genericArgs :: Generic (Args' s) _ | ||
instance showArgs :: Show (DeployOptions s) => Show (Args' s) where show = genericShow | ||
|
||
type DirPath = String | ||
data CommonOpts = CommonOpts | ||
{ optVerbosity :: String | ||
, rootPath :: DirPath | ||
} | ||
derive instance genericCommonOpts :: Generic CommonOpts _ | ||
instance showCommonOpts :: Show CommonOpts where show = genericShow | ||
|
||
|
||
data Command s | ||
= Build | ||
| Compile | ||
| Codegen | ||
| Genesis GenesisOptions | ||
| Deploy (DeployOptions s) | ||
derive instance genericCommand :: Generic (Command s) _ | ||
instance showCommand :: Show (DeployOptions s) => Show (Command s) where show = genericShow | ||
|
||
traverseArgs :: forall a b f. Applicative f => (DeployOptions a -> f (DeployOptions b)) -> Args' a -> f (Args' b) | ||
traverseArgs f (Args' o cmd) = Args' o <$> case cmd of | ||
Build -> pure Build | ||
Compile -> pure Compile | ||
Codegen -> pure Codegen | ||
Genesis opts -> pure $ Genesis opts | ||
Deploy dopts -> Deploy <$> f dopts | ||
|
||
data GenesisOptions = GenesisOptions | ||
{ input :: String | ||
, output :: String | ||
} | ||
derive instance genericGenesisOptions :: Generic GenesisOptions _ | ||
instance showGenesisOptions :: Show GenesisOptions where show = genericShow | ||
|
||
type DeployOptionsCLI = DeployOptions SelectCLI | ||
|
||
data DeployOptions s = DeployOptions | ||
{ nodeURL :: String | ||
, timeout :: Int | ||
, script :: s String (DeployM Unit) | ||
} | ||
derive instance genericDeployOptions :: Generic (DeployOptions s) _ | ||
instance showDeployOptions :: Show (DeployOptions SelectPS) where show = genericShow | ||
|
||
chanterelle :: Args -> Aff Unit | ||
chanterelle (Args' (CommonOpts{ optVerbosity, rootPath }) cmd) = do | ||
ourCwd <- liftEffect cwd | ||
liftEffect $ setLogLevel (readLogLevel optVerbosity) | ||
resolvedRoot <- liftEffect $ resolve [ourCwd] rootPath | ||
projE <- try $ loadProject resolvedRoot | ||
case projE of | ||
Left err -> log Error ("Couldn't parse chanterelle.json: " <> show err) | ||
Right project -> do | ||
log Info "Loaded chanterelle.json successfully!" | ||
runCommand project cmd | ||
|
||
runCommand :: ChanterelleProject -> Command SelectPS -> Aff Unit | ||
runCommand project = case _ of | ||
Build -> doCompile *> doCodegen | ||
Compile -> doCompile | ||
Codegen -> doCodegen | ||
Genesis opts -> doGenesis opts | ||
Deploy opts -> doDeploy opts | ||
where | ||
go level nodeUrl timeout = do | ||
setLogLevel $ readLogLevel level | ||
deploy nodeUrl timeout deployScript | ||
doDeploy (DeployOptions {nodeURL, timeout, script: SelectPS s}) = do | ||
deploy nodeURL timeout s | ||
doClassicBuild = doCompile *> doCodegen | ||
doCompile = runCompileM Chanterelle.compile project >>= case _ of | ||
Left err -> logCompileError err | ||
Right _ -> pure unit | ||
doCodegen = runCompileM Chanterelle.generatePS project >>= case _ of | ||
Left err -> logCompileError err | ||
Right _ -> pure unit | ||
doGenesis (GenesisOptions {input,output}) = generateGenesis project input >>= case _ of | ||
Left err -> logGenesisGenerationError err | ||
Right gb -> do | ||
let strungGb = jsonStringifyWithSpaces 4 (A.encodeJson gb) | ||
try (writeTextFile UTF8 output strungGb) >>= case _ of | ||
Left err -> log Error $ "Couldn't write genesis block to " <> show output <> ": " <> show err | ||
Right _ -> log Info $ "Successfully wrote generated genesis block to " <> show output |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.loadDeployMFromScriptPath = function (filePath) { | ||
return function () { | ||
return require(filePath).deploy; | ||
}; | ||
}; |
Oops, something went wrong.