mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-13 21:05:22 +00:00
* [wip] initial mt support in config syncer * Move logout button & profile picture into settings dropdown (#172) * update sync status properly and fix bug with multiple config in db case * make config path required in single tenant mode NOTE: deleting config/repos is currently not supported in multi tenancy case. Support for this will be added in a future PR --------- Co-authored-by: Brendan Kellam <bshizzle1234@gmail.com>
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { ArgumentParser } from "argparse";
|
|
import { existsSync } from 'fs';
|
|
import { mkdir } from 'fs/promises';
|
|
import path from 'path';
|
|
import { isRemotePath } from "./utils.js";
|
|
import { AppContext } from "./types.js";
|
|
import { main } from "./main.js"
|
|
import { PrismaClient } from "@sourcebot/db";
|
|
import { SOURCEBOT_TENANT_MODE } from "./environment.js";
|
|
|
|
|
|
const parser = new ArgumentParser({
|
|
description: "Sourcebot backend tool",
|
|
});
|
|
|
|
type Arguments = {
|
|
configPath: string;
|
|
cacheDir: string;
|
|
}
|
|
|
|
parser.add_argument("--configPath", {
|
|
help: "Path to config file",
|
|
required: SOURCEBOT_TENANT_MODE === "single",
|
|
});
|
|
|
|
parser.add_argument("--cacheDir", {
|
|
help: "Path to .sourcebot cache directory",
|
|
required: true,
|
|
});
|
|
const args = parser.parse_args() as Arguments;
|
|
|
|
if (SOURCEBOT_TENANT_MODE === "single" && !isRemotePath(args.configPath) && !existsSync(args.configPath)) {
|
|
console.error(`Config file ${args.configPath} does not exist, and is required in single tenant mode`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const cacheDir = args.cacheDir;
|
|
const reposPath = path.join(cacheDir, 'repos');
|
|
const indexPath = path.join(cacheDir, 'index');
|
|
|
|
if (!existsSync(reposPath)) {
|
|
await mkdir(reposPath, { recursive: true });
|
|
}
|
|
if (!existsSync(indexPath)) {
|
|
await mkdir(indexPath, { recursive: true });
|
|
}
|
|
|
|
const context: AppContext = {
|
|
indexPath,
|
|
reposPath,
|
|
cachePath: cacheDir,
|
|
configPath: args.configPath,
|
|
}
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
main(prisma, context)
|
|
.then(async () => {
|
|
await prisma.$disconnect();
|
|
})
|
|
.catch(async (e) => {
|
|
console.error(e);
|
|
await prisma.$disconnect();
|
|
process.exit(1);
|
|
})
|
|
.finally(() => {
|
|
console.log("Shutting down...");
|
|
});
|