2023-06-06 08:51:42 +00:00
|
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
2021-12-07 12:46:03 +00:00
|
|
|
import { join } from 'path'
|
2022-02-19 10:24:42 +00:00
|
|
|
import { fileURLToPath } from 'url'
|
2020-04-23 15:44:41 +00:00
|
|
|
|
2023-04-12 15:45:06 +00:00
|
|
|
export const dataDir = join(
|
2022-02-21 15:19:53 +00:00
|
|
|
fileURLToPath(import.meta.url),
|
|
|
|
'..',
|
|
|
|
'..',
|
|
|
|
'source',
|
2022-08-03 15:00:50 +00:00
|
|
|
'public',
|
2022-02-21 15:19:53 +00:00
|
|
|
'data'
|
|
|
|
)
|
2021-12-07 12:46:03 +00:00
|
|
|
|
|
|
|
export function createDataDir() {
|
|
|
|
if (!existsSync(dataDir)) {
|
|
|
|
mkdirSync(dataDir)
|
2020-04-23 15:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 12:46:03 +00:00
|
|
|
export function writeInDataDir(filename, data) {
|
|
|
|
writeFileSync(join(dataDir, filename), JSON.stringify(data, null, 2))
|
2020-04-23 15:44:41 +00:00
|
|
|
}
|
2023-06-06 08:51:42 +00:00
|
|
|
|
|
|
|
export function readInDataDir(filename) {
|
|
|
|
return JSON.parse(
|
|
|
|
readFileSync(join(dataDir, filename), { encoding: 'utf-8' })
|
|
|
|
)
|
|
|
|
}
|