1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-22 22:12:45 +01:00

Changed importing .json as text instead for performance reasons (#40)

This commit is contained in:
Lennard Fonteijn 2022-11-25 21:18:03 +01:00 committed by GitHub
parent b44774d971
commit c37241210a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 49 deletions

View File

@ -197,6 +197,9 @@ const configs: Record<string, unknown> = {
} }
Object.keys(configs).forEach((cfg) => { Object.keys(configs).forEach((cfg) => {
// Parse the string into an object
configs[cfg] = JSON.parse(configs[cfg])
const overridePath = join("overrides", `${cfg}.json`) const overridePath = join("overrides", `${cfg}.json`)
if (existsSync(overridePath)) { if (existsSync(overridePath)) {

View File

@ -66,7 +66,9 @@ import { MenuSystemDatabase, menuSystemDatabase } from "./menus/menuSystem"
import { escalationMappings } from "./contracts/escalationMappings" import { escalationMappings } from "./contracts/escalationMappings"
import { parse } from "json5" import { parse } from "json5"
import { userAuths } from "./officialServerAuth" import { userAuths } from "./officialServerAuth"
// @ts-expect-error Ignore JSON import
import LASTYARDBIRDSCPC from "../contractdata/SNIPER/THELASTYARDBIRD_SCPC.json" import LASTYARDBIRDSCPC from "../contractdata/SNIPER/THELASTYARDBIRD_SCPC.json"
// @ts-expect-error Ignore JSON import
import LEGACYFF from "../contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json" import LEGACYFF from "../contractdata/COLORADO/FREEDOMFIGHTERSLEGACY.json"
import { missionsInLocations } from "./contracts/missionsInLocation" import { missionsInLocations } from "./contracts/missionsInLocation"
import { createContext, Script } from "vm" import { createContext, Script } from "vm"
@ -263,9 +265,10 @@ function createPeacockRequire(pluginName: string): NodeRequire {
/** /**
* Freedom Fighters for Hitman 2016 (objectives are different). * 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[] = [ export const peacockRecentEscalations: readonly string[] = [
"35f1f534-ae2d-42be-8472-dd55e96625ea", "35f1f534-ae2d-42be-8472-dd55e96625ea",

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
import { MissionManifest } from "../../components/types/types"
declare const FREEDOMFIGHTERSLEGACY: MissionManifest
export default FREEDOMFIGHTERSLEGACY

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
import { MissionManifest } from "../../components/types/types"
declare const THELASTYARDBIRD_SCPC: MissionManifest
export default THELASTYARDBIRD_SCPC

View File

@ -27,6 +27,23 @@ await packContractsAndChallenges()
const { version, revisionIdent } = require("../package.json") 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({ await e.build({
entryPoints: ["components/index.ts"], entryPoints: ["components/index.ts"],
bundle: true, bundle: true,
@ -59,6 +76,7 @@ await e.build({
}, },
sourcemap: "external", sourcemap: "external",
plugins: [ plugins: [
jsonAsCompressedTextPlugin,
esbuildPluginLicense({ esbuildPluginLicense({
thirdParty: { thirdParty: {
output: { output: {

View File

@ -18,7 +18,8 @@
import picocolors from "picocolors" import picocolors from "picocolors"
import { packContractsAndChallenges } from "./buildTasks.mjs" 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 // this `require` instance will be hijacked by `esbuild-register` so we can load
// TS files as if they were JS in a CommonJS environment // TS files as if they were JS in a CommonJS environment
@ -46,4 +47,12 @@ const { register } = require("esbuild-register/dist/node")
register() register()
const resolveTextFile = function (module, path) {
const content = readFileSync(path).toString()
module.exports = content
}
Module._extensions[".json"] = resolveTextFile
require("../components/index.ts") require("../components/index.ts")