UNPKG

854 BJavaScriptView Raw
1const fs = require('fs-extra')
2const sleep = require('../utils/sleep')
3
4const defaultPlaceholder = require('../defaults/content-waiting')
5
6/**
7 * 检查文件内容是否已更新(条件:和 placeholder 字符不同)
8 * @async
9 * @param {String} pathname
10 * @param {String} [contentPlaceholder]
11 * @returns {Promise}
12 */
13module.exports = async (pathname, contentPlaceholder = defaultPlaceholder) =>
14 await new Promise(resolve => {
15 const waiting = () => setTimeout(async () => {
16 if (!fs.existsSync(pathname))
17 return waiting()
18 const content = await fs.readFile(pathname, 'utf-8')
19 if (!content || content === contentPlaceholder)
20 return waiting()
21 await sleep(100)
22 resolve(content)
23 }, 500)
24 waiting()
25 })