1 | const fs = require('fs-extra')
|
2 | const sleep = require('../utils/sleep')
|
3 |
|
4 | const defaultPlaceholder = require('../defaults/content-waiting')
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | module.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 | })
|