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": {
|
"scripts": {
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
"build": "vite build && node scripts/compileAssets.js",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"compileAssets": "node scripts/compileAssets.js --dev",
|
"compileAssets": "node scripts/compileAssets.js --dev",
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +1,70 @@
|
|||||||
[
|
[
|
||||||
"default",
|
"default",
|
||||||
"3024-day",
|
"3024-day",
|
||||||
"3024-night",
|
"3024-night",
|
||||||
"abbott",
|
"abbott",
|
||||||
"abcdef",
|
"abcdef",
|
||||||
"ambiance-mobile",
|
"ambiance-mobile",
|
||||||
"ambiance",
|
"ambiance",
|
||||||
"ayu-dark",
|
"ayu-dark",
|
||||||
"ayu-mirage",
|
"ayu-mirage",
|
||||||
"base16-dark",
|
"base16-dark",
|
||||||
"base16-light",
|
"base16-light",
|
||||||
"bespin",
|
"bespin",
|
||||||
"blackboard",
|
"blackboard",
|
||||||
"cobalt",
|
"cobalt",
|
||||||
"colorforth",
|
"colorforth",
|
||||||
"darcula",
|
"darcula",
|
||||||
"darkbrewery",
|
"darkbrewery",
|
||||||
"darkvision",
|
"darkvision",
|
||||||
"dracula",
|
"dracula",
|
||||||
"duotone-dark",
|
"duotone-dark",
|
||||||
"duotone-light",
|
"duotone-light",
|
||||||
"eclipse",
|
"eclipse",
|
||||||
"elegant",
|
"elegant",
|
||||||
"erlang-dark",
|
"erlang-dark",
|
||||||
"gruvbox-dark",
|
"gruvbox-dark",
|
||||||
"hopscotch",
|
"hopscotch",
|
||||||
"icecoder",
|
"icecoder",
|
||||||
"idea",
|
"idea",
|
||||||
"isotope",
|
"isotope",
|
||||||
"juejin",
|
"juejin",
|
||||||
"lesser-dark",
|
"lesser-dark",
|
||||||
"liquibyte",
|
"liquibyte",
|
||||||
"lucario",
|
"lucario",
|
||||||
"material-darker",
|
"material-darker",
|
||||||
"material-ocean",
|
"material-ocean",
|
||||||
"material-palenight",
|
"material-palenight",
|
||||||
"material",
|
"material",
|
||||||
"mbo",
|
"mbo",
|
||||||
"mdn-like",
|
"mdn-like",
|
||||||
"midnight",
|
"midnight",
|
||||||
"monokai",
|
"monokai",
|
||||||
"moxer",
|
"moxer",
|
||||||
"neat",
|
"neat",
|
||||||
"neo",
|
"neo",
|
||||||
"night",
|
"night",
|
||||||
"nord",
|
"nord",
|
||||||
"oceanic-next",
|
"oceanic-next",
|
||||||
"panda-syntax",
|
"panda-syntax",
|
||||||
"paraiso-dark",
|
"paraiso-dark",
|
||||||
"paraiso-light",
|
"paraiso-light",
|
||||||
"pastel-on-dark",
|
"pastel-on-dark",
|
||||||
"railscasts",
|
"railscasts",
|
||||||
"rubyblue",
|
"rubyblue",
|
||||||
"seti",
|
"seti",
|
||||||
"shadowfox",
|
"shadowfox",
|
||||||
"solarized",
|
"solarized",
|
||||||
"ssms",
|
"ssms",
|
||||||
"the-matrix",
|
"the-matrix",
|
||||||
"tomorrow-night-bright",
|
"tomorrow-night-bright",
|
||||||
"tomorrow-night-eighties",
|
"tomorrow-night-eighties",
|
||||||
"ttcn",
|
"ttcn",
|
||||||
"twilight",
|
"twilight",
|
||||||
"vibrant-ink",
|
"vibrant-ink",
|
||||||
"xq-dark",
|
"xq-dark",
|
||||||
"xq-light",
|
"xq-light",
|
||||||
"yeti",
|
"yeti",
|
||||||
"yonce",
|
"yonce",
|
||||||
"zenburn"
|
"zenburn"
|
||||||
]
|
]
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { generateAssetsPlugin } from "./vitePlugins/generateAssetsPlugin.js";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react(), generateAssetsPlugin()],
|
||||||
build: {
|
build: {
|
||||||
outDir: "build",
|
outDir: "build",
|
||||||
emptyOutDir: true,
|
emptyOutDir: false,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
entryFileNames: "[name]/bundle.js",
|
entryFileNames: "[name]/bundle.js",
|
||||||
@@ -16,7 +17,6 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// vite.config.js
|
|
||||||
define: {
|
define: {
|
||||||
global: "window",
|
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