Files
calendar/packages/app-store-cli/src/utils/getApp.ts
T
d4c5a906b5 App Store Templates (#5289)
* Start by moving what we have to _templates

* WIP

* WIP

* Add create/edit/delete template commands

* Type fixes cli

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: zomars <zomars@me.com>
2023-01-18 15:30:25 -07:00

27 lines
710 B
TypeScript

import fs from "fs";
import path from "path";
import { APP_STORE_PATH, TEMPLATES_PATH } from "../constants";
import { getAppName } from "./getAppName";
export const getApp = (slug: string, isTemplate: boolean) => {
const base = isTemplate ? TEMPLATES_PATH : APP_STORE_PATH;
const foundApp = fs
.readdirSync(base)
.filter((dir) => {
if (fs.statSync(path.join(base, dir)).isDirectory() && getAppName(dir)) {
return true;
}
return false;
})
.find((appName) => appName === slug);
if (foundApp) {
try {
return JSON.parse(fs.readFileSync(path.join(base, foundApp, "config.json")).toString());
} catch (e) {
return {};
}
}
return null;
};