'use strict' const fs = require('fs') const path = require('path') const root = path.resolve(__dirname, '..') const html = fs.readFileSync(path.join(root, 'renderer', 'index.html'), 'utf8') const css = fs.readFileSync(path.join(root, 'renderer', 'style.css'), 'utf8') const appJs = fs.readFileSync(path.join(root, 'renderer', 'app.js'), 'utf8') const en = JSON.parse(fs.readFileSync(path.join(root, 'files', 'translations', 'en-us.json'), 'utf8')) const pl = JSON.parse(fs.readFileSync(path.join(root, 'files', 'translations', 'pl.json'), 'utf8')) const fonts = { regular: fs.readFileSync(path.join(root, 'renderer', 'Nunito-Regular.ttf')).toString('base64'), black: fs.readFileSync(path.join(root, 'renderer', 'Nunito-Black.ttf')).toString('base64') } const mock = ` window.plgl = { FILES_DIR: '/home/user/PLGL/files', i18nList: async () => [ { code: 'en-us', nameEn: ${JSON.stringify(en.data.nameEn)}, nameSelf: ${JSON.stringify(en.data.nameSelf)} }, { code: 'pl', nameEn: ${JSON.stringify(pl.data.nameEn)}, nameSelf: ${JSON.stringify(pl.data.nameSelf)} } ], i18nGet: async code => ({ 'en-us': ${JSON.stringify(en)}, 'pl': ${JSON.stringify(pl)} }[code] || ${JSON.stringify(en)}), settingsGet: async () => ({ language: 'en-us', defaultWine: 'proton-ge-proton9-20' }), settingsSet: async p => ({ language: 'en-us', defaultWine: 'proton-ge-proton9-20', ...p }), winesList: async () => [ { id: 'system', type: 'system', label: 'System Wine', version: '11.0' }, { id: 'proton-ge-proton9-20', type: 'proton', label: 'Proton GE 9.20', path: '/home/user/PLGL/files/wines/proton-ge-proton9-20' }, { id: 'wine-10.2', type: 'wine', label: 'Wine 10.2', path: '/home/user/PLGL/files/wines/wine-10.2', version: '10.2' }, { id: 'wine-old-5.0', type: 'wine', label: 'Wine 5.0', path: '/home/user/PLGL/files/wines/wine-old', version: '5.0', disabled: true } ], winesRefresh: async () => [], winesSetDisabled: async () => {}, winesSetDefault: async id => ({ ok: true, defaultWine: id }), winesDelete: async id => id === 'system' ? ({ ok: false, error: 'isSystem' }) : ({ ok: true }), winesImport: async src => ({ ok: true, path: src }), prefixesList: async () => ({ default: 'Main', prefixes: [ { name: 'Main', created: 1, locked: true }, { name: 'gaming', created: 2 } ] }), prefixesCreate: async name => ({ ok: true, name }), prefixesDelete: async n => n === 'Main' ? ({ ok: false, error: 'isMain' }) : ({ ok: true }), prefixesSetDefault: async () => ({ ok: true }), gamesList: async () => [ { id: 'g1', name: 'Cyberpunk 2077', mode: 'copy', wine: 'proton-ge-proton9-20', prefix: '', args: '--launcher-skip', env: { 'DXVK_HUD': '0' }, dllOverrides: [{ dll: 'dinput8', setting: 'native' }], workdir: '/home/user/PLGL/files/apps/Cyberpunk 2077/bin/x64', exePath: '/home/user/PLGL/files/apps/Cyberpunk 2077/bin/x64/Cyberpunk2077.exe', created: 1, lastPlayed: Date.now() - 86400000 }, { id: 'g2', name: 'Heroes of Might and Magic III', mode: 'leave', wine: 'system', prefix: 'gaming', args: '', env: {}, dllOverrides: [], workdir: '/mnt/games/HoMM3', exePath: '/mnt/games/HoMM3/h3game.exe', created: 2, lastPlayed: 0 } ], gamesGet: async () => null, gamesUpdate: async (id, patch) => patch, gamesRemove: async () => {}, gamesPickFolder: async () => '', gamesImport: async (src, mode) => ({ id: 'g9', name: 'Imported Game', mode, wine: 'system', prefix: '', args: '', env: {}, dllOverrides: [], workdir: src, exePath: src + '/game.exe', lastPlayed: 0 }), gamesRun: async () => ({ ok: true }), gamesRunTool: async () => ({ ok: true }), gamesGetLogs: async () => [], gamesIsRunning: async () => false, gamesKill: async () => ({ ok: true }), gamesListRunning: async () => [], onGamesChanged: () => {}, dialogPickFile: async () => '', shellOpenPath: async () => {}, shellShowItemInFolder: async () => {}, onImportProgress: () => {} } ` const fontCss = ` @font-face { font-family: 'Nunito'; src: url(data:font/ttf;base64,${fonts.regular}) format('truetype'); } @font-face { font-family: 'Nunito Black'; src: url(data:font/ttf;base64,${fonts.black}) format('truetype'); } ` let out = html .replace(/]*>/, '') .replace('', ``) .replace('', `\n`) fs.writeFileSync(path.join(root, 'renderer', 'dev-preview.html'), out) console.log('renderer/dev-preview.html generated')