diff --git a/.gitignore b/.gitignore index 8d5fc50..aba28fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ package-lock.json desktop.ini -public/assets.json +public/resources/data/assets.json public/resources/scripts/ public/sw.js public/sw-full.js diff --git a/build.ts b/build.ts index 057f593..71d307d 100644 --- a/build.ts +++ b/build.ts @@ -35,7 +35,7 @@ if (tscOutput) { } console.log(chalk.cyan('Removing old build artifacts...\n')); -await $`rm -rf ./public/resources/scripts/ ./public/assets.json ./public/sw.js ./public/sw-full.js`.quiet(); +await $`rm -rf ./public/resources/scripts/ ./public/resources/data/assets.json ./public/sw.js ./public/sw-full.js`.quiet(); console.log(chalk.cyan('Bundling TypeScript and modules...\n')); const srcFilesArr = getFiles(join(import.meta.dir, 'src')); @@ -57,7 +57,7 @@ await $`bunx javascript-obfuscator ./public/resources/scripts/ --output ./public console.log(chalk.cyan('Generating assets list...\n')); const publicDir = join(import.meta.dir, 'public'); writeFileSync( - join(publicDir, 'assets.json'), + join(publicDir, 'resources/data/assets.json'), JSON.stringify( getFiles(publicDir).map((asset) => { return asset.replace(new RegExp(`^${publicDir}`), '').replace(/\/index\.html$/, '/'); diff --git a/build_fast.ts b/build_fast.ts index f9c4845..275721f 100644 --- a/build_fast.ts +++ b/build_fast.ts @@ -19,7 +19,7 @@ function getFiles(baseDir: string, dir?: string, filesArr?: string[]) { } console.log(chalk.cyan('Removing old build artifacts...\n')); -await $`rm -rf ./public/resources/scripts/ ./public/assets.json ./public/sw.js ./public/sw-full.js`.quiet(); +await $`rm -rf ./public/resources/scripts/ ./public/resources/data/assets.json ./public/sw.js ./public/sw-full.js`.quiet(); console.log(chalk.cyan('Bundling TypeScript and modules...\n')); const srcFilesArr = getFiles(join(import.meta.dir, 'src')); @@ -38,7 +38,7 @@ await build({ console.log(chalk.cyan('Generating assets list...\n')); const publicDir = join(import.meta.dir, 'public'); writeFileSync( - join(publicDir, 'assets.json'), + join(publicDir, 'resources/data/assets.json'), JSON.stringify( getFiles(publicDir).map((asset) => { return asset.replace(new RegExp(`^${publicDir}`), '').replace(/\/index\.html$/, '/'); diff --git a/public/resources/data.json b/public/resources/data/main.json similarity index 100% rename from public/resources/data.json rename to public/resources/data/main.json diff --git a/src/resources/scripts/main.ts b/src/resources/scripts/main.ts index 034bb81..f71684d 100644 --- a/src/resources/scripts/main.ts +++ b/src/resources/scripts/main.ts @@ -376,7 +376,7 @@ if (window.location.pathname === '/') { const titleBarText = document.getElementById('title-bar-text'); const lastVersion = storage.local.get('lastVersion'); - const updateData = (await (await fetch('/resources/data.json')).json()).updates; + const updateData = (await (await fetch('/resources/data/main.json')).json()).updates; const currentVersion = updateData[0].version; const changelog = updateData[0].changelog.map((change: string) => ` - ${change}`).join('\n'); @@ -417,7 +417,7 @@ if (window.location.pathname === '/settings/') { const themeSelect = document.getElementById('theme-select') as HTMLSelectElement; // const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement; // const adsCheckbox = document.getElementById('ads-checkbox') as HTMLInputElement; - const themeData: { id: string; name: string }[] = (await (await fetch('/resources/data.json')).json()).themes; + const themeData: { id: string; name: string }[] = (await (await fetch('/resources/data/main.json')).json()).themes; themeData.forEach((theme: { id: string; name: string }) => { const option = document.createElement('option'); @@ -467,7 +467,7 @@ if (window.location.pathname === '/settings/') { const usernameInput = document.getElementById('username-input') as HTMLInputElement; const themeSelect = document.getElementById('theme-select') as HTMLSelectElement; // const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement; - const themeData: { id: string; name: string }[] = (await (await fetch('/resources/data.json')).json()).themes; + const themeData: { id: string; name: string }[] = (await (await fetch('/resources/data/main.json')).json()).themes; themeData.forEach((theme: { id: string; name: string }) => { const option = document.createElement('option'); @@ -500,7 +500,7 @@ if (window.location.pathname === '/settings/') { // storage.local.set('offlineCache', offlineCheckbox.checked); storage.local.set('showAds', true); storage.local.set('mods', []); - storage.local.set('lastVersion', (await (await fetch('/resources/data.json')).json()).updates[0].version); + storage.local.set('lastVersion', (await (await fetch('/resources/data/main.json')).json()).updates[0].version); /* if (offlineCheckbox.checked) { sw.register('/sw-full.js'); @@ -520,7 +520,7 @@ if (window.location.pathname === '/settings/') { } else if (window.location.pathname === '/mods/mods/' || window.location.pathname === '/mods/resourcepacks/') { document.addEventListener('DOMContentLoaded', async () => { const addonType: 'mods' | 'resourcepacks' = window.location.pathname === '/mods/mods/' ? 'mods' : 'resourcepacks'; - const addonData: { id: string; name: string; description: string; author: string; authorLink: string; source: string }[] = (await (await fetch('/resources/data.json')).json()).addons; + const addonData: { id: string; name: string; description: string; author: string; authorLink: string; source: string }[] = (await (await fetch('/resources/data/main.json')).json()).addons; const modList = document.querySelector('.mod-list'); // @ts-expect-error addonData[addonType].forEach((addon) => { @@ -551,7 +551,7 @@ if (window.location.pathname === '/settings/') { } else if (window.location.pathname === '/updates/') { document.addEventListener('DOMContentLoaded', async () => { const updatesContainer = document.getElementById('updates-container'); - const updateData: { version: string; changelog: string[] }[] = (await (await fetch('/resources/data.json')).json()).updates; + const updateData: { version: string; changelog: string[] }[] = (await (await fetch('/resources/data/main.json')).json()).updates; updateData.forEach((update) => { const versionHeader = document.createElement('strong'); versionHeader.textContent = `MineXLauncher ${update.version}`; diff --git a/src/sw-full.ts b/src/sw-full.ts index 12b34e5..3ebed3d 100644 --- a/src/sw-full.ts +++ b/src/sw-full.ts @@ -5,7 +5,7 @@ const cacheName = `minexlauncher-full-v${cacheVersion}`; self.addEventListener('install', (event) => { event.waitUntil( caches.open(cacheName).then(async (cache) => { - const response = await fetch('/assets.json'); + const response = await fetch('/resources/data/assets.json'); const cacheAssets = await response.json(); const totalAssets = cacheAssets.length; let cachedAssets = 0;