2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-12-01 08:47:48 +00:00

chore: modman inital setup

This commit is contained in:
Jan Laupetin
2025-10-01 23:35:37 +01:00
parent ec7475c6e1
commit cf2bb15ce9
27 changed files with 7856 additions and 4 deletions

24
src/ModManUi/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -0,0 +1 @@
src-tauri

View File

@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"printWidth": 100
}

View File

@@ -0,0 +1,151 @@
import type { Plugin, ViteDevServer } from "vite";
import type { OutputOptions, OutputBundle, OutputAsset, OutputChunk } from "rollup";
import { createHmac } from "node:crypto";
import path from "node:path";
import fs from "node:fs";
function createTransformedTextSource2(varName: string, previousSource: string) {
const hash = createHmac("sha256", previousSource);
const digest = hash.digest("hex").substring(0, 16);
return `#pragma once
static inline const char* ${varName} = R"${digest}(${previousSource})${digest}";
`;
}
function createTransformedTextSource(varName: string, previousSource: string) {
const str = [...previousSource].map((v) => `0x${v.charCodeAt(0).toString(16).padStart(2, "0")}`).join(", ");
return `#pragma once
static inline const unsigned char ${varName}[] {
${str}
};
`;
}
function createVarName(fileName: string) {
return fileName.replaceAll(".", "_").toUpperCase();
}
function transformAsset(asset: OutputAsset) {
const varName = createVarName(asset.names[0]);
if (typeof asset.source === "string") {
asset.source = createTransformedTextSource(varName, asset.source);
return `${varName}, std::extent_v<decltype(${varName})>`;
// return `${varName}, std::char_traits<char>::length(${varName})`;
} else {
const str = [...asset.source].map((v) => `0x${v.toString(16).padStart(2, "0")}`).join(", ");
asset.source = `#pragma once
static inline const unsigned char ${varName}[] {
${str}
};
`;
return `${varName}, std::extent_v<decltype(${varName})>`;
}
}
function transformChunk(chunk: OutputChunk) {
const varName = createVarName(chunk.fileName);
chunk.code = createTransformedTextSource(varName, chunk.code);
return `${varName}, std::extent_v<decltype(${varName})>`;
// return `${varName}, std::char_traits<char>::length(${varName})`;
}
export function headerTransformationPlugin(): Plugin {
return {
name: "header-transformation",
apply: "build",
config(config) {
config.base = "http://modman-resource/";
},
generateBundle(options: OutputOptions, bundle: OutputBundle, isWrite: boolean) {
const includesStr: string[] = [];
const uiFilesStr: string[] = [];
for (const curBundle of Object.values(bundle)) {
let varStr: string;
if (curBundle.type === "asset") {
varStr = transformAsset(curBundle);
} else {
varStr = transformChunk(curBundle);
}
includesStr.push(`#include "${curBundle.fileName}.h"`);
uiFilesStr.push(`{ "${curBundle.fileName}", { "${curBundle.fileName}", ${varStr} } }`);
curBundle.fileName = `${curBundle.fileName}.h`;
}
this.emitFile({
type: "asset",
fileName: "modmanui.h",
source: `#pragma once
#include "index.html.h"
${includesStr.join("\n")}
#include <string>
#include <unordered_map>
struct UiFile
{
const char* filename;
const void* data;
const size_t dataSize;
};
static inline const std::unordered_map<std::string, UiFile> MOD_MAN_UI_FILES({
${uiFilesStr.join(",\n")}
});
`,
});
},
transformIndexHtml(
html: string,
ctx: {
path: string;
filename: string;
server?: ViteDevServer;
bundle?: OutputBundle;
chunk?: OutputChunk;
},
) {
html = html
.replaceAll("index.js.h", "index.js")
.replaceAll("http://modman-resource/", "modman-resource://");
html = createTransformedTextSource(createVarName("index.html"), html);
ctx.filename = `${ctx.filename}.h`;
return html;
},
writeBundle(options, bundle) {
for (const curBundle of Object.values(bundle)) {
if (curBundle.fileName === "index.html" && curBundle.type === "asset") {
const outputFilePath = path.join(options.dir!, curBundle.fileName);
fs.renameSync(outputFilePath, outputFilePath + ".h");
curBundle.fileName += ".h";
}
}
this.emitFile({
type: "asset",
fileName: "index.h",
source: `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="" type="module"></script>
<script src="" type="module"></script>
<script src="" type="module"></script>
</body>
</html>`,
});
},
};
}

1
src/ModManUi/env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

View File

@@ -0,0 +1,28 @@
import { globalIgnores } from "eslint/config";
import { defineConfigWithVueTs, vueTsConfigs } from "@vue/eslint-config-typescript";
import pluginVue from "eslint-plugin-vue";
import pluginVitest from "@vitest/eslint-plugin";
import skipFormatting from "@vue/eslint-config-prettier/skip-formatting";
// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
// import { configureVueProject } from '@vue/eslint-config-typescript'
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
export default defineConfigWithVueTs(
{
name: "app/files-to-lint",
files: ["**/*.{ts,mts,tsx,vue}"],
},
globalIgnores(["**/dist/**", "**/dist-ssr/**", "**/coverage/**"]),
pluginVue.configs["flat/essential"],
vueTsConfigs.recommended,
{
...pluginVitest.configs.recommended,
files: ["src/**/__tests__/*"],
},
skipFormatting,
);

13
src/ModManUi/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Vue + Typescript App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

7083
src/ModManUi/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

42
src/ModManUi/package.json Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "openassettools",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build",
"lint": "eslint . --fix",
"format": "prettier --write **/*.{js,ts,vue,html,json,yml,yaml,md}"
},
"dependencies": {
"pinia": "3.0.3",
"vue": "3.5.22"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/jsdom": "^21.1.7",
"@types/node": "^22.18.6",
"@vitejs/plugin-vue": "6.0.1",
"@vitest/eslint-plugin": "^1.3.13",
"@vue/eslint-config-prettier": "^10.2.0",
"@vue/eslint-config-typescript": "^14.6.0",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.8.1",
"eslint": "^9.33.0",
"eslint-plugin-vue": "~10.4.0",
"jiti": "^2.5.1",
"jsdom": "^27.0.0",
"npm-run-all2": "^8.0.4",
"prettier": "3.6.2",
"sass": "1.93.2",
"typescript": "~5.9.3",
"vite": "7.1.7",
"vite-plugin-vue-devtools": "^8.0.2",
"vitest": "^3.2.4",
"vue-tsc": "3.1.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

33
src/ModManUi/src/App.vue Normal file
View File

@@ -0,0 +1,33 @@
<script setup lang="ts">
import { ref } from "vue";
const greetMsg = ref("");
const name = ref("");
async function greet() {
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
// greetMsg.value = await invoke("greet", { name: name.value });
}
</script>
<template>
<main class="container">
<h1>Welcome to Tauri + Vue</h1>
<form class="row" @submit.prevent="greet">
<input id="greet-input" v-model="name" placeholder="Enter a name..." autocomplete="off" />
<button type="submit">Greet</button>
</form>
<p>{{ greetMsg }}</p>
</main>
</template>
<style scoped>
.logo.vite:hover {
filter: drop-shadow(0 0 2em #747bff);
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #249b73);
}
</style>

109
src/ModManUi/src/main.scss Normal file
View File

@@ -0,0 +1,109 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color: #0f0f0f;
background-color: #f6f6f6;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
.container {
margin: 0;
padding-top: 10vh;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: 0.75s;
}
.logo.tauri:hover {
filter: drop-shadow(0 0 2em #24c8db);
}
.row {
display: flex;
justify-content: center;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
h1 {
text-align: center;
}
input,
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: #0f0f0f;
background-color: #ffffff;
transition: border-color 0.25s;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}
button {
cursor: pointer;
}
button:hover {
border-color: #396cd8;
}
button:active {
border-color: #396cd8;
background-color: #e8e8e8;
}
input,
button {
outline: none;
}
#greet-input {
margin-right: 5px;
}
@media (prefers-color-scheme: dark) {
:root {
color: #f6f6f6;
background-color: #2f2f2f;
}
a:hover {
color: #24c8db;
}
input,
button {
color: #ffffff;
background-color: #0f0f0f98;
}
button:active {
background-color: #0f0f0f69;
}
}

13
src/ModManUi/src/main.ts Normal file
View File

@@ -0,0 +1,13 @@
import "../public/favicon.ico";
import "./main.scss";
import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
const app = createApp(App);
app.use(createPinia());
app.mount("#app");

View File

@@ -0,0 +1,12 @@
import { ref, computed } from "vue";
import { defineStore } from "pinia";
export const useCounterStore = defineStore("counter", () => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}
return { count, doubleCount, increment };
});

View File

@@ -0,0 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"paths": {
"@/*": ["./src/*"]
}
}
}

View File

@@ -0,0 +1,14 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
]
}

View File

@@ -0,0 +1,20 @@
{
"extends": "@tsconfig/node22/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*",
"eslint.config.*",
"build/**/*"
],
"compilerOptions": {
"noEmit": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}

View File

@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.app.json",
"include": ["src/**/__tests__/*", "env.d.ts"],
"exclude": [],
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",
"lib": [],
"types": ["node", "jsdom"]
}
}

View File

@@ -0,0 +1,32 @@
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import { headerTransformationPlugin } from "./build/HeaderTransformationPlugin";
// https://vite.dev/config/
export default defineConfig({
build: {
outDir: "../../build/src/ModMan/ui",
copyPublicDir: false,
emptyOutDir: true,
rollupOptions: {
output: {
assetFileNames: "[name][extname]",
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
},
},
},
plugins: [vue(), vueDevTools(), headerTransformationPlugin()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
server: {
port: 1420,
strictPort: true,
},
});

View File

@@ -0,0 +1,13 @@
import { fileURLToPath } from "node:url";
import { mergeConfig, defineConfig } from "vitest/config";
import viteConfig from "./vite.config";
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: "jsdom",
root: fileURLToPath(new URL("./", import.meta.url)),
},
}),
);