1
1
package main
2
2
3
3
import (
4
+ "bytes"
4
5
"crypto/md5"
6
+ "encoding/csv"
5
7
"encoding/hex"
6
8
"encoding/json"
7
9
"flag"
@@ -190,11 +192,30 @@ func VersionAndUploadFiles(
190
192
return fileVersions , nil
191
193
}
192
194
195
+ // FormatManifest returns the file version manifest in json or csv format
196
+ func FormatManifest (fileVersions map [string ]string , format string ) ([]byte , error ) {
197
+ if format == "json" {
198
+ return json .MarshalIndent (fileVersions , "" , " " )
199
+ }
200
+ if format == "csv" {
201
+ b := & bytes.Buffer {}
202
+ wr := csv .NewWriter (b )
203
+ for filename , uri := range fileVersions {
204
+ row := []string {filename , uri }
205
+ wr .Write (row )
206
+ }
207
+ wr .Flush ()
208
+ return b .Bytes (), nil
209
+ }
210
+ return nil , nil
211
+ }
212
+
193
213
func main () {
194
214
s3Bucket := flag .String ("bucket" , defaultS3Bucket , "the s3 bucket to upload to" )
195
215
directory := flag .String ("dir" , "" , "required, the directory to upload files to in the bucket" )
196
216
filesArg := flag .String ("files" , "" , "the path to the files you'd like to upload, ex. \" public/**/.*js,public/style.css\" " )
197
217
outputFilename := flag .String ("o" , "staticAssets.json" , "the filename for the versions manifest" )
218
+ format := flag .String ("format" , "json" , "format of the output [json,csv]" )
198
219
dryRun := flag .Bool ("dry-run" , false , "print the output only, skip file uploads and manifest creation" )
199
220
printVersion := flag .Bool ("v" , false , "print the current buffer-static-upload version" )
200
221
flag .Parse ()
@@ -221,15 +242,15 @@ func main() {
221
242
fatal ("failed to upload files %s" , err )
222
243
}
223
244
224
- output , err := json . MarshalIndent (fileVersions , "" , " " )
245
+ output , err := FormatManifest (fileVersions , * format )
225
246
if err != nil {
226
- fatal ("failed to generate versions json file %s" , err )
247
+ fatal ("failed to format versions manifest file %s" , err )
227
248
}
228
249
229
250
if ! * dryRun {
230
251
err = ioutil .WriteFile (* outputFilename , output , 0644 )
231
252
if err != nil {
232
- fatal ("failed to write versions json file %s" , err )
253
+ fatal ("failed to write versions mainifest file %s" , err )
233
254
}
234
255
}
235
256
0 commit comments