aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/misc.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-06-24 22:50:38 +0200
committerHampusM <hampus@hampusmat.com>2021-06-24 22:50:38 +0200
commita13786d6cc185822f5940582efde2349ef729145 (patch)
tree7d4f49b50fc30ced65c5661b22b027456b79948e /packages/server/src/git/misc.ts
parent01e5d215dbc152e34ecd005111171457f87c235d (diff)
Refactored the backend yet again
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