11package main
22
33import (
4+ "bytes"
45 "crypto/md5"
6+ "encoding/csv"
57 "encoding/hex"
68 "encoding/json"
79 "flag"
@@ -190,11 +192,30 @@ func VersionAndUploadFiles(
190192 return fileVersions , nil
191193}
192194
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+
193213func main () {
194214 s3Bucket := flag .String ("bucket" , defaultS3Bucket , "the s3 bucket to upload to" )
195215 directory := flag .String ("dir" , "" , "required, the directory to upload files to in the bucket" )
196216 filesArg := flag .String ("files" , "" , "the path to the files you'd like to upload, ex. \" public/**/.*js,public/style.css\" " )
197217 outputFilename := flag .String ("o" , "staticAssets.json" , "the filename for the versions manifest" )
218+ format := flag .String ("format" , "json" , "format of the output [json,csv]" )
198219 dryRun := flag .Bool ("dry-run" , false , "print the output only, skip file uploads and manifest creation" )
199220 printVersion := flag .Bool ("v" , false , "print the current buffer-static-upload version" )
200221 flag .Parse ()
@@ -221,15 +242,15 @@ func main() {
221242 fatal ("failed to upload files %s" , err )
222243 }
223244
224- output , err := json . MarshalIndent (fileVersions , "" , " " )
245+ output , err := FormatManifest (fileVersions , * format )
225246 if err != nil {
226- fatal ("failed to generate versions json file %s" , err )
247+ fatal ("failed to format versions manifest file %s" , err )
227248 }
228249
229250 if ! * dryRun {
230251 err = ioutil .WriteFile (* outputFilename , output , 0644 )
231252 if err != nil {
232- fatal ("failed to write versions json file %s" , err )
253+ fatal ("failed to write versions mainifest file %s" , err )
233254 }
234255 }
235256
0 commit comments