mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
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:
@@ -1,7 +1,7 @@
|
||||
# Usage
|
||||
|
||||
```
|
||||
node scripts/learn/checkSanitize https://LEARN_WIKI
|
||||
node scripts/learn/checkSanitize/index.mjs https://LEARN_WIKI
|
||||
```
|
||||
|
||||
## Bulk export
|
||||
|
||||
+12
-14
@@ -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
|
||||
+13
-7
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -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,
|
||||
}
|
||||
Reference in New Issue
Block a user