diff --git a/build/post-build.js b/build/post-build.js new file mode 100644 index 000000000..713c9ce02 --- /dev/null +++ b/build/post-build.js @@ -0,0 +1,17 @@ +const fs = require("fs"); +const path = require("path"); +const proc = require("child_process"); + +function executeCommand(command) { + return proc.execSync(command).toString().trim(); +} + +const commit = { + sha: executeCommand("git rev-parse HEAD"), + message: executeCommand("git log -1 --pretty=%B"), + author: executeCommand("git log -1 --pretty=format:%an") +}; + +const json = JSON.stringify(commit); + +fs.writeFileSync(path.resolve(__dirname, "../dist/commit.json"), json); diff --git a/javascripts/game.js b/javascripts/game.js index d14bf6295..8d4b02151 100644 --- a/javascripts/game.js +++ b/javascripts/game.js @@ -1,4 +1,3 @@ -import { isLocalEnvironment } from "./core/devtools.js"; import { playFabLogin } from "./core/playfab.js"; import { DC } from "./core/constants.js"; @@ -245,36 +244,6 @@ export function gainedInfinities() { return infGain; } -// TODO: remove before release -if (!isLocalEnvironment()) { - let commit; - setInterval(() => { - const url = "https://api.github.com/repos/IvarK/IToughtAboutCurseWordsButThatWouldBeMeanToOmsi/commits/master"; - const headers = new Headers(); - // Yes, this is my GitHub API key for reading private repo details - headers.append("Authorization", `Basic ${btoa("WaitingIdly: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")}`); - - fetch(url, { method: "GET", headers }) - .then(response => response.json()) - .then(json => { - if (commit === undefined) { - commit = json.sha; - return; - } - if (commit === json.sha) return; - // GH Pages need some time to get rebuilt, so show message after 60 seconds - setTimeout(() => { - Modal.message.show( - "Refresh the page (game will be saved), we've got new stuff: " + - `"${json.commit.message}" by ${json.author.login}`, - updateRefresh, - true - ); - }, 60000); - }); - }, 60000); -} - export function updateRefresh() { GameStorage.save(true); location.reload(true); diff --git a/package.json b/package.json index d8fa55cc1..f18b7d17a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "scripts": { "serve": "vue-cli-service serve", - "build": "vue-cli-service build", + "build": "vue-cli-service build && node build/post-build.js", "lint": "vue-cli-service lint" }, "dependencies": { diff --git a/src/commit-watcher.js b/src/commit-watcher.js new file mode 100644 index 000000000..126d04159 --- /dev/null +++ b/src/commit-watcher.js @@ -0,0 +1,32 @@ +// TODO: remove before release +export function watchLatestCommit() { + if (isLocalEnvironment()) { + return; + } + + const url = "commit.json"; + let current; + + function watch() { + fetch(url, { method: "GET" }) + .then(response => response.json()) + .then(json => { + if (json === undefined) { + return; + } + current = current ?? json.sha; + if (current === json.sha) { + return; + } + + Modal.message.show( + "Refresh the page (game will be saved), we've got new stuff: " + + `"${json.message}" by ${json.author}`, + updateRefresh, + true + ); + }); + } + + setInterval(watch, 60000); +} diff --git a/src/main.js b/src/main.js index 7660b46a8..426f388fb 100644 --- a/src/main.js +++ b/src/main.js @@ -1,47 +1,6 @@ -function mergeIntoGlobal(object) { - for (const key in object) { - const value = object[key]; - const existingValue = window[key]; - if (existingValue !== undefined) { - throw `Property ${key} already exists in global context`; - } +import "./merge-globals"; +import { init } from "../javascripts/game"; +import { watchLatestCommit } from "@/commit-watcher"; - window[key] = value; - } -} - -import * as Utils from "../javascripts/core/utils.js"; -mergeIntoGlobal(Utils); - -import "../javascripts/components"; - -import * as GameDB from "../javascripts/core/secret-formula"; -mergeIntoGlobal(GameDB); - -// Start of bullshit - -// Hevi, why -import * as AutomatorBlockEditor from "../javascripts/components/reality/automator/automator-block-editor.js"; -mergeIntoGlobal(AutomatorBlockEditor); - -// Hevi, whyy -import * as AutomatorBlocks from "../javascripts/components/reality/automator/automator-blocks.js"; -mergeIntoGlobal(AutomatorBlocks); - -// Garnet, nooo -import * as AutomatorTextEditor from "../javascripts/components/reality/automator/automator-text-editor.js"; -mergeIntoGlobal(AutomatorTextEditor); - -// Spec, reeee -import * as PerksTab from "../javascripts/components/reality/perks-tab.js"; -mergeIntoGlobal(PerksTab); - -// End of bullshit - -import * as core from "../javascripts/core/globals.js"; -mergeIntoGlobal(core); - -import * as game from "../javascripts/game.js"; -mergeIntoGlobal(game); - -game.init(); +init(); +watchLatestCommit(); diff --git a/src/merge-globals.js b/src/merge-globals.js new file mode 100644 index 000000000..212b15bb3 --- /dev/null +++ b/src/merge-globals.js @@ -0,0 +1,45 @@ +function mergeIntoGlobal(object) { + for (const key in object) { + const value = object[key]; + const existingValue = window[key]; + if (existingValue !== undefined) { + throw `Property ${key} already exists in global context`; + } + + window[key] = value; + } +} + +import * as Utils from "../javascripts/core/utils"; +mergeIntoGlobal(Utils); + +import "../javascripts/components"; + +import * as GameDB from "../javascripts/core/secret-formula"; +mergeIntoGlobal(GameDB); + +// Start of bullshit + +// Hevi, why +import * as AutomatorBlockEditor from "../javascripts/components/reality/automator/automator-block-editor"; +mergeIntoGlobal(AutomatorBlockEditor); + +// Hevi, whyy +import * as AutomatorBlocks from "../javascripts/components/reality/automator/automator-blocks"; +mergeIntoGlobal(AutomatorBlocks); + +// Garnet, nooo +import * as AutomatorTextEditor from "../javascripts/components/reality/automator/automator-text-editor"; +mergeIntoGlobal(AutomatorTextEditor); + +// Spec, reeee +import * as PerksTab from "../javascripts/components/reality/perks-tab"; +mergeIntoGlobal(PerksTab); + +// End of bullshit + +import * as core from "../javascripts/core/globals"; +mergeIntoGlobal(core); + +import * as game from "../javascripts/game"; +mergeIntoGlobal(game);