mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
chore: update pjax-api script
This commit is contained in:
parent
69440c0138
commit
65562a6d9e
1 changed files with 11 additions and 10 deletions
|
|
@ -5,17 +5,15 @@
|
|||
const fs = require('fs').promises
|
||||
const path = require('path')
|
||||
|
||||
function modify(source = '', pairs = [], loose = true) {
|
||||
function modify(source = '', pairs = []) {
|
||||
for (const [original, replace] of pairs) {
|
||||
if (source.includes(original)) {
|
||||
source = source.replace(original, replace)
|
||||
if (source.includes(original)) {
|
||||
throw new Error(`More than one original string found`, JSON.stringify(original))
|
||||
}
|
||||
} else {
|
||||
if (loose) console.log(`Skipped missing snippet`, original)
|
||||
else throw new Error(`Original string not found`, JSON.stringify(original))
|
||||
}
|
||||
throw new Error(`Original string not found`, JSON.stringify(original))
|
||||
}
|
||||
|
||||
return source
|
||||
|
|
@ -54,11 +52,14 @@ async function fixPJAXAPI(loose) {
|
|||
}`,
|
||||
],
|
||||
]
|
||||
const filePath = path.resolve(__dirname, '..', `node_modules/pjax-api/dist/pjax-api.js`)
|
||||
const source = await fs.readFile(filePath, 'utf-8')
|
||||
const modified = modify(source, pairs, loose)
|
||||
fs.writeFile(filePath, modified, 'utf-8')
|
||||
try {
|
||||
const filePath = path.resolve(__dirname, '..', `node_modules/pjax-api/dist/pjax-api.js`)
|
||||
const source = await fs.readFile(filePath, 'utf-8')
|
||||
const modified = modify(source, pairs, loose)
|
||||
await fs.writeFile(filePath, modified, 'utf-8')
|
||||
} catch (err) {
|
||||
console.error((err && err.message) || err)
|
||||
}
|
||||
}
|
||||
|
||||
const loose = process.argv.includes('loose')
|
||||
fixPJAXAPI(loose)
|
||||
fixPJAXAPI()
|
||||
|
|
|
|||
Loading…
Reference in a new issue