MCPcopy Index your code
hub / github.com/VPSDance/ai-proxy-rules / sync

Function sync

scripts/sync.ts:37–70  ·  view source on GitHub ↗
(options: SyncOptions)

Source from the content-addressed store, hash-verified

35await program.parseAsync();
36
37async function sync(options: SyncOptions): Promise<void> {
38 const sourceFiles = await selectSourceFiles(options.input, options.provider);
39 const writes: string[] = [];
40 const cache = new FetchCache(options.cache);
41
42 await mkdir(options.output, { recursive: true });
43
44 for (const sourceFile of sourceFiles) {
45 const provider = await loadSourceProvider(sourceFile);
46 const normalized = await buildProviderData(provider, path.dirname(sourceFile), {
47 fetcher: (url) => cache.fetch(url),
48 cache
49 });
50 const outPath = path.join(options.output, `${provider.provider}.yaml`);
51
52 await writeFile(outPath, stringifyProviderData(normalized), "utf8");
53 writes.push(outPath);
54 }
55
56 for (const filePath of writes) {
57 console.log(filePath);
58 }
59
60 if (isFullSync(options.provider)) {
61 const removed = await cache.pruneOrphans();
62 if (removed.length > 0) {
63 const isGithubActions = process.env.GITHUB_ACTIONS === "true";
64 const tag = isGithubActions ? "::notice::" : "[notice] ";
65 console.log(`${tag}Pruned ${removed.length} orphan cache entry/entries.`);
66 }
67 }
68
69 reportCacheWarnings(cache);
70}
71
72function reportCacheWarnings(cache: FetchCache): void {
73 const warnings = cache.getWarnings();

Callers 1

sync.tsFile · 0.85

Calls 8

fetchMethod · 0.95
pruneOrphansMethod · 0.95
selectSourceFilesFunction · 0.85
loadSourceProviderFunction · 0.85
buildProviderDataFunction · 0.85
stringifyProviderDataFunction · 0.85
isFullSyncFunction · 0.85
reportCacheWarningsFunction · 0.85

Tested by

no test coverage detected