-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfs.ts
More file actions
37 lines (35 loc) · 1.03 KB
/
Copy pathfs.ts
File metadata and controls
37 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { promises as fs } from "fs";
import * as path from "path";
import { commitFilesFromBase64 } from "./core.ts";
import type {
CommitFilesFromBase64Args,
CommitFilesFromDirectoryArgs,
CommitFilesResult,
} from "./interface.ts";
export async function commitFilesFromDirectory({
cwd,
fileChanges,
...otherArgs
}: CommitFilesFromDirectoryArgs): Promise<CommitFilesResult> {
return await commitFilesFromBase64({
...otherArgs,
fileChanges: await normalizeFileChanges(fileChanges, cwd),
});
}
// Exported for testing only
export async function normalizeFileChanges(
fileChanges: CommitFilesFromDirectoryArgs["fileChanges"],
cwd: string,
): Promise<CommitFilesFromBase64Args["fileChanges"]> {
return {
additions: fileChanges.additions
? await Promise.all(
fileChanges.additions.map(async (a) => ({
path: a,
contents: await fs.readFile(path.join(cwd, a), "base64"),
})),
)
: undefined,
deletions: fileChanges.deletions?.map((d) => ({ path: d })),
};
}