Merge pull request #21282 from overleaf/ls-scripts-to-esm-5

Migrate rest of the scripts to esm

GitOrigin-RevId: 421f3ccd15342d34113be8d22e343d08533177ea
This commit is contained in:
Liangjun Song
2024-10-25 08:05:41 +00:00
committed by Copybot
parent e3b93f0a22
commit 14cd8f5479
13 changed files with 140 additions and 125 deletions
@@ -1,7 +1,7 @@
# Usage
```
node scripts/learn/checkSanitize https://LEARN_WIKI
node scripts/learn/checkSanitize/index.mjs https://LEARN_WIKI
```
## Bulk export
@@ -1,15 +1,15 @@
const crypto = require('crypto')
const fs = require('fs')
const Path = require('path')
const cheerio = require('cheerio')
const prettier = require('prettier')
const sanitizeHtml = require('sanitize-html')
const {
sanitizeOptions,
} = require('../../../modules/learn/app/src/sanitizeOptions')
import crypto from 'crypto'
import fs from 'fs'
import Path from 'path'
import cheerio from 'cheerio'
// checkSanitizeOptions is only used in dev env
// eslint-disable-next-line import/no-extraneous-dependencies
import prettier from 'prettier'
import sanitizeHtml from 'sanitize-html'
import { sanitizeOptions } from '../../../modules/learn/app/src/sanitizeOptions.js'
import { fileURLToPath } from 'url'
const __dirname = Path.dirname(fileURLToPath(import.meta.url))
const EXTRACT_STYLE = process.env.EXTRACT_STYLES === 'true'
const OMIT_STYLE = process.env.OMIT_STYLE !== 'false'
const DUMP_CSS_IN = Path.join(
@@ -115,6 +115,4 @@ function checkSanitizeOptions(page, title, text) {
console.error('sanitizedToText:', peak(sanitizedToText, offsetText))
}
module.exports = {
checkSanitizeOptions,
}
export default checkSanitizeOptions
@@ -1,11 +1,14 @@
const { checkSanitizeOptions } = require('./checkSanitizeOptions')
const { getAllPagesAndCache, scrapeAndCachePage } = require('./scrape')
import checkSanitizeOptions from './checkSanitizeOptions.mjs'
import Scrape from './scrape.mjs'
import { fileURLToPath } from 'url'
const { getAllPagesAndCache, scrapeAndCachePage } = Scrape
async function main() {
const BASE_URL = process.argv.pop()
if (!BASE_URL.startsWith('http')) {
throw new Error(
'Usage: node scripts/learn/checkSanitize https://LEARN_WIKI'
'Usage: node scripts/learn/checkSanitize/index.mjs https://LEARN_WIKI'
)
}
@@ -27,9 +30,12 @@ async function main() {
}
}
if (require.main === module) {
main().catch(err => {
console.error(err)
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await main()
process.exit(0)
} catch (error) {
console.error(error)
process.exit(1)
})
}
}
@@ -1,12 +1,14 @@
const Path = require('path')
const fs = require('fs')
const {
import Path from 'path'
import fs from 'fs'
import {
fetchString,
fetchJson,
RequestFailedError,
} = require('@overleaf/fetch-utils')
} from '@overleaf/fetch-utils'
import crypto from 'crypto'
import { fileURLToPath } from 'url'
const __dirname = Path.dirname(fileURLToPath(import.meta.url))
const CACHE_IN = Path.join(
Path.dirname(Path.dirname(Path.dirname(__dirname))),
'data',
@@ -33,8 +35,6 @@ async function scrape(baseUrl, page) {
}
}
const crypto = require('crypto')
function hash(blob) {
return crypto.createHash('sha1').update(blob).digest('hex')
}
@@ -124,7 +124,7 @@ async function getAllPagesAndCache(baseUrl) {
}
}
module.exports = {
export default {
getAllPagesAndCache,
scrapeAndCachePage,
}