feat: Serve static assets of apps

This commit is contained in:
Faruk AYDIN
2021-10-19 16:29:37 +02:00
committed by Ali BARIN
parent 5a2de1de9e
commit 672cc4c60c
17 changed files with 118 additions and 23 deletions

View File

@@ -4,22 +4,28 @@ class App {
static folderPath = __dirname + '/../apps';
static list = fs.readdirSync(this.folderPath);
static findAll(name?: string): object[] {
if(!name) return this.list.map((name) => this.findOneByName(name));
static async findAll(name?: string): Promise<object[]> {
let appList;
return this.list
.filter((app) => app.includes(name.toLowerCase()))
.map((name) => this.findOneByName(name));
if(!name) {
appList = this.list.map(async (name) => await this.findOneByName(name));
} else {
appList = this.list
.filter((app) => app.includes(name.toLowerCase()))
.map(async (name) => await this.findOneByName(name));
}
return Promise.all(appList)
}
static findOneByName(name: string): object {
const rawAppData = fs.readFileSync(this.folderPath + `/${name}/info.json`, 'utf-8');
return JSON.parse(rawAppData);
static async findOneByName(name: string): Promise<object> {
const rawAppData = (await import(`../apps/${name}/info`)).default;
return rawAppData;
}
static findOneByKey(key: string): object {
const rawAppData = fs.readFileSync(this.folderPath + `/${key}/info.json`, 'utf-8');
return JSON.parse(rawAppData);
static async findOneByKey(key: string): Promise<object> {
const rawAppData = (await import(`../apps/${key}/info`)).default;
return rawAppData;
}
}