chore: Find apps folder path by using require resolve
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
b2369fa8cd
commit
bbb6f0b0ff
@@ -1,12 +1,14 @@
|
||||
import fs from 'fs';
|
||||
import { dirname, join } from 'path';
|
||||
import appInfoConverter from '../helpers/app-info-converter';
|
||||
|
||||
class App {
|
||||
static folderPath = __dirname + '/../apps';
|
||||
static backendPath = require.resolve('@automatisch/backend');
|
||||
static folderPath = join(dirname(this.backendPath), 'apps');
|
||||
static list = fs.readdirSync(this.folderPath);
|
||||
|
||||
static findAll(name?: string): object[] {
|
||||
if(!name) return this.list.map((name) => this.findOneByName(name));
|
||||
if (!name) return this.list.map((name) => this.findOneByName(name));
|
||||
|
||||
return this.list
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
@@ -14,12 +16,18 @@ class App {
|
||||
}
|
||||
|
||||
static findOneByName(name: string): object {
|
||||
const rawAppData = fs.readFileSync(this.folderPath + `/${name}/info.json`, 'utf-8');
|
||||
const rawAppData = fs.readFileSync(
|
||||
this.folderPath + `/${name}/info.json`,
|
||||
'utf-8'
|
||||
);
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
|
||||
static findOneByKey(key: string): object {
|
||||
const rawAppData = fs.readFileSync(this.folderPath + `/${key}/info.json`, 'utf-8');
|
||||
const rawAppData = fs.readFileSync(
|
||||
this.folderPath + `/${key}/info.json`,
|
||||
'utf-8'
|
||||
);
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user