@@ -8,8 +8,7 @@ const execa = require('execa')
8
8
const { nanoid } = require ( 'nanoid' )
9
9
const path = require ( 'path' )
10
10
const os = require ( 'os' )
11
- const tempWrite = require ( 'temp-write' )
12
- const { checkForRunningApi, repoExists, tmpDir, defaultRepo } = require ( './utils' )
11
+ const { checkForRunningApi, repoExists, tmpDir, defaultRepo, buildInitArgs, buildStartArgs } = require ( './utils' )
13
12
const waitFor = require ( 'p-wait-for' )
14
13
15
14
const daemonLog = {
@@ -87,35 +86,23 @@ class Daemon {
87
86
return this
88
87
}
89
88
90
- const opts = merge (
91
- {
92
- emptyRepo : false ,
93
- profiles : this . opts . test ? [ 'test' ] : [ ]
94
- } ,
95
- typeof this . opts . ipfsOptions . init === 'boolean' ? { } : this . opts . ipfsOptions . init ,
96
- typeof initOptions === 'boolean' ? { } : initOptions
89
+ initOptions = merge ( {
90
+ emptyRepo : false ,
91
+ profiles : this . opts . test ? [ 'test' ] : [ ]
92
+ } ,
93
+ typeof this . opts . ipfsOptions . init === 'boolean' ? { } : this . opts . ipfsOptions . init ,
94
+ typeof initOptions === 'boolean' ? { } : initOptions
97
95
)
98
96
99
- const args = [ 'init' ]
100
-
101
- // default-config only for JS
102
- if ( this . opts . ipfsOptions . config && this . opts . type === 'js' ) {
103
- args . push ( tempWrite . sync ( JSON . stringify ( this . opts . ipfsOptions . config ) ) )
104
- }
97
+ const opts = merge (
98
+ this . opts , {
99
+ ipfsOptions : {
100
+ init : initOptions
101
+ }
102
+ }
103
+ )
105
104
106
- // Translate ipfs options to cli args
107
- if ( opts . bits ) {
108
- args . push ( '--bits' , opts . bits )
109
- }
110
- if ( opts . pass && this . opts . type === 'js' ) {
111
- args . push ( '--pass' , '"' + opts . pass + '"' )
112
- }
113
- if ( opts . emptyRepo ) {
114
- args . push ( '--empty-repo' )
115
- }
116
- if ( Array . isArray ( opts . profiles ) && opts . profiles . length ) {
117
- args . push ( '--profile' , opts . profiles . join ( ',' ) )
118
- }
105
+ const args = buildInitArgs ( opts )
119
106
120
107
const { stdout, stderr } = await execa ( this . exec , args , {
121
108
env : this . env
@@ -166,30 +153,7 @@ class Daemon {
166
153
} else if ( ! this . exec ) {
167
154
throw new Error ( 'No executable specified' )
168
155
} else {
169
- const args = [ 'daemon' ]
170
- const opts = this . opts . ipfsOptions
171
- // add custom args
172
- args . push ( ...this . opts . args )
173
-
174
- if ( opts . pass && this . opts . type === 'js' ) {
175
- args . push ( '--pass' , '"' + opts . pass + '"' )
176
- }
177
-
178
- if ( opts . offline ) {
179
- args . push ( '--offline' )
180
- }
181
-
182
- if ( opts . preload && this . opts . type === 'js' ) {
183
- args . push ( '--enable-preload' , Boolean ( opts . preload . enabled ) )
184
- }
185
-
186
- if ( opts . EXPERIMENTAL && opts . EXPERIMENTAL . sharding && this . opts . type === 'js' ) {
187
- args . push ( '--enable-sharding-experiment' )
188
- }
189
-
190
- if ( opts . EXPERIMENTAL && opts . EXPERIMENTAL . ipnsPubsub ) {
191
- args . push ( '--enable-namesys-pubsub' )
192
- }
156
+ const args = buildStartArgs ( this . opts )
193
157
194
158
let output = ''
195
159
0 commit comments