doesitarm/scripts/download-sitemaps.js
ThatGuySam d45b587434 Finish axios migration via shared native HTTP helper
Replace all in-scope axios callsites with a new helpers/http.js wrapper over native fetch, including JSON/text GET, JSON POST, HEAD checks, and transient 5xx retry behavior; update all browser, build, script, and proxy API clients to use it; add focused unit tests; and remove axios from package dependencies.

Constraint: Preserve API/build and deployment behavior while lowering transport surface area.

Rejected: inline fetch replacements at each callsite | rejected to avoid inconsistent error/retry semantics.

Confidence: high

Scope-risk: moderate

Directive: Keep helper in place as the transport boundary and update tests when changing request semantics.

Tested: pnpm run -s typecheck, pnpm -s run test-prebuild, pnpm -s run test, pnpm -s run test:browser, pnpm -s run netlify-build, smoke GETs on /apple-silicon-app-test and /apple-silicon-app-test/?version=2

Not-tested: branch/netlify deployment health in CI pipeline after merge
2026-04-06 12:09:16 -05:00

55 lines
1.5 KiB
JavaScript

import fs from 'fs-extra'
import 'dotenv/config.js'
import {
sitemapLocation,
sitemapIndexFileName,
} from '~/helpers/constants.js'
import { parseSitemapXml } from '~/helpers/api/sitemap/parse.js'
import { getText } from '~/helpers/http.js'
;(async () => {
// Build Sitemap Index URL
const sitemapIndexUrl = new URL( `${ sitemapLocation.split('static')[1] }${ sitemapIndexFileName }`, process.env.PUBLIC_API_DOMAIN )
// Fetch Sitemap Index
const sitemapIndexXML = await getText( sitemapIndexUrl.href )
// Save Sitemap Index
const sitemapIndexFilePath = `${ sitemapLocation }${ sitemapIndexFileName }`
await fs.writeFile( sitemapIndexFilePath, sitemapIndexXML )
const urlEntries = parseSitemapXml( sitemapIndexXML )
// Fetch each sitemap
for ( const entry of urlEntries ) {
// Build Sitemap Index URL
const sitemapUrl = new URL( entry.loc )
const apiSitemapUrl = new URL( sitemapUrl.pathname, process.env.PUBLIC_API_DOMAIN )
// sitemapUrl.origin = process.env.PUBLIC_API_DOMAIN
// Fetch Sitemap Index
const sitemapXML = await getText( apiSitemapUrl.href )
// const sitemap = parse( sitemapXML )
// console.log( 'sitemap', sitemap )
// console.log( 'apiSitemapUrl', apiSitemapUrl )
const sitemapFileName = apiSitemapUrl.pathname.split('/')[1]
const sitemapIndexFilePath = `${ sitemapLocation }${ sitemapFileName }`
// Save file
await fs.writeFile( sitemapIndexFilePath, sitemapXML )
}
process.exit()
})()