@@ -26,7 +26,8 @@ const sendJSON = (ws, obj) => {
26
26
} ;
27
27
28
28
export default async function upload ( basedir , args ) {
29
- const { _ : namePaths , 'ag-solo' : agSolo } = parseArgs ( args , {
29
+ const { _ : namePaths , once, 'ag-solo' : agSolo } = parseArgs ( args , {
30
+ boolean : [ 'once' ] ,
30
31
default : {
31
32
target : 'contractHost' ,
32
33
} ,
@@ -37,8 +38,6 @@ export default async function upload(basedir, args) {
37
38
return 1 ;
38
39
}
39
40
40
- console . log ( `Uploading contracts...` ) ;
41
-
42
41
let wsurl = agSolo ;
43
42
if ( ! agSolo ) {
44
43
const cjson = await fs . promises . readFile (
@@ -77,9 +76,20 @@ export default async function upload(basedir, args) {
77
76
console . log ( 'Chain loaded:' , await bootC . G . LOADING . P ) ;
78
77
// Take a new copy, since the contract targets should exist.
79
78
bootC = E . C ( bootstrap ( ) ) ;
79
+ if ( once ) {
80
+ if ( await bootC . G . READY . M . isReady ( ) . P ) {
81
+ console . log ( 'Contracts already uploaded' ) ;
82
+ ws . close ( ) ;
83
+ exit . res ( 0 ) ;
84
+ return ;
85
+ }
86
+ }
87
+ const uploadsC = bootC . G . uploads ;
88
+
89
+ console . log ( `Uploading contracts...` ) ;
80
90
81
- const contractAP = [ ] ;
82
91
const names = [ ] ;
92
+ const contractsAP = [ ] ;
83
93
for ( const namePath of namePaths ) {
84
94
const match = namePath . match ( / ^ ( ( [ ^ \W - ] + ) - [ ^ = ] + ) = ( .+ ) $ / ) ;
85
95
if ( ! match ) {
@@ -98,21 +108,21 @@ export default async function upload(basedir, args) {
98
108
) ;
99
109
} else {
100
110
// Install the contract, then save it in home.uploads.
101
- contractAP . push ( E ( targetObj ) . install ( source , moduleFormat ) ) ;
111
+ console . log ( `Uploading ${ name } ` )
112
+ contractsAP . push ( E ( targetObj ) . install ( source , moduleFormat ) ) ;
102
113
names . push ( name ) ;
103
114
}
104
115
}
105
116
106
- const contracts = await Promise . all ( contractAP ) ;
107
-
108
- const uploadsC = bootC . G . uploads ;
109
- const uploadAP = [ ] ;
110
- for ( let i = 0 ; i < contractAP . length ; i += 1 ) {
111
- uploadAP . push ( uploadsC . M . set ( names [ i ] , contracts [ i ] ) . P ) ;
117
+ const contracts = await Promise . all ( contractsAP ) ;
118
+ for ( let i = 0 ; i < contracts . length ; i ++ ) {
119
+ await uploadsC . M . set ( names [ i ] , contracts [ i ] ) . P ;
112
120
}
113
121
114
- await Promise . all ( uploadAP ) ;
115
122
console . log ( 'Success! See home.uploads~.list()' ) ;
123
+ if ( once ) {
124
+ await bootC . G . READY . M . resolve ( 'contracts uploaded' ) . P ;
125
+ }
116
126
ws . close ( ) ;
117
127
exit . res ( 0 ) ;
118
128
} catch ( e ) {
0 commit comments