This commit is contained in:
parent
6694730b84
commit
8ea07bdbb4
1 changed files with 65 additions and 24 deletions
|
@ -1,6 +1,32 @@
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
|
|
||||||
const CONFIG_FILE = "publish.config.json";
|
// Load key value pairs from any .env like file
|
||||||
|
// const props = await getProps("gradle.properties");
|
||||||
|
|
||||||
|
// Either a path to a JSON file or an object
|
||||||
|
// const CONFIG = "publish.config.json";
|
||||||
|
const gradleProps = getProps("gradle.properties");
|
||||||
|
const CONFIG = {
|
||||||
|
"title": process.env.VER_TITTLE,
|
||||||
|
"version": "${gradleProps.version}",
|
||||||
|
"featured": false,
|
||||||
|
"releaseChannel": "dev",
|
||||||
|
"loaders": ["quilt"],
|
||||||
|
"gameVersions": {
|
||||||
|
"file": "src/main/resources/quilt.mod.json",
|
||||||
|
"key": "quilt_loader.depends.1.versions"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"primary": "build/libs/CookieServerUtils-${gradleProps.version}.jar"
|
||||||
|
},
|
||||||
|
"repoApi": "",
|
||||||
|
"gitReleaseUrl": "/releases/latest",
|
||||||
|
"crmm": {
|
||||||
|
"authToken": process.env.TOKEN,
|
||||||
|
"projectId": "cookie-server-utils"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const CRMM_API_URL = "https://api.crmm.tech/api";
|
const CRMM_API_URL = "https://api.crmm.tech/api";
|
||||||
const includeGameVersionTypes = [
|
const includeGameVersionTypes = [
|
||||||
"release",
|
"release",
|
||||||
|
@ -58,27 +84,7 @@ async function prepareMultipartFormData(data) {
|
||||||
|
|
||||||
async function loadConfigData() {
|
async function loadConfigData() {
|
||||||
console.log("Loading config...");
|
console.log("Loading config...");
|
||||||
//const config = await getConfig();
|
const config = await getConfig();
|
||||||
const config = {
|
|
||||||
"title": process.env.VER_TITTLE,
|
|
||||||
"version": "1.0.6",
|
|
||||||
"featured": false,
|
|
||||||
"releaseChannel": "dev",
|
|
||||||
"loaders": ["quilt"],
|
|
||||||
"gameVersions": {
|
|
||||||
"file": "src/main/resources/quilt.mod.json",
|
|
||||||
"key": "quilt_loader.depends.1.versions"
|
|
||||||
},
|
|
||||||
"files": {
|
|
||||||
"primary": "build/libs/CookieServerUtils-1.0.6.jar"
|
|
||||||
},
|
|
||||||
"repoApi": "",
|
|
||||||
"gitReleaseUrl": "/releases/latest",
|
|
||||||
"crmm": {
|
|
||||||
"authToken": process.env.TOKEN,
|
|
||||||
"projectId": "cookie-server-utils"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version
|
// Version
|
||||||
const version = config.version;
|
const version = config.version;
|
||||||
|
@ -168,7 +174,8 @@ async function getGameVersions(source) {
|
||||||
`Failed to get game versions from source file using key '${gameVersionSourceKey}'`,
|
`Failed to get game versions from source file using key '${gameVersionSourceKey}'`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeof gameVersions_raw === "string") gameVersions_raw = [gameVersions_raw];
|
if (typeof gameVersions_raw === "string")
|
||||||
|
gameVersions_raw = [gameVersions_raw];
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedGameVersions = new Set();
|
const parsedGameVersions = new Set();
|
||||||
|
@ -204,7 +211,11 @@ async function getVersionChangelog(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getConfig() {
|
async function getConfig() {
|
||||||
const file = await getFileContents(CONFIG_FILE, "utf-8");
|
if (typeof CONFIG !== "string") {
|
||||||
|
return CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await getFileContents(CONFIG, "utf-8");
|
||||||
const json = JSON.parse(file);
|
const json = JSON.parse(file);
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
@ -303,3 +314,33 @@ function getObjValue(obj, keys) {
|
||||||
|
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getProps(filePath) {
|
||||||
|
const file = await getFileContents(filePath, "utf-8");
|
||||||
|
if (!file) return undefined;
|
||||||
|
|
||||||
|
// Parse the .env file
|
||||||
|
const props = {};
|
||||||
|
|
||||||
|
const lines = file.split("\n");
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.startsWith("#") || !line.includes("=")) continue;
|
||||||
|
|
||||||
|
let [key, value] = line.split("=");
|
||||||
|
if (!key?.length || !value?.length) continue;
|
||||||
|
|
||||||
|
key = key.trim();
|
||||||
|
value = value.trim();
|
||||||
|
|
||||||
|
if (
|
||||||
|
value.startsWith('"') && value.endsWith('"') ||
|
||||||
|
value.startsWith("'") && value.endsWith("'")
|
||||||
|
) {
|
||||||
|
value = value.slice(1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
props[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
Loading…
Reference in a new issue