diff --git a/.github/workflows/biome.yml b/.github/workflows/biome.yml new file mode 100644 index 0000000..04f83bc --- /dev/null +++ b/.github/workflows/biome.yml @@ -0,0 +1,11 @@ +name: Linter & Formatter Check +on: push +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install modules + run: npm ci + - name: Run Biome + run: npx biome check . \ No newline at end of file diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..d599ea0 --- /dev/null +++ b/biome.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "ignore": ["SteamTracking", "GameTracking-SteamVR/"] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 150 + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "complexity": { + "noForEach": "off" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + } +} diff --git a/dump_javascript_paths.mjs b/dump_javascript_paths.mjs index b63e9ca..fb512a9 100644 --- a/dump_javascript_paths.mjs +++ b/dump_javascript_paths.mjs @@ -1,17 +1,11 @@ /* Based on https://github.com/SteamDatabase/SteamTracking/blob/master/dump_javascript_paths.mjs Thanks xPaw! */ -import { resolve as pathResolve } from "path"; -import { readdir as readDir } from "fs/promises"; +import { readdir as readDir } from "node:fs/promises"; +import { resolve as pathResolve } from "node:path"; -const pathsToRecurse = [ - "./SteamTracking/", - "./GameTracking-SteamVR/", -]; +const pathsToRecurse = ["./SteamTracking/", "./GameTracking-SteamVR/"]; -const blocklist = [ - "licenses.js", - "steamaudio.js", -]; +const blocklist = ["licenses.js", "steamaudio.js"]; async function* GetRecursiveJavascriptCssFiles(dir) { const dirents = await readDir(dir, { withFileTypes: true }); diff --git a/find_svg.mjs b/find_svg.mjs index f3c8ae3..b8a177c 100644 --- a/find_svg.mjs +++ b/find_svg.mjs @@ -1,11 +1,11 @@ -import {basename, sep as pathSep } from "path"; -import { readFile } from "fs/promises"; -import { createWriteStream, existsSync, mkdirSync, rmSync } from "fs"; import { createHash } from "node:crypto"; -import { parse, latestEcmaVersion } from "espree"; -import { traverse, Syntax } from "estraverse"; -import { GetRecursiveFilesToParse } from "./dump_javascript_paths.mjs"; +import { createWriteStream, existsSync, mkdirSync, rmSync } from "node:fs"; +import { readFile } from "node:fs/promises"; +import { basename, sep as pathSep } from "node:path"; +import { latestEcmaVersion, parse } from "espree"; +import { Syntax, traverse } from "estraverse"; import { create } from "xmlbuilder2"; +import { GetRecursiveFilesToParse } from "./dump_javascript_paths.mjs"; const svgOutputPath = "./svgs"; const pngOutputPath = "./pngs"; @@ -18,7 +18,7 @@ if (existsSync(pngOutputPath)) { rmSync(pngOutputPath, { recursive: true }); } -const base64PngPattern = RegExp("data:image/png;base64,([A-Za-z0-9+/=]+)", "g"); +const base64PngPattern = /data:image\/png;base64,([A-Za-z0-9+\/=]+)/g; for await (const file of GetRecursiveFilesToParse()) { try { @@ -26,80 +26,73 @@ for await (const file of GetRecursiveFilesToParse()) { const code = await readFile(file, "utf8"); - const file_basename = basename(file, '.js'); + const file_basename = basename(file, ".js"); - if ( file.endsWith('.js') ) { + if (file.endsWith(".js")) { console.log("Looking for svgs"); const ast = parse(code, { ecmaVersion: latestEcmaVersion, loc: true }); let last_function_seen = null; - // output folder / resource folder / file name - const outputFolder = `${svgOutputPath}/${file.replace(process.cwd(), '').split(pathSep)[1]}/${file_basename}`; - if (!existsSync(outputFolder)) - mkdirSync(outputFolder, { recursive: true }); + const outputFolder = `${svgOutputPath}/${file.replace(process.cwd(), "").split(pathSep)[1]}/${file_basename}`; + if (!existsSync(outputFolder)) mkdirSync(outputFolder, { recursive: true }); traverse(ast, { enter: function (node) { - if(node.type === Syntax.FunctionDeclaration) { + if (node.type === Syntax.FunctionDeclaration) { last_function_seen = node; } - - if (node.type === Syntax.CallExpression && node.callee?.property?.name === 'createElement' && node.arguments?.[0]?.value === 'svg') { + + if (node.type === Syntax.CallExpression && node.callee?.property?.name === "createElement" && node.arguments?.[0]?.value === "svg") { // as i understand it we don't want to go deeper if it's an svg (bc there can be svg in svg but we're only interested in the one most "outside") this.skip(); - const svg = (createSvgBody(node)).end({ prettyPrint: true }); - const hash = createHash('sha1').update(svg).digest('hex').substring(0,16); + const svg = createSvgBody(node).end({ prettyPrint: true }); + const hash = createHash("sha1").update(svg).digest("hex").substring(0, 16); console.debug(`Hash ${hash} from ${file} line ${node.loc.start.line} col ${node.loc.start.column}`); OutputToFile(`${outputFolder}/${last_function_seen?.id.name ?? "null"}_${hash}.svg`, `${svg}\n`); - }} + } + }, }); } - console.log("Looking for pngs") + console.log("Looking for pngs"); // output folder / resource folder / file name - const outputFolder = `${pngOutputPath}/${file.replace(process.cwd(), '').split(pathSep)[1]}/${file_basename}`; - if (!existsSync(outputFolder)) - mkdirSync(outputFolder, { recursive: true }); - + const outputFolder = `${pngOutputPath}/${file.replace(process.cwd(), "").split(pathSep)[1]}/${file_basename}`; + if (!existsSync(outputFolder)) mkdirSync(outputFolder, { recursive: true }); + const result = code.matchAll(base64PngPattern); for (const match of result) { const png = Buffer.from(match[1], "base64"); - const hash = createHash('sha1').update(png).digest('hex').substring(0,16); + const hash = createHash("sha1").update(png).digest("hex").substring(0, 16); console.debug(`Hash ${hash} from ${file}`); OutputToFile(`${outputFolder}/${hash}.png`, png); } - } catch (e) { console.error(`::error::Unable to parse "${file}":`, e); - continue; } finally { console.log("::endgroup::"); } } -function createSvgBody(node, xml = undefined) { - if (!xml) { - xml = create(); - } +function createSvgBody(node, xml = create()) { if (!node) { return xml; } try { const elem = xml.ele(node.arguments[0].value); node.arguments[1].properties?.forEach((prop) => { - if (prop.type === 'SpreadElement' || prop.key.name === 'className') return; - elem.att(fixSVGKeyName(prop.key) , prop.value.value); - }) + if (prop.type === "SpreadElement" || prop.key.name === "className") return; + elem.att(fixSVGKeyName(prop.key), prop.value.value); + }); node.arguments.slice(2)?.forEach((prop) => { - if (prop.type === 'CallExpression') { + if (prop.type === "CallExpression") { createSvgBody(prop, elem); } }); } catch (e) { - console.warn("::warning::probably some vars that i can do nothing about",e); + console.warn("::warning::probably some vars that i can do nothing about", e); } return xml; } diff --git a/package-lock.json b/package-lock.json index 0e3e824..259ad84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,173 @@ "espree": "^10.1.0", "estraverse": "github:Lifeismana/estraverse#static-block", "xmlbuilder2": "^3.1.1" + }, + "devDependencies": { + "@biomejs/biome": "1.9.4" + } + }, + "node_modules/@biomejs/biome": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.9.4.tgz", + "integrity": "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==", + "dev": true, + "hasInstallScript": true, + "license": "MIT OR Apache-2.0", + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.9.4", + "@biomejs/cli-darwin-x64": "1.9.4", + "@biomejs/cli-linux-arm64": "1.9.4", + "@biomejs/cli-linux-arm64-musl": "1.9.4", + "@biomejs/cli-linux-x64": "1.9.4", + "@biomejs/cli-linux-x64-musl": "1.9.4", + "@biomejs/cli-win32-arm64": "1.9.4", + "@biomejs/cli-win32-x64": "1.9.4" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.9.4.tgz", + "integrity": "sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.9.4.tgz", + "integrity": "sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.9.4.tgz", + "integrity": "sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.9.4.tgz", + "integrity": "sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.9.4.tgz", + "integrity": "sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.9.4.tgz", + "integrity": "sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.9.4.tgz", + "integrity": "sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.9.4.tgz", + "integrity": "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" } }, "node_modules/@oozcitak/dom": { diff --git a/package.json b/package.json index 5ad4a64..30793ed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,10 @@ { - "dependencies": { - "espree": "^10.1.0", - "estraverse": "github:Lifeismana/estraverse#static-block", - "xmlbuilder2": "^3.1.1" - } + "dependencies": { + "espree": "^10.1.0", + "estraverse": "github:Lifeismana/estraverse#static-block", + "xmlbuilder2": "^3.1.1" + }, + "devDependencies": { + "@biomejs/biome": "1.9.4" + } } diff --git a/renovate.json b/renovate.json index 5db72dd..ac08426 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,4 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:recommended" - ] + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:recommended"] } diff --git a/update.sh b/update.sh index fa81164..2e10d43 100755 --- a/update.sh +++ b/update.sh @@ -11,7 +11,7 @@ UpdateSvg() { elif [ -n "$changes" -o -n "$new" ]; then echo "Changes detected" git add -A - git commit -S -a -m "$(git status --porcelain | wc -l) svgs | $(git status --porcelain|awk '{print "basename " $2}'| sh | sed '{:q;N;s/\n/, /g;t q}')" + git commit -S -a -m "$(git status --porcelain | wc -l) files | $(git status --porcelain|awk '{print "basename " $2}'| sh | sed '{:q;N;s/\n/, /g;t q}')" git push else echo "No changes detected"