mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
reworked asset generation
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"build": "vite build && node scripts/compileAssets.js",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"compileAssets": "node scripts/compileAssets.js --dev",
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
[
|
||||
"default",
|
||||
"3024-day",
|
||||
"3024-night",
|
||||
"abbott",
|
||||
"abcdef",
|
||||
"ambiance-mobile",
|
||||
"ambiance",
|
||||
"ayu-dark",
|
||||
"ayu-mirage",
|
||||
"base16-dark",
|
||||
"base16-light",
|
||||
"bespin",
|
||||
"blackboard",
|
||||
"cobalt",
|
||||
"colorforth",
|
||||
"darcula",
|
||||
"darkbrewery",
|
||||
"darkvision",
|
||||
"dracula",
|
||||
"duotone-dark",
|
||||
"duotone-light",
|
||||
"eclipse",
|
||||
"elegant",
|
||||
"erlang-dark",
|
||||
"gruvbox-dark",
|
||||
"hopscotch",
|
||||
"icecoder",
|
||||
"idea",
|
||||
"isotope",
|
||||
"juejin",
|
||||
"lesser-dark",
|
||||
"liquibyte",
|
||||
"lucario",
|
||||
"material-darker",
|
||||
"material-ocean",
|
||||
"material-palenight",
|
||||
"material",
|
||||
"mbo",
|
||||
"mdn-like",
|
||||
"midnight",
|
||||
"monokai",
|
||||
"moxer",
|
||||
"neat",
|
||||
"neo",
|
||||
"night",
|
||||
"nord",
|
||||
"oceanic-next",
|
||||
"panda-syntax",
|
||||
"paraiso-dark",
|
||||
"paraiso-light",
|
||||
"pastel-on-dark",
|
||||
"railscasts",
|
||||
"rubyblue",
|
||||
"seti",
|
||||
"shadowfox",
|
||||
"solarized",
|
||||
"ssms",
|
||||
"the-matrix",
|
||||
"tomorrow-night-bright",
|
||||
"tomorrow-night-eighties",
|
||||
"ttcn",
|
||||
"twilight",
|
||||
"vibrant-ink",
|
||||
"xq-dark",
|
||||
"xq-light",
|
||||
"yeti",
|
||||
"yonce",
|
||||
"zenburn"
|
||||
]
|
||||
"default",
|
||||
"3024-day",
|
||||
"3024-night",
|
||||
"abbott",
|
||||
"abcdef",
|
||||
"ambiance-mobile",
|
||||
"ambiance",
|
||||
"ayu-dark",
|
||||
"ayu-mirage",
|
||||
"base16-dark",
|
||||
"base16-light",
|
||||
"bespin",
|
||||
"blackboard",
|
||||
"cobalt",
|
||||
"colorforth",
|
||||
"darcula",
|
||||
"darkbrewery",
|
||||
"darkvision",
|
||||
"dracula",
|
||||
"duotone-dark",
|
||||
"duotone-light",
|
||||
"eclipse",
|
||||
"elegant",
|
||||
"erlang-dark",
|
||||
"gruvbox-dark",
|
||||
"hopscotch",
|
||||
"icecoder",
|
||||
"idea",
|
||||
"isotope",
|
||||
"juejin",
|
||||
"lesser-dark",
|
||||
"liquibyte",
|
||||
"lucario",
|
||||
"material-darker",
|
||||
"material-ocean",
|
||||
"material-palenight",
|
||||
"material",
|
||||
"mbo",
|
||||
"mdn-like",
|
||||
"midnight",
|
||||
"monokai",
|
||||
"moxer",
|
||||
"neat",
|
||||
"neo",
|
||||
"night",
|
||||
"nord",
|
||||
"oceanic-next",
|
||||
"panda-syntax",
|
||||
"paraiso-dark",
|
||||
"paraiso-light",
|
||||
"pastel-on-dark",
|
||||
"railscasts",
|
||||
"rubyblue",
|
||||
"seti",
|
||||
"shadowfox",
|
||||
"solarized",
|
||||
"ssms",
|
||||
"the-matrix",
|
||||
"tomorrow-night-bright",
|
||||
"tomorrow-night-eighties",
|
||||
"ttcn",
|
||||
"twilight",
|
||||
"vibrant-ink",
|
||||
"xq-dark",
|
||||
"xq-light",
|
||||
"yeti",
|
||||
"yonce",
|
||||
"zenburn"
|
||||
]
|
||||
@@ -2,12 +2,13 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import path from "path";
|
||||
import { generateAssetsPlugin } from "./vitePlugins/generateAssetsPlugin.js";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
plugins: [react(), generateAssetsPlugin()],
|
||||
build: {
|
||||
outDir: "build",
|
||||
emptyOutDir: true,
|
||||
emptyOutDir: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: "[name]/bundle.js",
|
||||
@@ -16,7 +17,6 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
// vite.config.js
|
||||
define: {
|
||||
global: "window",
|
||||
},
|
||||
|
||||
80
vitePlugins/generateAssetsPlugin.js
Normal file
80
vitePlugins/generateAssetsPlugin.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// vite-plugins/generateAssetsPlugin.js
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import less from "less";
|
||||
|
||||
export function generateAssetsPlugin(isDev = false) {
|
||||
return {
|
||||
name: "generate-assets",
|
||||
async buildStart() {
|
||||
const buildDir = path.resolve(process.cwd(), "build");
|
||||
|
||||
// Copy favicon
|
||||
await fs.copy("./client/homebrew/favicon.ico", `${buildDir}/assets/favicon.ico`);
|
||||
|
||||
// Copy shared styles/fonts
|
||||
const assets = fs.readdirSync("./shared/naturalcrit/styles");
|
||||
for (const file of assets) {
|
||||
await fs.copy(`./shared/naturalcrit/styles/${file}`, `${buildDir}/fonts/${file}`);
|
||||
}
|
||||
|
||||
// Compile Legacy themes
|
||||
const themes = { Legacy: {}, V3: {} };
|
||||
const legacyDirs = fs.readdirSync("./themes/Legacy");
|
||||
for (const dir of legacyDirs) {
|
||||
const themeData = JSON.parse(fs.readFileSync(`./themes/Legacy/${dir}/settings.json`, "utf-8"));
|
||||
themeData.path = dir;
|
||||
themes.Legacy[dir] = themeData;
|
||||
|
||||
const src = `./themes/Legacy/${dir}/style.less`;
|
||||
const outputDir = `${buildDir}/themes/Legacy/${dir}/style.css`;
|
||||
const lessOutput = await less.render(fs.readFileSync(src, "utf-8"), { compress: !isDev });
|
||||
await fs.outputFile(outputDir, lessOutput.css);
|
||||
}
|
||||
|
||||
// Compile V3 themes
|
||||
const v3Dirs = fs.readdirSync("./themes/V3");
|
||||
for (const dir of v3Dirs) {
|
||||
const themeData = JSON.parse(fs.readFileSync(`./themes/V3/${dir}/settings.json`, "utf-8"));
|
||||
themeData.path = dir;
|
||||
themes.V3[dir] = themeData;
|
||||
|
||||
await fs.copy(
|
||||
`./themes/V3/${dir}/dropdownTexture.png`,
|
||||
`${buildDir}/themes/V3/${dir}/dropdownTexture.png`,
|
||||
);
|
||||
await fs.copy(
|
||||
`./themes/V3/${dir}/dropdownPreview.png`,
|
||||
`${buildDir}/themes/V3/${dir}/dropdownPreview.png`,
|
||||
);
|
||||
|
||||
const src = `./themes/V3/${dir}/style.less`;
|
||||
const outputDir = `${buildDir}/themes/V3/${dir}/style.css`;
|
||||
const lessOutput = await less.render(fs.readFileSync(src, "utf-8"), { compress: !isDev });
|
||||
await fs.outputFile(outputDir, lessOutput.css);
|
||||
}
|
||||
|
||||
// Write themes.json
|
||||
await fs.outputFile("./themes/themes.json", JSON.stringify(themes, null, 2));
|
||||
|
||||
// Copy fonts/assets/icons
|
||||
await fs.copy("./themes/fonts", `${buildDir}/fonts`);
|
||||
await fs.copy("./themes/assets", `${buildDir}/assets`);
|
||||
await fs.copy("./client/icons", `${buildDir}/icons`);
|
||||
|
||||
// Compile CodeMirror editor themes
|
||||
const editorThemesBuildDir = `${buildDir}/homebrew/cm-themes`;
|
||||
await fs.copy("./node_modules/codemirror/theme", editorThemesBuildDir);
|
||||
await fs.copy("./themes/codeMirror/customThemes", editorThemesBuildDir);
|
||||
|
||||
const editorThemeFiles = fs.readdirSync(editorThemesBuildDir);
|
||||
await fs.outputFile(
|
||||
"./themes/codeMirror/editorThemes.json",
|
||||
JSON.stringify(["default", ...editorThemeFiles.map((f) => f.slice(0, -4))], null, 2),
|
||||
);
|
||||
|
||||
// Copy remaining CodeMirror assets
|
||||
await fs.copy("./themes/codeMirror", `${buildDir}/homebrew/codeMirror`);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user