2017-10-14 06:06:09 -04:00
const program = require ( 'commander' ) ;
2018-08-08 18:07:10 -04:00
const EmbarkController = require ( './cmd_controller.js' ) ;
2018-08-08 15:05:22 -04:00
const i18n = require ( '../lib/core/i18n/i18n.js' ) ;
2018-08-17 12:37:15 -05:00
const utils = require ( '../lib/utils/utils.js' ) ;
2018-10-06 18:05:37 +02:00
let embark = new EmbarkController ( ) ;
2016-08-17 20:29:41 -04:00
2018-08-17 12:37:15 -05:00
// set PWD to process.cwd() since Windows doesn't have a value for PWD
if ( ! process . env . PWD ) {
process . env . PWD = process . cwd ( ) ;
}
// set the anchor for embark's fs.dappPath()
if ( ! process . env . DAPP _PATH ) {
process . env . DAPP _PATH = process . env . PWD ;
}
// set the anchor for embark's fs.embarkPath()
if ( ! process . env . EMBARK _PATH ) {
process . env . EMBARK _PATH = utils . joinPath ( _ _dirname , '..' ) ;
}
2018-09-10 01:53:12 -05:00
// set the anchor for embark's fs.pkgPath()
if ( ! process . env . PKG _PATH ) {
process . env . PKG _PATH = process . env . PWD ;
}
2018-10-01 20:39:45 +02:00
process . env . DEFAULT _DIAGRAM _PATH = utils . joinPath ( process . env . DAPP _PATH , 'diagram.svg' ) ;
2018-10-08 11:04:34 +02:00
process . env . DEFAULT _CMD _HISTORY _SIZE = 20 ;
2018-10-01 20:39:45 +02:00
2017-03-30 20:12:39 +09:00
class Cmd {
constructor ( ) {
2017-03-30 22:16:46 +09:00
program . version ( embark . version ) ;
2017-02-17 14:34:07 -05:00
}
2016-08-17 20:29:41 -04:00
2017-03-30 20:12:39 +09:00
process ( args ) {
this . newApp ( ) ;
this . demo ( ) ;
this . build ( ) ;
this . run ( ) ;
2018-07-23 09:34:21 +01:00
this . console ( ) ;
2017-03-30 20:12:39 +09:00
this . blockchain ( ) ;
this . simulator ( ) ;
this . test ( ) ;
2018-01-11 09:22:58 -05:00
this . reset ( ) ;
2018-08-16 18:02:54 -05:00
this . ejectWebpack ( ) ;
2018-03-22 10:43:29 -04:00
this . graph ( ) ;
2018-05-09 17:02:17 -04:00
this . scaffold ( ) ;
2017-03-30 20:12:39 +09:00
this . upload ( ) ;
2017-12-19 10:20:05 -05:00
this . versionCmd ( ) ;
2018-08-14 16:48:40 -04:00
this . helpCmd ( ) ;
2017-03-30 20:12:39 +09:00
this . otherCommands ( ) ;
//If no arguments are passed display help by default
if ( ! process . argv . slice ( 2 ) . length ) {
program . help ( ) ;
2016-08-21 10:42:42 -04:00
}
2017-03-30 20:12:39 +09:00
program . parse ( args ) ;
}
2017-10-14 06:06:09 -04:00
newApp ( ) {
2017-03-30 20:12:39 +09:00
2018-09-07 12:37:18 -04:00
let validateName = function ( value ) {
2017-03-30 20:12:39 +09:00
try {
2017-10-14 06:06:09 -04:00
if ( value . match ( /^[a-zA-Z\s-]+$/ ) ) return value ;
2017-03-30 20:12:39 +09:00
} catch ( e ) {
2018-05-08 17:49:46 -04:00
throw new Error ( _ _ ( 'Name must be only letters, spaces, or dashes' ) ) ;
2017-03-22 14:13:58 +09:00
}
2017-03-30 20:12:39 +09:00
} ;
program
. command ( 'new [name]' )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'New Application' ) )
. option ( '--simple' , _ _ ( 'create a barebones project meant only for contract development' ) )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-09-24 17:40:50 -05:00
. option ( '--template <name/url>' , _ _ ( 'download a template using a known name or a git host URL' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( name , options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2017-03-30 20:12:39 +09:00
if ( name === undefined ) {
2018-06-01 11:57:01 -04:00
const promptly = require ( 'promptly' ) ;
2018-05-08 17:49:46 -04:00
return promptly . prompt ( _ _ ( "Name your app (default is %s):" , 'embarkDapp' ) , {
2017-06-27 15:45:30 -04:00
default : "embarkDApp" ,
2017-03-30 20:12:39 +09:00
validator : validateName
2018-09-07 12:37:18 -04:00
} , function ( err , inputvalue ) {
2017-03-30 20:12:39 +09:00
if ( err ) {
2018-05-08 17:49:46 -04:00
console . error ( _ _ ( 'Invalid name' ) + ':' , err . message ) ;
2017-03-30 20:12:39 +09:00
// Manually call retry
// The passed error has a retry method to easily prompt again.
err . retry ( ) ;
} else {
//slightly different assignment of name since it comes from child prompt
2018-03-29 19:42:47 -04:00
if ( options . simple ) {
embark . generateTemplate ( 'simple' , './' , inputvalue ) ;
} else {
2018-07-06 11:38:09 +03:00
embark . generateTemplate ( 'boilerplate' , './' , inputvalue , options . template ) ;
2018-03-29 19:42:47 -04:00
}
2017-03-30 20:12:39 +09:00
}
} ) ;
2018-09-07 12:37:18 -04:00
}
if ( options . simple ) {
embark . generateTemplate ( 'simple' , './' , name ) ;
2017-03-30 20:12:39 +09:00
} else {
2018-09-07 12:37:18 -04:00
embark . generateTemplate ( 'boilerplate' , './' , name , options . template ) ;
2017-03-30 20:12:39 +09:00
}
} ) ;
}
demo ( ) {
program
. command ( 'demo' )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'create a working dapp with a SimpleStorage contract' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2017-03-30 22:16:46 +09:00
embark . generateTemplate ( 'demo' , './' , 'embark_demo' ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
build ( ) {
program
. command ( 'build [environment]' )
2018-05-17 15:37:57 -05:00
. option ( '--contracts' , 'only compile contracts into Embark wrappers' )
2018-05-08 17:49:46 -04:00
. option ( '--logfile [logfile]' , _ _ ( 'filename to output logs (default: none)' ) )
2018-10-06 18:05:37 +02:00
. option ( '-c, --client [client]' , _ _ ( 'Use a specific ethereum client [%s] (default: %s)' , 'geth, parity' , 'geth' ) )
2018-05-08 17:49:46 -04:00
. option ( '--loglevel [loglevel]' , _ _ ( 'level of logging to display' ) + ' ["error", "warn", "info", "debug", "trace"]' , /^(error|warn|info|debug|trace)$/i , 'debug' )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-08-16 15:51:34 -05:00
. option ( '--pipeline [pipeline]' , _ _ ( 'webpack config to use (default: production)' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'deploy and build dapp at ' ) + 'dist/ (default: development)' )
2018-09-07 12:37:18 -04:00
. action ( function ( env , _options ) {
2018-05-10 15:36:24 -04:00
i18n . setOrDetectLocale ( _options . locale ) ;
2018-04-19 14:25:43 +10:00
_options . env = env || 'development' ;
_options . logFile = _options . logfile ; // fix casing
_options . logLevel = _options . loglevel ; // fix casing
2018-05-17 15:37:57 -05:00
_options . onlyCompile = _options . contracts ;
2018-10-06 18:05:37 +02:00
_options . client = _options . client ;
2018-08-16 15:51:34 -05:00
_options . webpackConfigName = _options . pipeline || 'production' ;
2018-04-19 14:25:43 +10:00
embark . build ( _options ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
run ( ) {
program
. command ( 'run [environment]' )
2018-05-08 17:49:46 -04:00
. option ( '-p, --port [port]' , _ _ ( 'port to run the dev webserver (default: %s)' , '8000' ) )
2018-10-06 18:05:37 +02:00
. option ( '-c, --client [client]' , _ _ ( 'Use a specific ethereum client [%s] (default: %s)' , 'geth, parity' , 'geth' ) )
2018-05-08 17:49:46 -04:00
. option ( '-b, --host [host]' , _ _ ( 'host to run the dev webserver (default: %s)' , 'localhost' ) )
. option ( '--noserver' , _ _ ( 'disable the development webserver' ) )
. option ( '--nodashboard' , _ _ ( 'simple mode, disables the dashboard' ) )
2018-09-17 18:50:47 -05:00
. option ( '--nobrowser' , _ _ ( 'prevent the development webserver from automatically opening a web browser' ) )
2018-05-08 17:49:46 -04:00
. option ( '--no-color' , _ _ ( 'no colors in case it\'s needed for compatbility purposes' ) )
. option ( '--logfile [logfile]' , _ _ ( 'filename to output logs (default: %s)' , 'none' ) )
. option ( '--loglevel [loglevel]' , _ _ ( 'level of logging to display' ) + ' ["error", "warn", "info", "debug", "trace"]' , /^(error|warn|info|debug|trace)$/i , 'debug' )
2018-05-09 18:43:09 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-08-16 15:51:34 -05:00
. option ( '--pipeline [pipeline]' , _ _ ( 'webpack config to use (default: development)' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'run dapp (default: %s)' , 'development' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( env , options ) {
2018-05-09 18:43:09 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2018-10-11 16:14:58 -04:00
const nullify = ( v ) => {
return ( ! v || typeof v !== 'string' ) ? null : v ;
} ;
2017-03-30 22:16:46 +09:00
embark . run ( {
2017-03-30 20:12:39 +09:00
env : env || 'development' ,
2018-10-06 18:05:37 +02:00
serverPort : options . port ,
serverHost : options . host ,
client : options . client ,
2018-07-23 09:34:21 +01:00
locale : options . locale ,
2018-10-12 13:46:25 -04:00
runWebserver : ! options . noserver ? null : false ,
2018-07-23 09:34:21 +01:00
useDashboard : ! options . nodashboard ,
logFile : options . logfile ,
2018-08-16 15:51:34 -05:00
logLevel : options . loglevel ,
2018-09-17 17:46:48 -05:00
webpackConfigName : options . pipeline || 'development' ,
2018-10-12 13:46:25 -04:00
openBrowser : ! options . nobrowser ? null : false
2018-07-23 09:34:21 +01:00
} ) ;
} ) ;
}
console ( ) {
program
. command ( 'console [environment]' )
2018-10-06 18:05:37 +02:00
. option ( '-c, --client [client]' , _ _ ( 'Use a specific ethereum client [%s] (default: %s)' , 'geth, parity' , 'geth' ) )
2018-07-23 09:34:21 +01:00
. option ( '--logfile [logfile]' , _ _ ( 'filename to output logs (default: %s)' , 'none' ) )
. option ( '--loglevel [loglevel]' , _ _ ( 'level of logging to display' ) + ' ["error", "warn", "info", "debug", "trace"]' , /^(error|warn|info|debug|trace)$/i , 'debug' )
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-08-18 20:04:16 -05:00
. option ( '--pipeline [pipeline]' , _ _ ( 'webpack config to use (default: development)' ) )
2018-07-23 13:36:15 +01:00
. description ( _ _ ( 'Start the Embark console' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( env , options ) {
2018-07-23 09:34:21 +01:00
i18n . setOrDetectLocale ( options . locale ) ;
embark . console ( {
env : env || 'development' ,
2018-10-06 18:05:37 +02:00
client : options . client ,
2018-05-18 15:48:28 -04:00
locale : options . locale ,
2018-04-19 14:25:43 +10:00
logFile : options . logfile ,
2018-08-18 20:04:16 -05:00
logLevel : options . loglevel ,
webpackConfigName : options . pipeline || 'development'
2017-03-30 20:12:39 +09:00
} ) ;
} ) ;
}
blockchain ( ) {
program
. command ( 'blockchain [environment]' )
2018-10-06 18:05:37 +02:00
. option ( '-c, --client [client]' , _ _ ( 'Use a specific ethereum client [%s] (default: %s)' , 'geth, parity' , 'geth' ) )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'run blockchain server (default: %s)' , 'development' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( env , options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2017-03-30 22:16:46 +09:00
embark . initConfig ( env || 'development' , {
2017-03-30 20:12:39 +09:00
embarkConfig : 'embark.json' ,
interceptLogs : false
} ) ;
2018-10-06 18:05:37 +02:00
embark . blockchain ( env || 'development' , options . client ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
simulator ( ) {
program
. command ( 'simulator [environment]' )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'run a fast ethereum rpc simulator' ) )
2018-10-06 18:05:37 +02:00
. option ( '--testrpc' , _ _ ( 'use ganache-cli (former "testrpc") as the rpc simulator [%s]' , 'default' ) )
2018-05-08 17:49:46 -04:00
. option ( '-p, --port [port]' , _ _ ( 'port to run the rpc simulator (default: %s)' , '8545' ) )
. option ( '-h, --host [host]' , _ _ ( 'host to run the rpc simulator (default: %s)' , 'localhost' ) )
. option ( '-a, --accounts [numAccounts]' , _ _ ( 'number of accounts (default: %s)' , '10' ) )
. option ( '-e, --defaultBalanceEther [balance]' , _ _ ( 'Amount of ether to assign each test account (default: %s)' , '100' ) )
. option ( '-l, --gasLimit [gasLimit]' , _ _ ( 'custom gas limit (default: %s)' , '8000000' ) )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2017-12-27 17:48:33 -05:00
2018-09-07 12:37:18 -04:00
. action ( function ( env , options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2017-03-30 22:16:46 +09:00
embark . initConfig ( env || 'development' , {
2017-03-30 20:12:39 +09:00
embarkConfig : 'embark.json' ,
interceptLogs : false
} ) ;
2017-12-27 17:48:33 -05:00
embark . simulator ( {
port : options . port ,
host : options . host ,
numAccounts : options . numAccounts ,
defaultBalance : options . balance ,
gasLimit : options . gasLimit
} ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
test ( ) {
program
2017-07-02 11:32:16 -04:00
. command ( 'test [file]' )
2018-09-18 15:01:32 -05:00
. option ( '-n , --node <node>' , _ _ ( 'node for running the tests ["vm", "embark", <endpoint>] (default: vm)\n' ) +
' vm - ' + _ _ ( 'start and use an Ethereum simulator (ganache)' ) + '\n' +
' embark - ' + _ _ ( 'use the node of a running embark process' ) + '\n' +
' <endpoint> - ' + _ _ ( 'connect to and use the specified node' ) )
2018-09-18 15:01:48 -05:00
. option ( '-d , --gasDetails' , _ _ ( 'print the gas cost for each contract deployment when running the tests' ) )
2018-09-18 15:05:52 -05:00
. option ( '-c , --coverage' , _ _ ( 'generate a coverage report after running the tests (vm only)' ) )
2018-10-01 20:04:29 +02:00
. option ( '--nobrowser' , _ _ ( 'do not start browser after coverage report is generated' ) )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-10-16 10:53:07 -04:00
. option ( '--loglevel [loglevel]' , _ _ ( 'level of logging to display' ) + ' ["error", "warn", "info", "debug", "trace"]' , /^(error|warn|info|debug|trace)$/i , 'warn' )
2018-10-04 17:10:41 +05:30
. option ( '--solc' , _ _ ( 'run only solidity tests' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'run tests' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( file , options ) {
2018-09-14 20:15:48 -05:00
const node = options . node || 'vm' ;
2018-09-14 19:58:23 -05:00
const urlRegexExp = /^(vm|embark|((ws|https?):\/\/([a-zA-Z0-9_.-]*):?([0-9]*)?))$/i ;
2018-09-15 11:38:48 +10:00
if ( ! urlRegexExp . test ( node ) ) {
2018-09-18 15:06:27 -05:00
console . error ( ` invalid --node option: must be "vm", "embark" or a valid URL \n ` . red ) ;
2018-09-15 11:32:16 +10:00
options . outputHelp ( ) ;
2018-09-14 19:58:23 -05:00
process . exit ( 1 ) ;
}
2018-09-14 20:15:48 -05:00
options . node = node ;
2018-09-18 15:05:52 -05:00
if ( options . coverage && options . node !== 'vm' ) {
console . error ( ` invalid --node option: coverage supports "vm" only \n ` . red ) ;
options . outputHelp ( ) ;
process . exit ( 1 ) ;
}
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2018-10-16 10:53:07 -04:00
embark . runTests ( { file , solc : options . solc , logLevel : options . loglevel , gasDetails : options . gasDetails ,
2018-10-01 20:04:29 +02:00
node : options . node , coverage : options . coverage , noBrowser : options . nobrowser } ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
upload ( ) {
program
2018-05-17 17:38:17 +10:00
. command ( 'upload [environment]' )
2018-09-21 17:51:33 -04:00
//.option('--ens [ensDomain]', __('ENS domain to associate to'))
2018-05-08 17:49:46 -04:00
. option ( '--logfile [logfile]' , _ _ ( 'filename to output logs (default: %s)' , 'none' ) )
. option ( '--loglevel [loglevel]' , _ _ ( 'level of logging to display' ) + ' ["error", "warn", "info", "debug", "trace"]' , /^(error|warn|info|debug|trace)$/i , 'debug' )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-10-06 18:05:37 +02:00
. option ( '-c, --client [client]' , _ _ ( 'Use a specific ethereum client [%s] (default: %s)' , 'geth, parity' , 'geth' ) )
2018-08-28 15:44:13 -05:00
. option ( '--pipeline [pipeline]' , _ _ ( 'webpack config to use (default: production)' ) )
2018-05-30 16:34:36 +10:00
. description ( _ _ ( 'Upload your dapp to a decentralized storage' ) + '.' )
2018-09-07 12:37:18 -04:00
. action ( function ( env , _options ) {
2018-05-10 15:36:24 -04:00
i18n . setOrDetectLocale ( _options . locale ) ;
2018-06-19 14:07:14 -04:00
if ( env === "ipfs" || env === "swarm" ) {
console . warn ( ( "did you mean " + "embark upload" . bold + " ?" ) . underline ) ;
console . warn ( "In embark 3.1 forwards, the correct command is embark upload <environment> and the provider is configured in config/storage.js" ) ;
}
2018-04-24 10:27:11 +10:00
_options . env = env || 'development' ;
2018-07-26 13:52:22 -04:00
_options . ensDomain = _options . ens ;
2018-04-19 14:25:43 +10:00
_options . logFile = _options . logfile ; // fix casing
_options . logLevel = _options . loglevel ; // fix casing
2018-10-06 18:05:37 +02:00
_options . client = _options . client ;
2018-08-28 15:44:13 -05:00
_options . webpackConfigName = _options . pipeline || 'production' ;
2018-05-17 17:38:17 +10:00
embark . upload ( _options ) ;
2017-03-30 20:12:39 +09:00
} ) ;
}
2018-03-22 10:43:29 -04:00
graph ( ) {
program
. command ( 'graph [environment]' )
2018-05-08 17:49:46 -04:00
. option ( '--skip-undeployed' , _ _ ( 'Graph will not include undeployed contracts' ) )
. option ( '--skip-functions' , _ _ ( 'Graph will not include functions' ) )
. option ( '--skip-events' , _ _ ( 'Graph will not include events' ) )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-10-01 20:39:45 +02:00
. option ( '--output [svgfile]' , _ _ ( 'filepath to output SVG graph to (default: %s)' , process . env [ 'DEFAULT_DIAGRAM_PATH' ] ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'generates documentation based on the smart contracts configured' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( env , options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2018-03-22 15:09:01 -04:00
embark . graph ( {
env : env || 'development' ,
2018-05-04 16:17:12 -04:00
logFile : options . logfile ,
skipUndeployed : options . skipUndeployed ,
skipFunctions : options . skipFunctions ,
2018-10-01 20:39:45 +02:00
skipEvents : options . skipEvents ,
output : options . output || process . env [ 'DEFAULT_DIAGRAM_PATH' ]
2018-03-22 10:43:29 -04:00
} ) ;
} ) ;
}
2018-05-09 17:02:17 -04:00
scaffold ( ) {
program
2018-10-12 13:50:35 -04:00
. command ( 'scaffold [contract] [fields...]' )
2018-05-11 16:07:28 -04:00
. option ( '--framework <framework>' , 'UI framework to use. (default: react)' )
2018-10-12 13:50:35 -04:00
. option ( '--contract-language <language>' , 'Language used for the smart contract generation (default: solidity)' )
2018-10-05 11:45:03 -04:00
. option ( '--overwrite' , 'Overwrite existing files. (default: false)' )
2018-10-17 13:18:33 -04:00
. description ( _ _ ( 'Generates a contract and a function tester for you\nExample: ContractName field1:uint field2:address --contract-language solidity --framework react' ) )
. action ( function ( contract , fields , options ) {
if ( contract === undefined ) {
2018-05-09 17:02:17 -04:00
console . log ( "contract name is required" ) ;
process . exit ( 0 ) ;
}
2018-10-17 13:18:33 -04:00
let fieldMapping = { } ;
if ( fields . length > 0 ) {
2018-10-12 14:23:31 -04:00
const typeRegex = /^(u?int[0-9]{0,3}(\[\])?|string|bool|address|bytes[0-9]{0,3})(\[\])?$/ ;
const varRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/ ;
2018-10-17 13:18:33 -04:00
fieldMapping = fields . reduce ( ( acc , curr ) => {
2018-10-12 13:50:35 -04:00
const c = curr . split ( ':' ) ;
2018-10-12 14:23:31 -04:00
2018-10-17 13:18:33 -04:00
if ( ! varRegex . test ( c [ 0 ] ) ) {
2018-10-12 14:23:31 -04:00
console . log ( "Invalid variable name: " + c [ 0 ] ) ;
2018-10-17 13:18:33 -04:00
process . exit ( 1 ) ;
2018-10-12 14:23:31 -04:00
}
2018-10-17 13:18:33 -04:00
if ( ! typeRegex . test ( c [ 1 ] ) ) {
2018-10-12 14:23:31 -04:00
console . log ( "Invalid datatype: " + c [ 1 ] + " - The dApp generator might not support this type at the moment" ) ;
2018-10-17 13:18:33 -04:00
process . exit ( 1 ) ;
2018-10-12 14:23:31 -04:00
}
2018-10-17 13:18:33 -04:00
acc [ c [ 0 ] ] = c [ 1 ] ;
return acc ;
} , { } ) ;
2018-10-12 13:50:35 -04:00
}
2018-10-03 16:34:36 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2018-10-12 13:50:35 -04:00
options . env = 'development' ;
2018-10-03 16:34:36 -04:00
options . logFile = options . logfile ; // fix casing
options . logLevel = options . loglevel ; // fix casing
options . onlyCompile = options . contracts ;
options . client = options . client || 'geth' ;
options . webpackConfigName = options . pipeline || 'development' ;
2018-05-09 17:02:17 -04:00
options . contract = contract ;
2018-05-09 17:02:17 -04:00
options . framework = options . framework || 'react' ;
2018-10-12 13:50:35 -04:00
options . contractLanguage = options . contractLanguage || 'solidity' ;
2018-10-05 11:45:03 -04:00
options . overwrite = options . overwrite || false ;
2018-10-12 13:50:35 -04:00
options . fields = fieldMapping ;
2018-10-05 11:45:03 -04:00
2018-05-09 17:02:17 -04:00
embark . scaffold ( options ) ;
} ) ;
}
2018-01-11 09:22:58 -05:00
reset ( ) {
program
. command ( 'reset' )
2018-05-09 18:46:38 -04:00
. option ( '--locale [locale]' , _ _ ( 'language to use (default: en)' ) )
2018-05-08 17:49:46 -04:00
. description ( _ _ ( 'resets embarks state on this dapp including clearing cache' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( options ) {
2018-05-09 18:46:38 -04:00
i18n . setOrDetectLocale ( options . locale ) ;
2018-01-11 09:22:58 -05:00
embark . initConfig ( 'development' , {
embarkConfig : 'embark.json' , interceptLogs : false
} ) ;
embark . reset ( ) ;
} ) ;
}
2018-08-16 18:02:54 -05:00
ejectWebpack ( ) {
program
. command ( 'eject-webpack' )
. description ( _ _ ( 'copy the default webpack config into your dapp for customization' ) )
2018-09-07 12:37:18 -04:00
. action ( function ( ) {
2018-09-11 19:37:06 -05:00
embark . initConfig ( 'development' , {
embarkConfig : 'embark.json' ,
interceptLogs : false
} ) ;
2018-08-16 18:02:54 -05:00
embark . ejectWebpack ( ) ;
} ) ;
}
2017-12-19 10:20:05 -05:00
versionCmd ( ) {
program
2018-09-07 12:37:18 -04:00
. command ( 'version' )
. description ( _ _ ( 'output the version number' ) )
. action ( function ( ) {
console . log ( embark . version ) ;
process . exit ( 0 ) ;
} ) ;
2017-12-19 10:20:05 -05:00
}
2018-08-14 16:48:40 -04:00
helpCmd ( ) {
program
2018-09-07 12:37:18 -04:00
. command ( 'help' )
. description ( _ _ ( 'output usage information and help information' ) )
. action ( function ( ) {
console . log ( "Documentation can be found at: " . green + "https://embark.status.im/docs/" . underline . green ) ;
console . log ( "" ) ;
console . log ( "Have an issue? submit it here: " . green + "https://github.com/embark-framework/embark/issues/new" . underline . green ) ;
console . log ( "or chat with us directly at: " . green + "https://gitter.im/embark-framework/Lobby" . underline . green ) ;
program . help ( ) ;
process . exit ( 0 ) ;
} ) ;
2018-08-14 16:48:40 -04:00
}
2017-03-30 20:12:39 +09:00
otherCommands ( ) {
program
2018-09-07 12:37:18 -04:00
. action ( function ( cmd ) {
2018-05-08 17:49:46 -04:00
console . log ( ( _ _ ( 'unknown command' ) + ' "%s"' ) . red , cmd ) ;
2018-08-08 15:05:22 -04:00
let utils = require ( '../lib/utils/utils.js' ) ;
2018-09-21 17:51:33 -04:00
let dictionary = [ 'new' , 'demo' , 'build' , 'run' , 'blockchain' , 'simulator' , 'test' , 'upload' , 'version' , 'console' , 'eject-webpack' , 'graph' , 'help' , 'reset' ] ;
2017-12-19 14:07:48 -05:00
let suggestion = utils . proposeAlternative ( cmd , dictionary ) ;
2017-12-19 13:29:48 -05:00
if ( suggestion ) {
2018-05-08 17:49:46 -04:00
console . log ( ( _ _ ( 'did you mean' ) + ' "%s"?' ) . green , suggestion ) ;
2017-12-19 13:29:48 -05:00
}
2017-03-30 20:12:39 +09:00
console . log ( "type embark --help to see the available commands" ) ;
process . exit ( 0 ) ;
} ) ;
}
2017-03-22 14:13:58 +09:00
2017-03-30 20:12:39 +09:00
}
2016-08-17 20:29:41 -04:00
module . exports = Cmd ;