diff --git a/src/ui/client/.gitignore b/src/ui/client/.gitignore index a547bf36d..afb9d87e4 100644 --- a/src/ui/client/.gitignore +++ b/src/ui/client/.gitignore @@ -22,3 +22,7 @@ dist-ssr *.njsproj *.sln *.sw? + +# build +opt-dashboard +opt-setup \ No newline at end of file diff --git a/src/ui/client/README.md b/src/ui/client/README.md index 16cb9fead..5638443d2 100644 --- a/src/ui/client/README.md +++ b/src/ui/client/README.md @@ -17,7 +17,7 @@ For example, you need to execute `npm run dev-dashboard` to run a vite dev serve In case you want to run the BunkerWeb UI, try to update front-end and get the modifications on your app, you need to do the following : - go to `misc/dev` path and run `docker compose -f docker-compose.ui.yml up --build` in order to create BunkerWeb with UI looking for local static and templates folder -- update front-end in dev mode and run inside `cd/src/ui/client` : `node ./build.js` to rebuild setup and dashboard pages. +- update front-end in dev mode and run inside `cd/src/ui/client` : `python build.py` to rebuild setup and dashboard pages. # Prod mode diff --git a/src/ui/client/build.js b/src/ui/client/build.js deleted file mode 100644 index 8e9604b08..000000000 --- a/src/ui/client/build.js +++ /dev/null @@ -1,205 +0,0 @@ -import { execSync } from "child_process"; -import { resolve } from "path"; -import fs from "fs"; - -const __dirname = import.meta.dirname; - -const clientBuildDir = "opt-dashboard"; -const appStaticDir = "../static"; -const appTempDir = "../templates"; - -async function moveFile(src, dest) { - fs.renameSync(src, dest, (err) => { - if (err) { - return console.error(err); - } - }); -} - -async function createDirIfNotExists(dir) { - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir); - } -} - -async function delElRecursive(path) { - if (!fs.existsSync(path)) return; - fs.rmSync(path, { recursive: true }, (err) => { - if (err) { - console.log(err); - } - }); -} - -async function copyDir(src, dest) { - fs.cpSync(src, dest, { recursive: true }, (err) => { - if (err) { - console.log(err); - } - }); -} - -// Run subprocess command on specific dir -async function runCommand(dir, command) { - try { - execSync( - command, - { cwd: resolve(__dirname + dir) }, - function (err, stdout, stderr) { - console.log(stdout); - console.log(stderr); - if (err !== null) { - console.log(`exec error: ${err}`); - } - } - ); - } catch (err) { - console.log(err); - } -} - -// Install deps and build vite (work for client and setup) -async function buildVite() { - // Install packages - await runCommand("", "npm install"); - await runCommand("", "npm run build-dashboard"); -} - -// Change dir structure for flask app -async function updateClientDir() { - const srcDir = resolve(`./${clientBuildDir}/dashboard/pages`); - const temporaryTemp = resolve(`./templatestemp`); - const baseTemp = resolve(`./${clientBuildDir}/dashboard/`); - const staticTemp = resolve(`./${clientBuildDir}/templates`); - - try { - createDirIfNotExists(staticTemp); - copyDir(srcDir, temporaryTemp); - changeOutputTemplates(); - // Delete templatestemp dir - delElRecursive(baseTemp); - } catch (err) { - console.log(err); - } -} - -async function changeOutputTemplates() { - const templateTempDir = resolve(`./templatestemp`); - fs.readdir(templateTempDir, (err, subdirs) => { - subdirs.forEach((subdir) => { - // Get absolute path of current subdir - const currPath = resolve(`./templatestemp/${subdir}`); - // Rename index.html by subdir name - moveFile( - `${currPath}/index.html`, - `./${clientBuildDir}/templates/${subdir}.html` - ); - }); - }); -} - -async function setBuildTempToUI() { - // Run all files in /templates and get data - fs.readdir(resolve(`./${clientBuildDir}/templates`), (err, files) => { - // Read content - files.forEach((file) => { - fs.readFile( - resolve(`./${clientBuildDir}/templates/${file}`), - { - encoding: "utf8", - flag: "r", - }, - (err, data) => { - if (err) { - console.log(err); - } - let updateData = data; - // I want to remove the first "/" for href="/css", href="/js", href="/img", href="/favicon", src="/assets" or src="/js" - const regexPaths = - /href="\/(css|js|img|favicon|assets|js)|src="\/(assets|js)/g; - updateData = data.replace(regexPaths, (match) => { - return match.replace("/", ""); - }); - - // For each