resource extraction and reading
This commit is contained in:
20
server/util/readDir.ts
Normal file
20
server/util/readDir.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const readDirFiles = async (path: string) => {
|
||||
return readDirFiltered(path, (file) => file.isFile);
|
||||
};
|
||||
|
||||
export const readDirDirs = async (path: string) => {
|
||||
return readDirFiltered(path, (file) => file.isDirectory);
|
||||
};
|
||||
|
||||
export const readDirFiltered = async (
|
||||
path: string,
|
||||
filter: (file: Deno.DirEntry) => boolean,
|
||||
) => {
|
||||
const files: string[] = [];
|
||||
for await (const file of Deno.readDir(path)) {
|
||||
if (filter(file)) {
|
||||
files.push(file.name);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
};
|
14
server/util/versionCompat.ts
Normal file
14
server/util/versionCompat.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const versionCompat = (version: string, targetVersion: string) => {
|
||||
if (targetVersion === "*") return true;
|
||||
if (targetVersion === version) return true;
|
||||
if (targetVersion.startsWith("^")) {
|
||||
const versionSplit = version.split(".");
|
||||
const targetVersionSplit = targetVersion.split(".");
|
||||
for (let i = 0; i < versionSplit.length; i++) {
|
||||
if (versionSplit[i] > targetVersionSplit[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
Reference in New Issue
Block a user