From 4aef61f23244ca4ed21134e79de05ec6d41c3366 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 26 Oct 2021 09:41:22 +0200 Subject: [PATCH] feat: git add multiple files at once --- src/git.ts | 10 +++++++++- src/helpers.ts | 6 ++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/git.ts b/src/git.ts index 51c36e3..c77249b 100644 --- a/src/git.ts +++ b/src/git.ts @@ -60,7 +60,15 @@ class Git { config = (prop: string, value: string) => this.exec(`config ${prop} "${value}"`); - add = (file: string) => this.exec(`add ${file}`); + add = (file: string | string[]) => { + let str = ''; + if (Array.isArray(file)) { + file.map((f) => (str += ` ${f}`)); + } else { + str = file; + } + return this.exec(`add ${str}`); + }; commit = (message: string) => this.exec(`commit -m "${message}"`); diff --git a/src/helpers.ts b/src/helpers.ts index 5337f70..948520b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -129,12 +129,10 @@ export async function pushNewFiles(files: File[] = []): Promise { await git.pull(); await Promise.all( - files.map(async ({ filename, data }) => { - await fsp.writeFile(filename, data); - await git.add(filename); - }) + files.map(({ filename, data }) => fsp.writeFile(filename, data)) ); + await git.add(files.map(({ filename }) => filename)); await git.commit(`chore(updates): updated entries in files`); await git.push(); }