Skip to content

Commit

Permalink
feat: git add multiple files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Oct 26, 2021
1 parent 5e0ef82 commit 4aef61f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`);

Expand Down
6 changes: 2 additions & 4 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ export async function pushNewFiles(files: File[] = []): Promise<any> {
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();
}

0 comments on commit 4aef61f

Please sign in to comment.