@@ -128,45 +128,54 @@ const isGif = path => path.endsWith(".gif");
128128const createGists = async ( files , githubToken ) => {
129129 const hashes = [ ] ;
130130 try {
131- for ( const file of files ) {
132- const files = {
133- [ file ] : {
134- content : `Placeholder for ${ file } .`
135- }
136- } ;
137- const body = JSON . stringify ( {
138- description : `Gist for ${ file } . Generated by \`crop-github-images-cli\`.` ,
139- public : true ,
140- files
141- } ) ;
142- const { body : res } = await got . post ( "gists" , {
143- baseUrl : "https://api.github.com" ,
144- headers : {
145- Authorization : `token ${ githubToken } `
146- } ,
147- body
148- } ) ;
149- const {
150- html_url,
151- id : hash ,
152- owner : { login }
153- } = JSON . parse ( res ) ;
154- console . log ( `Prepared the gist for ${ file } in ${ html_url } ` ) ;
155- await cloneGistPath ( hash ) ;
156- await cp ( file , `${ hash } /${ file } ` ) ;
157- const gitPath = resolve ( `./${ hash } /.git` ) ;
158- await commitAll ( gitPath ) ;
159- fs . writeFileSync (
160- `${ hash } /.netrc` ,
161- `machine github.com\nlogin ${ login } \npassword ${ githubToken } `
162- ) ;
163- await push ( gitPath ) ;
164- hashes . push ( hash ) ;
165- console . log (
166- `${ isGif ( path ) ? "GIF" : "Image" } ${ file } has been added to the gist`
167- ) ;
168- }
131+ await Promise . all (
132+ files . map (
133+ file =>
134+ new Promise ( async done => {
135+ const files = {
136+ [ file ] : {
137+ content : `Placeholder for ${ file } .`
138+ }
139+ } ;
140+ const body = JSON . stringify ( {
141+ description : `Gist for ${ file } . Generated by \`crop-github-images-cli\`.` ,
142+ public : true ,
143+ files
144+ } ) ;
145+ const { body : res } = await got . post ( "gists" , {
146+ baseUrl : "https://api.github.com" ,
147+ headers : {
148+ Authorization : `token ${ githubToken } `
149+ } ,
150+ body
151+ } ) ;
152+ const {
153+ html_url,
154+ id : hash ,
155+ owner : { login }
156+ } = JSON . parse ( res ) ;
157+ console . log ( `Prepared the gist for ${ file } in ${ html_url } ` ) ;
158+ await cloneGistPath ( hash ) ;
159+ await cp ( file , `${ hash } /${ file } ` ) ;
160+ const gitPath = resolve ( `./${ hash } /.git` ) ;
161+ await commitAll ( gitPath ) ;
162+ fs . writeFileSync (
163+ `${ hash } /.netrc` ,
164+ `machine github.com\nlogin ${ login } \npassword ${ githubToken } `
165+ ) ;
166+ await push ( gitPath ) ;
167+ hashes . push ( hash ) ;
168+ console . log (
169+ `${
170+ isGif ( path ) ? "GIF" : "Image"
171+ } ${ file } has been added to the gist`
172+ ) ;
173+ done ( ) ;
174+ } )
175+ )
176+ ) ;
169177 await trash ( hashes ) ;
178+ console . log ( "Cleaned working directory." ) ;
170179 } catch ( e ) {
171180 console . error ( e ) ;
172181 if ( hashes . length ) {
0 commit comments