minor reordering while thinking how to progress and where to start
This commit is contained in:
@@ -11,7 +11,7 @@ export const auth = betterAuth({
|
|||||||
socialProviders: {
|
socialProviders: {
|
||||||
microsoft: {
|
microsoft: {
|
||||||
clientId: process.env.MICROSOFT_CLIENT_ID as string,
|
clientId: process.env.MICROSOFT_CLIENT_ID as string,
|
||||||
clientSecret: process.env.MICROSOFT_CLIENT_SECRET as string,
|
clientSecret: process.env.MICROSOFT_CLIENT_SECRET as string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { spawn, $, write, file } from 'bun';
|
import { spawn, $, write, file } from 'bun';
|
||||||
import { join } from 'path';
|
import { join } from 'node:path';
|
||||||
|
import { stringifyYAML } from '../stringify-yaml';
|
||||||
|
|
||||||
declare namespace Bun {
|
declare namespace Bun {
|
||||||
export const YAML: {
|
export const YAML: {
|
||||||
@@ -10,7 +11,7 @@ declare namespace Bun {
|
|||||||
interface MinecraftEnvironment {
|
interface MinecraftEnvironment {
|
||||||
EULA: string;
|
EULA: string;
|
||||||
VERSION?: string;
|
VERSION?: string;
|
||||||
TYPE?: 'VANILLA' | 'FORGE' | 'FABRIC' | 'PAPER' | 'SPIGOT' | 'BUKKIT' | 'PURPUR' | 'MODDED';
|
TYPE?: ;
|
||||||
DIFFICULTY?: 'PEACEFUL' | 'EASY' | 'NORMAL' | 'HARD';
|
DIFFICULTY?: 'PEACEFUL' | 'EASY' | 'NORMAL' | 'HARD';
|
||||||
MODE?: 'SURVIVAL' | 'CREATIVE' | 'ADVENTURE' | 'SPECTATOR';
|
MODE?: 'SURVIVAL' | 'CREATIVE' | 'ADVENTURE' | 'SPECTATOR';
|
||||||
MAX_PLAYERS?: string;
|
MAX_PLAYERS?: string;
|
||||||
@@ -41,50 +42,6 @@ interface MinecraftService {
|
|||||||
restart?: 'unless-stopped' | 'no';
|
restart?: 'unless-stopped' | 'no';
|
||||||
networks?: string[];
|
networks?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// simple YAML stringifier for basic objects
|
|
||||||
function stringifyYAML(obj: any, indent = 0): string {
|
|
||||||
const spaces = ' '.repeat(indent);
|
|
||||||
|
|
||||||
if (obj === null || obj === undefined) {
|
|
||||||
return 'null';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof obj === 'string') {
|
|
||||||
// handle strings that need quoting
|
|
||||||
if (obj.includes(':') || obj.includes('\n') || obj.includes('#')) {
|
|
||||||
return `"${obj.replace(/"/g, '\\"')}"`;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
|
||||||
return String(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
if (obj.length === 0) return '[]';
|
|
||||||
return obj.map((item) => `${spaces}- ${stringifyYAML(item, indent + 2)}`).join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof obj === 'object') {
|
|
||||||
const entries = Object.entries(obj);
|
|
||||||
if (entries.length === 0) return '{}';
|
|
||||||
|
|
||||||
return entries
|
|
||||||
.map(([key, value]) => {
|
|
||||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
||||||
return `${spaces}${key}:\n${stringifyYAML(value, indent + 2)}`;
|
|
||||||
} else {
|
|
||||||
return `${spaces}${key}: ${stringifyYAML(value, 0)}`;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// minimal Minecraft docker-compose template
|
// minimal Minecraft docker-compose template
|
||||||
const baseTemplate: { services: { mc: MinecraftService } } = {
|
const baseTemplate: { services: { mc: MinecraftService } } = {
|
||||||
services: {
|
services: {
|
||||||
@@ -96,7 +53,7 @@ const baseTemplate: { services: { mc: MinecraftService } } = {
|
|||||||
ports: ['25565:25565'],
|
ports: ['25565:25565'],
|
||||||
environment: {
|
environment: {
|
||||||
EULA: 'TRUE',
|
EULA: 'TRUE',
|
||||||
TYPE: 'PAPER',
|
TYPE: 'LEAF',
|
||||||
ENABLE_WHITELIST: 'true',
|
ENABLE_WHITELIST: 'true',
|
||||||
WHITELIST: 'f396e2b9-cbb1-46a0-bb72-96898a1ca44d',
|
WHITELIST: 'f396e2b9-cbb1-46a0-bb72-96898a1ca44d',
|
||||||
DIFFICULTY: 'NORMAL',
|
DIFFICULTY: 'NORMAL',
|
||||||
@@ -176,13 +133,13 @@ class ProjectManager {
|
|||||||
await $`rm -rf ${cwd}`;
|
await $`rm -rf ${cwd}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async runCompose(name: string, args: string[]) {
|
runCompose(name: string, args: string[]) {
|
||||||
const cwd = this.projectPath(name);
|
const cwd = this.projectPath(name);
|
||||||
const result = await spawn(['docker', 'compose', ...args], { cwd });
|
const result = spawn(['docker', 'compose', ...args], { cwd });
|
||||||
return result.exited;
|
return result.exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
async attach(name: string) {
|
attach(name: string) {
|
||||||
const cwd = this.projectPath(name);
|
const cwd = this.projectPath(name);
|
||||||
|
|
||||||
const process = spawn(['docker', 'exec', '-i', 'minecraft', 'rcon-cli'], {
|
const process = spawn(['docker', 'exec', '-i', 'minecraft', 'rcon-cli'], {
|
||||||
@@ -215,11 +172,11 @@ class ProjectManager {
|
|||||||
const ansiRegex = /\x1b\[([0-9;]+)m/g;
|
const ansiRegex = /\x1b\[([0-9;]+)m/g;
|
||||||
const chunks: any[] = [];
|
const chunks: any[] = [];
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match;
|
let match: RegExpExecArray | null = ansiRegex.exec(text);
|
||||||
let currentColor: string | undefined;
|
let currentColor: string | undefined;
|
||||||
let currentBold = false;
|
let currentBold = false;
|
||||||
|
|
||||||
while ((match = ansiRegex.exec(text)) !== null) {
|
while (match !== null) {
|
||||||
if (match.index > lastIndex) {
|
if (match.index > lastIndex) {
|
||||||
const textChunk = text.substring(lastIndex, match.index);
|
const textChunk = text.substring(lastIndex, match.index);
|
||||||
chunks.push({
|
chunks.push({
|
||||||
@@ -243,6 +200,7 @@ class ProjectManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastIndex = ansiRegex.lastIndex;
|
lastIndex = ansiRegex.lastIndex;
|
||||||
|
match = ansiRegex.exec(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastIndex < text.length) {
|
if (lastIndex < text.length) {
|
||||||
@@ -325,7 +283,7 @@ class ProjectManager {
|
|||||||
const writer = {
|
const writer = {
|
||||||
async write(text: string) {
|
async write(text: string) {
|
||||||
if (process.stdin) {
|
if (process.stdin) {
|
||||||
await process.stdin.write(text);
|
process.stdin.write(text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async close() {
|
async close() {
|
||||||
41
app/src/lib/api/utils/stringify-yaml.ts
Normal file
41
app/src/lib/api/utils/stringify-yaml.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
export function stringifyYAML(obj: any, indent = 0): string {
|
||||||
|
const spaces = ' '.repeat(indent);
|
||||||
|
|
||||||
|
if (obj === null || obj === undefined) {
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof obj === 'string') {
|
||||||
|
// handle strings that need quoting
|
||||||
|
if (obj.includes(':') || obj.includes('\n') || obj.includes('#')) {
|
||||||
|
return `"${obj.replace(/"/g, '\\"')}"`;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
||||||
|
return String(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
if (obj.length === 0) return '[]';
|
||||||
|
return obj.map((item) => `${spaces}- ${stringifyYAML(item, indent + 2)}`).join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof obj === 'object') {
|
||||||
|
const entries = Object.entries(obj);
|
||||||
|
if (entries.length === 0) return '{}';
|
||||||
|
|
||||||
|
return entries
|
||||||
|
.map(([key, value]) => {
|
||||||
|
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||||
|
return `${spaces}${key}:\n${stringifyYAML(value, indent + 2)}`;
|
||||||
|
} else {
|
||||||
|
return `${spaces}${key}: ${stringifyYAML(value, 0)}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(obj);
|
||||||
|
}
|
||||||
17
app/src/lib/types/mcservetype.type.ts
Normal file
17
app/src/lib/types/mcservetype.type.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
type McServerType =
|
||||||
|
| 'VANILLA'
|
||||||
|
| 'NEOFORGE'
|
||||||
|
| 'FORGE'
|
||||||
|
| 'FABRIC'
|
||||||
|
| 'PAPER'
|
||||||
|
| 'LEAF'
|
||||||
|
| 'SPIGOT'
|
||||||
|
| 'CANYON'
|
||||||
|
| 'PURPUR'
|
||||||
|
| 'MAGMA'
|
||||||
|
| 'MAGMA_MAINTAINED'
|
||||||
|
| 'KETTING'
|
||||||
|
| 'MOHIST'
|
||||||
|
| 'YOUER'
|
||||||
|
| 'BANNER'
|
||||||
|
| 'CATSERVER';
|
||||||
Reference in New Issue
Block a user