1- const path = require ( "path" ) ;
2- const _ = require ( "lodash" ) ;
3- const Provider = require ( "@truffle/provider" ) ;
1+ import * as path from 'path' ;
2+ import lodash from 'lodash' ;
3+ import Provider from '@truffle/provider' ;
4+ import TruffleConfig from './' ;
5+
6+ export const getInitialConfig = ( {
7+ truffleDirectory,
8+ workingDirectory,
9+ network,
10+ } : {
11+ truffleDirectory ?: string ;
12+ workingDirectory ?: string ;
13+ network ?: string ;
14+ } ) => {
15+ const truffle_directory = truffleDirectory || path . resolve ( path . join ( __dirname , '../' ) ) ;
16+ const working_directory = workingDirectory || process . cwd ( ) ;
417
5- // This is a list of multi-level keys with defaults
6- // we need to _.merge. Using this list for safety
7- // vs. just merging all objects.
8- const _values = ( { truffleDirectory, workingDirectory, network } ) => {
918 return {
10- truffle_directory :
11- truffleDirectory || path . resolve ( path . join ( __dirname , "../" ) ) ,
12- working_directory : workingDirectory || process . cwd ( ) ,
19+ truffle_directory,
20+ working_directory,
1321 network,
1422 networks : { } ,
1523 verboseRpc : false ,
@@ -42,34 +50,38 @@ const _values = ({ truffleDirectory, workingDirectory, network }) => {
4250 vyper : { }
4351 } ,
4452 logger : {
45- log ( ) { }
53+ log ( ) { }
4654 }
4755 } ;
4856} ;
4957
50- const configProps = ( { configObject } ) => {
51- const resolveDirectory = value => {
52- return path . resolve ( configObject . working_directory , value ) ;
53- } ;
58+ export const configProps = ( {
59+ configObject
60+ } : {
61+ configObject : TruffleConfig
62+ } ) => {
63+ const resolveDirectory = ( value : string ) : string =>
64+ path . resolve ( configObject . working_directory , value ) ;
5465
5566 const defaultTXValues = {
5667 gas : 6721975 ,
5768 gasPrice : 20000000000 , // 20 gwei,
58- from : null
69+ from : null ,
5970 } ;
71+
6072 return {
6173 // These are already set.
62- truffle_directory ( ) { } ,
63- working_directory ( ) { } ,
64- network ( ) { } ,
65- networks ( ) { } ,
66- verboseRpc ( ) { } ,
67- build ( ) { } ,
68- resolver ( ) { } ,
69- artifactor ( ) { } ,
70- ethpm ( ) { } ,
71- logger ( ) { } ,
72- compilers ( ) { } ,
74+ truffle_directory ( ) { } ,
75+ working_directory ( ) { } ,
76+ network ( ) { } ,
77+ networks ( ) { } ,
78+ verboseRpc ( ) { } ,
79+ build ( ) { } ,
80+ resolver ( ) { } ,
81+ artifactor ( ) { } ,
82+ ethpm ( ) { } ,
83+ logger ( ) { } ,
84+ compilers ( ) { } ,
7385
7486 build_directory : {
7587 default : ( ) => path . join ( configObject . working_directory , "build" ) ,
@@ -123,15 +135,15 @@ const configProps = ({ configObject }) => {
123135 throw new Error ( "Network not set. Cannot determine network to use." ) ;
124136 }
125137
126- let conf = configObject . networks [ network ] ;
138+ let config = configObject . networks [ network ] ;
127139
128- if ( conf === null || conf === undefined ) {
140+ if ( config === null || config === undefined ) {
129141 config = { } ;
130142 }
131143
132- conf = _ . extend ( { } , defaultTXValues , conf ) ;
144+ config = lodash . extend ( { } , defaultTXValues , config ) ;
133145
134- return conf ;
146+ return config ;
135147 } ,
136148 set ( ) {
137149 throw new Error (
@@ -241,9 +253,4 @@ const configProps = ({ configObject }) => {
241253 }
242254 }
243255 } ;
244- } ;
245-
246- module . exports = {
247- _values,
248- configProps
249- } ;
256+ } ;
0 commit comments