[Feature] App Store CLI - Make it super easy to add an app. (#2917)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Hariom Balharaandkodiakhq[bot] authored and GitHub committed 2022-06-07 11:43:32 +05:30
1 parent 51b86b1d97
commit 18e0f13605
44 files changed
+1290 -131

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
import prisma from ".";
require("dotenv").config({ path: "../../.env" });
// TODO: Put some restrictions here to run it on local DB only.
// Production DB currently doesn't support app deletion
async function main() {
const appId = process.argv[2];
try {
await prisma.app.delete({
where: {
slug: appId,
},
});
await prisma.credential.deleteMany({
where: {
appId: appId,
},
});
console.log(`Deleted app from DB: '${appId}'`);
} catch (e) {
if (e.code === "P2025") {
console.log(`App '${appId}' already deleted from DB`);
return;
}
throw e;
}
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
+2 -1
View File
@@ -16,7 +16,8 @@
"dx": "yarn db-setup",
"generate-schemas": "prisma generate && prisma format",
"post-install": "yarn generate-schemas",
"seed-app-store": "ts-node --transpile-only ./seed-app-store.ts"
"seed-app-store": "ts-node --transpile-only ./seed-app-store.ts",
"delete-app": "ts-node --transpile-only ./delete-app.ts"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
+1
View File
@@ -86,6 +86,7 @@ model Credential {
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
// How to make it a required column?
appId String?
}
@@ -0,0 +1 @@
[]
+10
View File
@@ -1,4 +1,6 @@
import { Prisma } from "@prisma/client";
import fs from "fs";
import path from "path";
import prisma from ".";
@@ -131,6 +133,14 @@ async function main() {
webhook_secret: process.env.STRIPE_WEBHOOK_SECRET,
});
}
const generatedApps = JSON.parse(
fs.readFileSync(path.join(__dirname, "seed-app-store.config.json"), "utf8")
);
for (let i = 0; i < generatedApps.length; i++) {
const generatedApp = generatedApps[i];
await createApp(generatedApp.slug, generatedApp.dirName, generatedApp.categories, generatedApp.type);
}
}
main()