@@ -15,13 +15,15 @@ ContractMetadata = require './ContractMetadata'
15
15
ContractExecution = require ' ./ContractExecution'
16
16
ContractTemplate = require ' ./ContractTemplate'
17
17
prettyjson = require ' prettyjson'
18
+ zipIt = require (' zip-a-folder' )
18
19
19
20
class SetupClient
20
21
21
22
constructor : (opts ) ->
22
23
@g = opts .graph
23
24
@clientIdentity = opts .clientIdentity .uuid
24
25
@container = opts .container
26
+ @baseTemplateDirectory = opts .baseTemplateDirectory
25
27
26
28
getWorkerId : () =>
27
29
@clientIdentity
@@ -68,6 +70,10 @@ class SetupClient
68
70
result = await @ execute directory, sampleTxtFile, requestFile, stateFile
69
71
console .log result
70
72
73
+ program .usage (' zip <folder>' ).command (' zip <folder>' ).action (folder, cmd) =>
74
+ console .log ' zip folder ' + folder
75
+ @ zipFolder folder
76
+
71
77
# Subscribe to server to await work events
72
78
program .usage (' subscribe <server ip address> <server port>' ).command (' subscribe <server ip address> <server port>' ).action (serverIp, serverPort, cmd) =>
73
79
console .log ' subscribe, attempting to subscribe to server for work'
@@ -77,13 +83,14 @@ class SetupClient
77
83
program .parse process .argv
78
84
79
85
deploy : (guid , directoryToCreate ) =>
86
+ dir = @baseTemplateDirectory + directoryToCreate
80
87
contractJson = await @ fetchContractJsonFromServer guid
81
- await @ createProject directoryToCreate , contractJson
88
+ await @ createProject dir , contractJson
82
89
83
90
templateProcess : (jsonData , grammar , directory ) =>
84
- # t = new ContractTemplate()
85
91
t = @container .resolve " ContractTemplate"
86
- await t .template (jsonData, grammar, directory)
92
+ dir = @baseTemplateDirectory + directory
93
+ await t .template (jsonData, grammar, dir)
87
94
88
95
extract : (directory , jsonFile , isMulti ) =>
89
96
meta = new ContractMetadata ()
@@ -177,8 +184,16 @@ class SetupClient
177
184
result = @ export params[0 ], params[1 ]
178
185
if (command == ' exportmulti' )
179
186
result = @ export params[0 ], params[1 ]
187
+ if (command == ' zip' )
188
+ result = @ zipFolder params[0 ]
180
189
result
181
190
191
+ zipFolder : (folder ) =>
192
+ base = @baseTemplateDirectory
193
+ f = base + folder
194
+ a = base + folder + ' .zip'
195
+ await zipIt .zip (f, a)
196
+
182
197
subscribeCluster : (serverId , port ) =>
183
198
socket = new ClusterWS (url : ' ws://localhost:3050' )
184
199
@@ -236,6 +251,8 @@ class SetupClient
236
251
237
252
# Executes all handlebars templates and places them in the destination directory
238
253
createProject : (dir , contract ) =>
254
+ console .log ' create project'
255
+ console .log dir
239
256
@ createDirectoryIfNotExist dir
240
257
@ createDirectoryIfNotExist dir + path .sep + ' grammar'
241
258
@ createDirectoryIfNotExist dir + path .sep + ' lib'
0 commit comments