Skip to content

Commit 4aef61f

Browse files
author
GitHub Actions
committed
feat: git add multiple files at once
1 parent 5e0ef82 commit 4aef61f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/git.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ class Git {
6060
config = (prop: string, value: string) =>
6161
this.exec(`config ${prop} "${value}"`);
6262

63-
add = (file: string) => this.exec(`add ${file}`);
63+
add = (file: string | string[]) => {
64+
let str = '';
65+
if (Array.isArray(file)) {
66+
file.map((f) => (str += ` ${f}`));
67+
} else {
68+
str = file;
69+
}
70+
return this.exec(`add ${str}`);
71+
};
6472

6573
commit = (message: string) => this.exec(`commit -m "${message}"`);
6674

src/helpers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ export async function pushNewFiles(files: File[] = []): Promise<any> {
129129
await git.pull();
130130

131131
await Promise.all(
132-
files.map(async ({ filename, data }) => {
133-
await fsp.writeFile(filename, data);
134-
await git.add(filename);
135-
})
132+
files.map(({ filename, data }) => fsp.writeFile(filename, data))
136133
);
137134

135+
await git.add(files.map(({ filename }) => filename));
138136
await git.commit(`chore(updates): updated entries in files`);
139137
await git.push();
140138
}

0 commit comments

Comments
 (0)