First build
This commit is contained in:
parent
511556737e
commit
fd773f5832
954 changed files with 305115 additions and 2 deletions
60
src/paths.js
Normal file
60
src/paths.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const APP_ROOT = path.resolve(__dirname, '..')
|
||||
|
||||
const BUILD = process.env.PLGL_BUILD_DIR || path.join(APP_ROOT, 'build')
|
||||
const BUNDLED = path.join(APP_ROOT, 'files')
|
||||
|
||||
const FILES = path.join(BUILD, 'files')
|
||||
const DATA = path.join(FILES, 'data')
|
||||
|
||||
const DIRS = {
|
||||
BUILD,
|
||||
APP_ROOT,
|
||||
FILES,
|
||||
DATA,
|
||||
WINES: path.join(FILES, 'wines'),
|
||||
PREFIXES: path.join(FILES, 'wineprefixes'),
|
||||
GAMES: path.join(FILES, 'games'),
|
||||
TRANSLATIONS: path.join(FILES, 'translations'),
|
||||
BUNDLED_TRANSLATIONS: path.join(BUNDLED, 'translations'),
|
||||
FAKE_STEAM: path.join(DATA, 'fake-steam')
|
||||
}
|
||||
|
||||
function ensureDirs() {
|
||||
const legacy = path.join(FILES, 'wine prefixes')
|
||||
try {
|
||||
if (fs.existsSync(legacy) && !fs.existsSync(DIRS.PREFIXES)) fs.renameSync(legacy, DIRS.PREFIXES)
|
||||
} catch {}
|
||||
for (const dir of [FILES, DATA, DIRS.WINES, DIRS.PREFIXES, DIRS.GAMES, DIRS.TRANSLATIONS, DIRS.FAKE_STEAM]) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
if (DIRS.TRANSLATIONS !== DIRS.BUNDLED_TRANSLATIONS) {
|
||||
try {
|
||||
for (const f of fs.readdirSync(DIRS.BUNDLED_TRANSLATIONS)) {
|
||||
const dst = path.join(DIRS.TRANSLATIONS, f)
|
||||
if (!fs.existsSync(dst)) fs.copyFileSync(path.join(DIRS.BUNDLED_TRANSLATIONS, f), dst)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
function readJson(file, fallback) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
||||
} catch {
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
||||
function writeJson(file, data) {
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true })
|
||||
const tmp = file + '.tmp'
|
||||
fs.writeFileSync(tmp, JSON.stringify(data, null, 2))
|
||||
fs.renameSync(tmp, file)
|
||||
}
|
||||
|
||||
module.exports = { APP_ROOT, BUILD, FILES, DATA, DIRS, ensureDirs, readJson, writeJson }
|
||||
Loading…
Add table
Add a link
Reference in a new issue