index.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import checkSanitizeOptions from './checkSanitizeOptions.mjs'
  2. import Scrape from './scrape.mjs'
  3. import { fileURLToPath } from 'node:url'
  4. import { scriptRunner } from '../../lib/ScriptRunner.mjs'
  5. const { getAllPagesAndCache, scrapeAndCachePage } = Scrape
  6. async function main() {
  7. const BASE_URL = process.argv.pop()
  8. if (!BASE_URL.startsWith('http')) {
  9. throw new Error(
  10. 'Usage: node scripts/learn/checkSanitize/index.mjs https://LEARN_WIKI'
  11. )
  12. }
  13. const pages = await getAllPagesAndCache(BASE_URL)
  14. for (const page of pages) {
  15. try {
  16. const parsed = await scrapeAndCachePage(BASE_URL, page)
  17. const title = parsed.title
  18. const text = parsed.text ? parsed.text['*'] : ''
  19. checkSanitizeOptions(page, title, text)
  20. } catch (e) {
  21. console.error('---')
  22. console.error(page, e)
  23. throw e
  24. }
  25. }
  26. }
  27. if (fileURLToPath(import.meta.url) === process.argv[1]) {
  28. try {
  29. await scriptRunner(main)
  30. process.exit(0)
  31. } catch (error) {
  32. console.error(error)
  33. process.exit(1)
  34. }
  35. }