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

committed by
Ömer Faruk Aydın

parent
b2369fa8cd
commit
bbb6f0b0ff
@@ -5,7 +5,7 @@
|
||||
"scripts": {
|
||||
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/app.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"start": "node dist/src/app.js",
|
||||
"test": "ava",
|
||||
"lint": "eslint . --ignore-path ../../.eslintignore",
|
||||
"db:create": "ts-node ./bin/database/create.ts",
|
||||
@@ -75,6 +75,7 @@
|
||||
"@types/node": "^16.10.2",
|
||||
"@types/nodemailer": "^6.4.4",
|
||||
"@types/pg": "^8.6.1",
|
||||
"@types/pino": "^7.0.5",
|
||||
"ava": "^3.15.0",
|
||||
"eslint": "8.7.0",
|
||||
"nodemon": "^2.0.13",
|
||||
|
@@ -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