sourcebot/packages/backend/src/index.ts

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-10-17 20:31:18 +00:00
import { ArgumentParser } from "argparse";
import { existsSync } from 'fs';
import { mkdir } from 'fs/promises';
2024-10-17 20:31:18 +00:00
import path from 'path';
import { isRemotePath } from "./utils.js";
import { AppContext } from "./types.js";
import { main } from "./main.js"
2024-10-17 20:31:18 +00:00
const parser = new ArgumentParser({
description: "Sourcebot backend tool",
});
type Arguments = {
configPath: string;
cacheDir: string;
}
parser.add_argument("--configPath", {
help: "Path to config file",
required: true,
});
2024-11-10 00:40:07 +00:00
parser.add_argument("--cacheDir", {
help: "Path to .sourcebot cache directory",
required: true,
});
const args = parser.parse_args() as Arguments;
2024-11-01 17:51:14 +00:00
if (!isRemotePath(args.configPath) && !existsSync(args.configPath)) {
console.error(`Config file ${args.configPath} does not exist`);
process.exit(1);
2024-10-17 20:31:18 +00:00
}
const cacheDir = args.cacheDir;
const reposPath = path.join(cacheDir, 'repos');
const indexPath = path.join(cacheDir, 'index');
2024-11-07 02:28:10 +00:00
if (!existsSync(reposPath)) {
await mkdir(reposPath, { recursive: true });
2024-11-07 02:28:10 +00:00
}
if (!existsSync(indexPath)) {
await mkdir(indexPath, { recursive: true });
2024-10-17 20:31:18 +00:00
}
const context: AppContext = {
indexPath,
reposPath,
cachePath: cacheDir,
configPath: args.configPath,
}
2024-11-10 00:40:07 +00:00
main(context).finally(() => {
console.log("Shutting down...");
});