diff --git a/components/configSwizzleManager.ts b/components/configSwizzleManager.ts index f19e82f2..cb7911f0 100644 --- a/components/configSwizzleManager.ts +++ b/components/configSwizzleManager.ts @@ -197,6 +197,9 @@ const configs: Record = { } Object.keys(configs).forEach((cfg) => { + // Parse the string into an object + configs[cfg] = JSON.parse(configs[cfg]) + const overridePath = join("overrides", `${cfg}.json`) if (existsSync(overridePath)) { diff --git a/components/controller.ts b/components/controller.ts index 09f477a4..65876b25 100644 --- a/components/controller.ts +++ b/components/controller.ts @@ -66,7 +66,9 @@ import { MenuSystemDatabase, menuSystemDatabase } from "./menus/menuSystem" import { escalationMappings } from "./contracts/escalationMappings" import { parse } from "json5" import { userAuths } from "./officialServerAuth" +// @ts-expect-error Ignore JSON import import LASTYARDBIRDSCPC from "../contractdata/SNIPER/THELASTYARDBIRD_SCPC.json" +// @ts-expect-error Ignore JSON import import LEGACYFF from "../contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json" import { missionsInLocations } from "./contracts/missionsInLocation" import { createContext, Script } from "vm" @@ -263,9 +265,10 @@ function createPeacockRequire(pluginName: string): NodeRequire { /** * Freedom Fighters for Hitman 2016 (objectives are different). */ -export const _legacyBull: MissionManifest = LEGACYFF +export const _legacyBull: MissionManifest = JSON.parse(LEGACYFF) -export const _theLastYardbirdScpc: MissionManifest = LASTYARDBIRDSCPC +export const _theLastYardbirdScpc: MissionManifest = + JSON.parse(LASTYARDBIRDSCPC) export const peacockRecentEscalations: readonly string[] = [ "35f1f534-ae2d-42be-8472-dd55e96625ea", diff --git a/contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json.d.ts b/contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json.d.ts deleted file mode 100644 index 97e42e52..00000000 --- a/contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * The Peacock Project - a HITMAN server replacement. - * Copyright (C) 2021-2022 The Peacock Project Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { MissionManifest } from "../../components/types/types" - -declare const FREEDOMFIGHTERSLEGACY: MissionManifest - -export default FREEDOMFIGHTERSLEGACY diff --git a/contractdata/SNIPER/THELASTYARDBIRD_SCPC.json.d.ts b/contractdata/SNIPER/THELASTYARDBIRD_SCPC.json.d.ts deleted file mode 100644 index 846437a5..00000000 --- a/contractdata/SNIPER/THELASTYARDBIRD_SCPC.json.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * The Peacock Project - a HITMAN server replacement. - * Copyright (C) 2021-2022 The Peacock Project Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { MissionManifest } from "../../components/types/types" - -declare const THELASTYARDBIRD_SCPC: MissionManifest - -export default THELASTYARDBIRD_SCPC diff --git a/packaging/build.mjs b/packaging/build.mjs index fd391cf2..add04a9c 100644 --- a/packaging/build.mjs +++ b/packaging/build.mjs @@ -27,6 +27,23 @@ await packContractsAndChallenges() const { version, revisionIdent } = require("../package.json") +const jsonAsCompressedTextPlugin = { + name: "jsonAsCompressedTextPlugin", + + setup(build) { + const fs = require("fs") + + build.onLoad({ filter: /\.json$/ }, async (args) => { + const text = await fs.promises.readFile(args.path) + + return { + contents: JSON.stringify(JSON.parse(text)), + loader: "text", + } + }) + }, +} + await e.build({ entryPoints: ["components/index.ts"], bundle: true, @@ -59,6 +76,7 @@ await e.build({ }, sourcemap: "external", plugins: [ + jsonAsCompressedTextPlugin, esbuildPluginLicense({ thirdParty: { output: { diff --git a/packaging/devLoader.mjs b/packaging/devLoader.mjs index 39a09d63..9213c33b 100644 --- a/packaging/devLoader.mjs +++ b/packaging/devLoader.mjs @@ -18,7 +18,8 @@ import picocolors from "picocolors" import { packContractsAndChallenges } from "./buildTasks.mjs" -import { createRequire } from "module" +import { createRequire, Module } from "module" +import { readFileSync } from "fs" // this `require` instance will be hijacked by `esbuild-register` so we can load // TS files as if they were JS in a CommonJS environment @@ -46,4 +47,12 @@ const { register } = require("esbuild-register/dist/node") register() +const resolveTextFile = function (module, path) { + const content = readFileSync(path).toString() + + module.exports = content +} + +Module._extensions[".json"] = resolveTextFile + require("../components/index.ts")