diff --git a/.forgejo/ISSUE_TEMPLATE/bug_report.md b/.forgejo/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.forgejo/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.forgejo/scripts/convert/index.mjs b/.forgejo/scripts/convert/index.mjs new file mode 100644 index 00000000..340f3f5d --- /dev/null +++ b/.forgejo/scripts/convert/index.mjs @@ -0,0 +1,41 @@ +import { readFile, writeFile } from "fs/promises"; +import { join } from "path"; +import { format } from "prettier"; + +console.time("Done"); + +console.log("Reading avatarsdatabase.css..."); +const avis = (await readFile(join("../../", "avatarsdatabase.css"), "utf8")) + .replace(/\r/g, "") + .split("\n"); + +const imageMatcher = /url\((?:'|")([^'"]+)(?:'|")\)/; +const avatarMatcher = /^\/\* Custom avatar for ([0-9]+) \*\/$/; +const badgeMatcher = /^\/\* Custom badge for (.*?) \*\/$/; + +const avatars = {}; +for (let i = 0; i < avis.length; i++) { + const l = avis[i]; + const id = l.match(avatarMatcher)?.[1]; + if (id) avatars[id] = avis[i + 2].match(imageMatcher)[1]; +} + +const badges = {}; +for (let i = 0; i < avis.length; i++) { + const l = avis[i]; + const bid = l.match(badgeMatcher)?.[1]; + if (bid) badges[bid] = avis[i + 10].match(imageMatcher)[1]; +} + +await writeFile( + join("../../", "source", "data.json"), + format( + JSON.stringify({ + avatars, + badges, + }), + { + parser: "json", + } + ) +); \ No newline at end of file diff --git a/.forgejo/scripts/generate/index.mjs b/.forgejo/scripts/generate/index.mjs new file mode 100644 index 00000000..7c03a3fe --- /dev/null +++ b/.forgejo/scripts/generate/index.mjs @@ -0,0 +1,49 @@ +import { readFile, writeFile } from "fs/promises"; +import { join } from "path"; +import UglifyCSS from "uglifycss"; + +console.time("Done"); + +const uglify = !process.argv.includes("--debug"); + +console.log("Getting templates..."); +const templateLines = ( + await readFile(join("../../", "source", "template.css"), "utf8") +) + .replace(/\r/g, "") + .split("\n"); + +const templates = { + avatar: "", +}; + +for (const id of Object.keys(templates)) { + const start = templateLines.findIndex( + (x) => x === `/* ${id.toUpperCase()}-TEMPLATE-BEGIN */` + ), + end = templateLines.findIndex( + (x) => x === `/* ${id.toUpperCase()}-TEMPLATE-END */` + ); + + if (start >= 0 && end >= 0) + templates[id] = templateLines.slice(start + 1, end).join("\n"); + else throw new Error(`Failed to get template lines for: ${id}`); +} + +console.log("Generating import.css..."); +const data = JSON.parse( + await readFile(join("../../", "source", "data.json"), "utf8") +); + +const dist = []; + +for (const [id, img] of Object.entries(data.avatars)) { + dist.push(templates.avatar.replace(/{id}/g, id).replace(/{img}/g, img)); +} + +await writeFile( + join("../../", "import.css"), + uglify ? UglifyCSS.processString(dist.join("\n")) : dist.join("\n\n") +); + +console.timeEnd("Done"); diff --git a/.forgejo/scripts/package.json b/.forgejo/scripts/package.json new file mode 100644 index 00000000..efd4914f --- /dev/null +++ b/.forgejo/scripts/package.json @@ -0,0 +1,13 @@ +{ + "name": "scripts", + "private": true, + "scripts": { + "convert": "node convert/index.mjs", + "generate": "node generate/index.mjs", + "generate:debug": "node generate/index.mjs --debug" + }, + "dependencies": { + "prettier": "^3.0.2", + "uglifycss": "^0.0.29" + } +} diff --git a/.forgejo/scripts/pnpm-lock.yaml b/.forgejo/scripts/pnpm-lock.yaml new file mode 100644 index 00000000..ffae7571 --- /dev/null +++ b/.forgejo/scripts/pnpm-lock.yaml @@ -0,0 +1,27 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +dependencies: + prettier: + specifier: ^3.0.2 + version: 3.0.2 + uglifycss: + specifier: ^0.0.29 + version: 0.0.29 + +packages: + + /prettier@3.0.2: + resolution: {integrity: sha512-o2YR9qtniXvwEZlOKbveKfDQVyqxbEIWn48Z8m3ZJjBjcCmUy3xZGIv+7AkaeuaTr6yPXJjwv07ZWlsWbEy1rQ==} + engines: {node: '>=14'} + hasBin: true + dev: false + + /uglifycss@0.0.29: + resolution: {integrity: sha512-J2SQ2QLjiknNGbNdScaNZsXgmMGI0kYNrXaDlr4obnPW9ni1jljb1NeEVWAiTgZ8z+EBWP2ozfT9vpy03rjlMQ==} + engines: {node: '>=6.4.0'} + hasBin: true + dev: false diff --git a/.forgejo/workflows/generate-db.yml b/.forgejo/workflows/generate-db.yml new file mode 100644 index 00000000..ac2eec94 --- /dev/null +++ b/.forgejo/workflows/generate-db.yml @@ -0,0 +1,55 @@ +name: Generate Database + +on: + push: + branches: + - main + paths: + - ".forgejo/workflows/generate-source.yml" + - ".forgejo/scripts/generate/**/*.*" + - "source/data.json" + - "source/template.css" + pull_request: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + generate: + runs-on: ubuntu-latest + permissions: + contents: write + # v this isn't really needed v + # strategy: + # matrix: + # retry-max: [3] # Set the maximum number of retries here + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Setup PNPM + working-directory: .forgejo/scripts + run: | + npm i -g pnpm + pnpm i + + - name: Run generate script + working-directory: .forgejo/scripts + run: pnpm run generate + + - name: Push changes + run: | + git config --global user.name "dingus" + git config --global user.email "bot@dorkbutt.lol" + + git add import.css + git commit -m "Update import.css (${{ github.sha || 'manual trigger' }})" || true + git push diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 00000000..e401aca5 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2 + with: + version: latest + + - name: Install Node.js dependencies + run: pnpm install + + - name: Build TypeScript and bundle into asar + run: pnpm run bundle + + - uses: ncipollo/release-action@v1 + with: + artifacts: "bundle/*" + makeLatest: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index fa6f7687..4b097d22 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,4 @@ dist .tern-port .parcel-cache -/bundle - -# For now, as runners are unable to be deployed on local instance. -.forgejo +/bundle \ No newline at end of file diff --git a/import.css b/import.css deleted file mode 100644 index 785e9ab8..00000000 --- a/import.css +++ /dev/null @@ -1,25 +0,0 @@ -/* Manual submission for now */ - -.avatar__183c2[src^="https://cdn.discordapp.com/avatars/862105885660676146"] -,.avatar_c19a55[src^="https://cdn.discordapp.com/avatars/862105885660676146"] -,.avatar__44b0c[src^="https://cdn.discordapp.com/avatars/862105885660676146"] -,.voiceAvatar_f910d0[src^="https://cdn.discordapp.com/avatars/862105885660676146"] -,.replyAvatar_c19a55[src^="https://cdn.discordapp.com/avatars/862105885660676146"] -,.icon__6e9f8[src^="https://cdn.discordapp.com/avatars/862105885660676146"] { - content: url("https://nomadants.net/harleyLineup-2.jpeg") -} -.userAvatar__55bab[style*="{862105885660676146}"] { - background-image: url("https://nomadants.net/harleyLineup-2.jpeg")!important -} - -.avatar__183c2[src^="https://cdn.discordapp.com/avatars/578012873813524530"] -,.avatar_c19a55[src^="https://cdn.discordapp.com/avatars/578012873813524530"] -,.avatar__44b0c[src^="https://cdn.discordapp.com/avatars/578012873813524530"] -,.voiceAvatar_f910d0[src^="https://cdn.discordapp.com/avatars/578012873813524530"] -,.replyAvatar_c19a55[src^="https://cdn.discordapp.com/avatars/578012873813524530"] -,.icon__6e9f8[src^="https://cdn.discordapp.com/avatars/578012873813524530"] { - content: url("https://nomadants.net/ezgif-581c216698e71e.gif") -} -.userAvatar__55bab[style*="{578012873813524530}"] { - background-image: url("https://nomadants.net/ezgif-581c216698e71e.gif")!important -}