11import commander from "commander" ;
2- import { SourcePathInvalidError } from "../exceptions" ;
2+ import { SourcePathInvalidError , CliArgumentError } from "../exceptions" ;
33import * as PathFactory from "./PathFactory" ;
44
55const isInvalidPath = require ( "is-invalid-path" ) ;
@@ -13,6 +13,7 @@ interface CLIArguments {
1313 exportStatic ?: PathFactory . Type ;
1414 publicPath ?: string ;
1515 dryRun : boolean ;
16+ engine ?: "dot" ;
1617}
1718
1819export const validateCliArguments = ( args : commander . Command ) : CLIArguments => {
@@ -22,6 +23,12 @@ export const validateCliArguments = (args: commander.Command): CLIArguments => {
2223 if ( args [ "tsConfig" ] && isInvalidPath ( args [ "source" ] ) ) {
2324 throw new SourcePathInvalidError ( "`--source` arguments does not selected." ) ;
2425 }
26+ if ( "exportStatic" in args && typeof args [ "exportStatic" ] !== "string" ) {
27+ throw new CliArgumentError ( "`--export-static` require 1 string argument." ) ;
28+ }
29+ if ( "publicPath" in args && typeof args [ "publicPath" ] !== "string" ) {
30+ throw new CliArgumentError ( "`--public-path` require 1 string argument." ) ;
31+ }
2532 return {
2633 source : PathFactory . create ( { source : args [ "source" ] } ) ,
2734 port : args [ "port" ] ,
@@ -31,6 +38,7 @@ export const validateCliArguments = (args: commander.Command): CLIArguments => {
3138 exportStatic : args [ "exportStatic" ] && PathFactory . create ( { source : args [ "exportStatic" ] } ) ,
3239 publicPath : args [ "publicPath" ] ,
3340 dryRun : ! ! args [ "dryRun" ] ,
41+ engine : args [ "engine" ] === "dot" ? "dot" : undefined ,
3442 } ;
3543} ;
3644
@@ -45,6 +53,7 @@ export const executeCommandLine = (): CLIArguments => {
4553 . option ( "--export-static [static directory]" , "static file hosting directory" )
4654 . option ( "--public-path [host public path]" , "the base path for all the assets" )
4755 . option ( "--dry-run" , "only use --export-static option" )
56+ . option ( "--engine <dot>" , "already local installed graphviz. <https://www.graphviz.org/>" )
4857 . parse ( process . argv ) ;
4958 return validateCliArguments ( commander ) ;
5059} ;
0 commit comments