aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/misc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/git/misc.ts')
-rw-r--r--packages/server/src/git/misc.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/server/src/git/misc.ts b/packages/server/src/git/misc.ts
new file mode 100644
index 0000000..fcfaf29
--- /dev/null
+++ b/packages/server/src/git/misc.ts
@@ -0,0 +1,36 @@
+import { readFile, readdir } from "fs";
+
+export async function findAsync<T>(arr: T[], callback: (t: T) => Promise<boolean>): Promise<T> {
+ const results = await Promise.all(arr.map(callback));
+ const index = results.findIndex(result => result);
+ return arr[index];
+}
+
+export type Author = {
+ name: string,
+ email: string
+}
+
+export function getFile(base_dir: string, repository: string, file: string): Promise<string | null> {
+ return new Promise(resolve => {
+ readFile(`${base_dir}/${repository}/${file}`, (err, content) => {
+ if(err) {
+ resolve(null);
+ return;
+ }
+ resolve(content.toString().replace(/\n/gu, ""));
+ });
+ });
+}
+
+export function getDirectory(directory: string): Promise<string[]> {
+ return new Promise<string[]>(resolve => {
+ readdir(directory, (err, dir_content) => {
+ if(err) {
+ resolve([]);
+ }
+
+ resolve(dir_content);
+ });
+ });
+} \ No newline at end of file