From d78f1bf59bfb2b8ece261a37c14331ac12c77175 Mon Sep 17 00:00:00 2001 From: Matteias Collet Date: Wed, 1 Jul 2020 07:26:48 +0200 Subject: [PATCH] add code injection script --- package.json | 18 +- scripts/inject_codes.js | 12 +- site/.vuepress/components/CodeList.vue | 6 +- site/.vuepress/components/CodeOverview.vue | 41 +- site/.vuepress/components/DownloadButton.vue | 4 +- site/.vuepress/components/FormatSelect.vue | 2 +- site/.vuepress/components/Generator.vue | 7 +- site/.vuepress/components/SelectComponent.vue | 2 +- site/.vuepress/components/StageLoader.vue | 6 +- site/.vuepress/components/VersionCards.vue | 2 +- site/.vuepress/components/VersionSelect.vue | 2 +- .../components/scripts/codeFormatter.js | 8 +- site/.vuepress/data/gameVersions.json | 728 +++++++++++++++++- site/.vuepress/public/dna.js | 2 +- yarn.lock | 376 ++++++++- 15 files changed, 1097 insertions(+), 119 deletions(-) diff --git a/package.json b/package.json index 8dbe76a..43d18db 100755 --- a/package.json +++ b/package.json @@ -9,16 +9,24 @@ }, "repository": "https://github.com/BitPatty/gctGenerator/gctGenerator", "scripts": { - "dev": "vuepress dev site", - "build": "vuepress build site" + "dev": "yarn codes:inject && vuepress dev site", + "build": "yarn codes:inject && vuepress build site", + "format": "prettier --write ./site/**/*{.js,.json,.vue}", + "codes:inject": "node ./scripts/inject_codes.js && yarn format" }, "license": "Apache-2.0", "devDependencies": { - "vuepress": "^1.3.1", "@vuepress/plugin-back-to-top": "^1.3.1", - "@vuepress/plugin-medium-zoom": "^1.3.1" + "@vuepress/plugin-medium-zoom": "^1.3.1", + "jsdom": "^16.2.2", + "pre-commit": "^1.2.2", + "prettier": "^2.0.5", + "vuepress": "^1.3.1" }, "dependencies": { "vuedraggable": "^2.23.2" - } + }, + "pre-commit": [ + "format" + ] } diff --git a/scripts/inject_codes.js b/scripts/inject_codes.js index 9826a35..fb278f4 100644 --- a/scripts/inject_codes.js +++ b/scripts/inject_codes.js @@ -1,12 +1,12 @@ -import fs from 'fs'; +const fs = require('fs'); +const path = require('path'); +const jsdom = require('jsdom'); -const jsonFilePath = '../site/.vuepress/data/gameVersions.json'; +const jsonFilePath = path.join(__dirname, '../site/.vuepress/data/gameVersions.json'); const codeVersions = ['GMSE01', 'GMSJ01', 'GMSP01', 'GMSJ0A']; const parseXml = xmlString => { - const codeCollection = new DOMParser() - .parseFromString(xmlString, 'text/xml') - .getElementsByTagName('code'); + const codeCollection = new jsdom.JSDOM(xmlString).window.document.getElementsByTagName('code'); const codes = [...codeCollection]; @@ -25,7 +25,7 @@ const parseTextNode = (node, identifier) => node.getElementsByTagName(identifier const codes = JSON.parse(fs.readFileSync(jsonFilePath)); for (let i = 0; i < codeVersions.length; i++) { - const xml = fs.readFileSync(`../${codeVersions[i]}.xml`); + const xml = fs.readFileSync(path.join(__dirname, `../codes/${codeVersions[i]}.xml`)); codes.find(c => c.identifier === codeVersions[i]).codes = parseXml(xml); } diff --git a/site/.vuepress/components/CodeList.vue b/site/.vuepress/components/CodeList.vue index 65244c0..f0a6d98 100644 --- a/site/.vuepress/components/CodeList.vue +++ b/site/.vuepress/components/CodeList.vue @@ -22,7 +22,7 @@ export default { this.populate(); }, watch: { - codes: function() { + codes: function () { this.populate(); }, }, @@ -34,10 +34,10 @@ export default { methods: { toggle(code) { code.selected = !code.selected; - this.onSelectionChanged(this.availableCodes.filter(c => c.selected)); + this.onSelectionChanged(this.availableCodes.filter((c) => c.selected)); }, populate() { - this.availableCodes = this.codes.map(c => ({ ...c, selected: false })); + this.availableCodes = this.codes.map((c) => ({ ...c, selected: false })); }, inspect(code) { this.onInspect(code); diff --git a/site/.vuepress/components/CodeOverview.vue b/site/.vuepress/components/CodeOverview.vue index 22fc2f5..a279126 100644 --- a/site/.vuepress/components/CodeOverview.vue +++ b/site/.vuepress/components/CodeOverview.vue @@ -1,7 +1,5 @@ @@ -13,37 +11,16 @@ import CodeInfo from './CodeInfo'; // Data import gameVersions from '../data/gameVersions.json'; -// Util -import parseXml from './scripts/parseXml'; - -// Libs -import axios from 'axios'; - export default { props: { gameVersion: { type: String }, }, - mounted() { - if (localStorage.getItem('codes') != null) { - try { - const data = JSON.parse(localStorage.getItem('codes')).find( - c => c.identifier === this.gameVersion, - ); - if (data) { - this.codes = data.cheats.sort((a, b) => (a.title > b.title ? 1 : -1)); - console.log(this.codes); - return; - } - } catch {} - } - - axios - .get(`/codes/${this.gameVersion}.xml`) - .then(response => { - const xmlData = parseXml(response.data); - this.codes = xmlData.sort((a, b) => (a.title > b.title ? 1 : -1)); - }) - .catch(() => (this.hasError = true)); + data() { + return { + codes: gameVersions + .find((v) => v.identifier === this.gameVersion) + .codes.sort((a, b) => (a.title > b.title ? 1 : -1)), + }; }, updated() { // Scroll to anchor @@ -58,12 +35,6 @@ export default { } } }, - data() { - return { - codes: [], - hasError: false, - }; - }, }; diff --git a/site/.vuepress/components/DownloadButton.vue b/site/.vuepress/components/DownloadButton.vue index f44838f..3fd8386 100644 --- a/site/.vuepress/components/DownloadButton.vue +++ b/site/.vuepress/components/DownloadButton.vue @@ -45,7 +45,7 @@ export default { JSON.stringify({ gameVersion: this.versionIdentifier, format: this.format, - codes: c.map(code => ({ + codes: c.map((code) => ({ title: code.title, version: code.version, })), @@ -54,7 +54,7 @@ export default { } catch {} console.log(`Preparing download for ${this.format}`); - const fileName = gameVersions.find(v => v.identifier === this.versionIdentifier).version; + const fileName = gameVersions.find((v) => v.identifier === this.versionIdentifier).version; switch (this.format) { case 'gct': diff --git a/site/.vuepress/components/FormatSelect.vue b/site/.vuepress/components/FormatSelect.vue index d0a75ba..382f32d 100644 --- a/site/.vuepress/components/FormatSelect.vue +++ b/site/.vuepress/components/FormatSelect.vue @@ -21,7 +21,7 @@ export default { }, data() { return { - options: downloadFormats.map(v => ({ + options: downloadFormats.map((v) => ({ value: v.target, label: v.name, })), diff --git a/site/.vuepress/components/Generator.vue b/site/.vuepress/components/Generator.vue index e82dce1..4187923 100644 --- a/site/.vuepress/components/Generator.vue +++ b/site/.vuepress/components/Generator.vue @@ -122,9 +122,6 @@ import DownloadButton from './DownloadButton'; // Data import gameVersions from '../data/gameVersions.json'; -// Util -import parseXml from './scripts/parseXml'; - export default { data() { return { @@ -146,8 +143,8 @@ export default { onVersionChanged(e) { this.selectedVersion = e; this.selectedCheats = []; - this.codes = gameVersions.find(c => c.identifier === e).codes; - this.stageLoaderCodes = gameVersions.find(c => c.identifier === e).fastCode; + this.codes = gameVersions.find((c) => c.identifier === e).codes; + this.stageLoaderCodes = gameVersions.find((c) => c.identifier === e).fastCode; this.inspectingCode = null; }, onFormatChanged(e) { diff --git a/site/.vuepress/components/SelectComponent.vue b/site/.vuepress/components/SelectComponent.vue index 3f349a2..abf7860 100644 --- a/site/.vuepress/components/SelectComponent.vue +++ b/site/.vuepress/components/SelectComponent.vue @@ -1,6 +1,6 @@