(options: SyncOptions)
| 35 | await program.parseAsync(); |
| 36 | |
| 37 | async 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 | |
| 72 | function reportCacheWarnings(cache: FetchCache): void { |
| 73 | const warnings = cache.getWarnings(); |
no test coverage detected