2024-10-17 20:31:18 +00:00
|
|
|
import { ArgumentParser } from "argparse";
|
2024-11-13 02:37:35 +00:00
|
|
|
import { existsSync } from 'fs';
|
|
|
|
|
import { mkdir } from 'fs/promises';
|
2024-10-17 20:31:18 +00:00
|
|
|
import path from 'path';
|
2024-11-13 02:37:35 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:37:35 +00:00
|
|
|
parser.add_argument("--configPath", {
|
|
|
|
|
help: "Path to config file",
|
|
|
|
|
required: true,
|
|
|
|
|
});
|
2024-11-10 00:40:07 +00:00
|
|
|
|
2024-11-13 02:37:35 +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
|
|
|
|
2024-11-13 02:37:35 +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
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:37:35 +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
|
|
|
|
2024-11-13 02:37:35 +00:00
|
|
|
if (!existsSync(reposPath)) {
|
|
|
|
|
await mkdir(reposPath, { recursive: true });
|
2024-11-07 02:28:10 +00:00
|
|
|
}
|
2024-11-13 02:37:35 +00:00
|
|
|
if (!existsSync(indexPath)) {
|
|
|
|
|
await mkdir(indexPath, { recursive: true });
|
2024-10-17 20:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:37:35 +00:00
|
|
|
const context: AppContext = {
|
|
|
|
|
indexPath,
|
|
|
|
|
reposPath,
|
|
|
|
|
cachePath: cacheDir,
|
|
|
|
|
configPath: args.configPath,
|
|
|
|
|
}
|
2024-11-10 00:40:07 +00:00
|
|
|
|
2024-11-13 02:37:35 +00:00
|
|
|
main(context).finally(() => {
|
|
|
|
|
console.log("Shutting down...");
|
|
|
|
|
});
|