forked from CTFd/core-beta
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
119 lines (113 loc) · 4.07 KB
/
vite.config.js
File metadata and controls
119 lines (113 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const { resolve } = require("path");
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import copy from "rollup-plugin-copy";
import { exec, execSync } from "child_process";
import fs from "fs";
import os from "os";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(),
{
name: "clear-redis-cache",
buildEnd() {
try {
console.log("\nClearing Redis cache...");
const containerName = "ctfd_atr2025-cache-1"; // Depending on your setup, this might need to be changed
const containerId = execSync(`docker ps --filter "name=${containerName}" --format "{{.ID}}"`).toString().trim();
if (!containerId) {
console.error(`\nCould not find container with name "${containerName}"`);
return;
}
const luaScript = `
local keys = redis.call('keys', '*')
for i=1,#keys,1 do
if string.sub(keys[i], 1, 19) ~= 'flask_cache_session' then
redis.call('del', keys[i])
end
end
`;
const tmpFileName = "clear_redis_cache.lua";
const tmpFilePath = path.join(os.tmpdir(), tmpFileName);
fs.writeFileSync(tmpFilePath, luaScript);
const command = `docker cp ${tmpFilePath} ${containerId}:/tmp/${tmpFileName} && docker exec -i ${containerId} redis-cli --eval /tmp/${tmpFileName}`;
console.log(`Running command: ${command}`);
exec(command, (err, stdout, stderr) => {
if (err) {
console.error(`\nError clearing cache: ${err}`);
return;
}
if (stderr) {
console.error(`\nError output: ${stderr}`);
return;
}
console.log(`\nCleared Redis cache for container "${containerName}"`);
});
} catch (error) {
console.error(`\nError executing docker command: ${error.message}`);
}
},
}
],
resolve: {
alias: {
"~": resolve(__dirname, "./node_modules/"),
},
},
build: {
manifest: true,
outDir: "static",
rollupOptions: {
plugins: [
copy({
targets: [
// https://github.com/vitejs/vite/issues/1618#issuecomment-764579557
{
src: "./node_modules/@fortawesome/fontawesome-free/webfonts/**/*",
dest: "static/webfonts",
},
{
src: "./node_modules/@fontsource/lato/files/**/*400*-normal*",
dest: "static/webfonts",
},
{
src: "./node_modules/@fontsource/lato/files/**/*700*-normal*",
dest: "static/webfonts",
},
{
src: "./node_modules/@fontsource/raleway/files/**/*400*-normal*",
dest: "static/webfonts",
},
{
src: "./assets/img/**",
dest: "static/img",
},
],
hook: "writeBundle",
}),
],
output: {
manualChunks: {
echarts: ["echarts", "zrender"],
},
},
input: {
index: resolve(__dirname, "assets/js/index.js"),
page: resolve(__dirname, "assets/js/page.js"),
setup: resolve(__dirname, "assets/js/setup.js"),
settings: resolve(__dirname, "assets/js/settings.js"),
challenges: resolve(__dirname, "assets/js/challenges.js"),
scoreboard: resolve(__dirname, "assets/js/scoreboard.js"),
notifications: resolve(__dirname, "assets/js/notifications.js"),
teams_public: resolve(__dirname, "assets/js/teams/public.js"),
teams_private: resolve(__dirname, "assets/js/teams/private.js"),
teams_list: resolve(__dirname, "assets/js/teams/list.js"),
users_public: resolve(__dirname, "assets/js/users/public.js"),
users_private: resolve(__dirname, "assets/js/users/private.js"),
users_list: resolve(__dirname, "assets/js/users/list.js"),
main: resolve(__dirname, "assets/scss/main.scss"),
},
},
},
});