Skip to content

Update eslint monorepo to v9 (major) #993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 0 additions & 12 deletions openbas-front/.eslintignore

This file was deleted.

108 changes: 0 additions & 108 deletions openbas-front/.eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion openbas-front/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.1.cjs
defaultSemverRangePrefix: ""
108 changes: 58 additions & 50 deletions openbas-front/builder/dev/dev.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "url";
import fsExtra from "fs-extra/esm";
import path from "node:path";
import esbuild from "esbuild";
import chokidar from "chokidar";
/* eslint import/no-extraneous-dependencies: 0 */

import { readFileSync } from 'node:fs';
import path from 'node:path';

import chokidar from 'chokidar';
import esbuild from 'esbuild';
import express from 'express';
import fsExtra from 'fs-extra/esm';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { fileURLToPath } from 'url';

// mimic CommonJS variables -- not needed if using CommonJS
// eslint-disable-next-line no-underscore-dangle
const __filename = fileURLToPath(import.meta.url);
// eslint-disable-next-line no-underscore-dangle
const __dirname = path.dirname(__filename);

const basePath = "";
const basePath = '';
const clients = [];
const buildPath = "./builder/dev/build/";
const buildPath = './builder/dev/build/';
const debounce = (func, timeout = 500) => {
let timer;
return (...args) => {
Expand All @@ -26,42 +31,42 @@ const debounce = (func, timeout = 500) => {

const middleware = (target, ws = true) =>
createProxyMiddleware({
target: "http://localhost:8080" + basePath + target,
target: 'http://localhost:8080' + basePath + target,
changeOrigin: true,
ws,
});

// Start with an initial build
esbuild
.context({
logLevel: "info",
entryPoints: ["src/index.tsx"],
publicPath: "/",
logLevel: 'info',
entryPoints: ['src/index.tsx'],
publicPath: '/',
bundle: true,
banner: {
js: ' (() => new EventSource("http://localhost:3001/dev").onmessage = () => location.reload())();',
},
loader: {
".js": "jsx",
".svg": "file",
".png": "file",
".woff": "dataurl",
".woff2": "dataurl",
".ttf": "dataurl",
".eot": "dataurl",
'.js': 'jsx',
'.svg': 'file',
'.png': 'file',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.ttf': 'dataurl',
'.eot': 'dataurl',
},
assetNames: "[dir]/[name]-[hash]",
target: ["chrome58"],
assetNames: '[dir]/[name]-[hash]',
target: ['chrome58'],
minify: false,
keepNames: true,
sourcemap: true,
sourceRoot: "src",
outdir: "builder/dev/build",
sourceRoot: 'src',
outdir: 'builder/dev/build',
})
.then(async (builder) => {
await builder.rebuild();
// region Copy public files to build
fsExtra.copySync("./src/static/ext", buildPath + "/static/ext", {
fsExtra.copySync('./src/static/ext', buildPath + '/static/ext', {
recursive: true,
overwrite: true,
});
Expand All @@ -72,63 +77,66 @@ esbuild
&& !(path.endsWith('.js') || path.endsWith('.jsx') || path.endsWith('.ts') || path.endsWith('.tsx')),
})
.on(
"all",
'all',
debounce(() => {
const start = new Date().getTime();
// eslint-disable-next-line no-console
console.log(`[HOT RELOAD] Update of front detected`);
return builder
.rebuild()
.then(() => {
const time = new Date().getTime() - start;
// eslint-disable-next-line no-console
console.log(
`[HOT RELOAD] Rebuild done in ${time} ms, updating frontend`,
);
clients.forEach((res) => res.write("data: update\n\n"));
clients.forEach(res => res.write('data: update\n\n'));
clients.length = 0;
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error);
});
}),
);
// Start a dev web server
const app = express();
app.get("/dev", (req, res) => {
app.get('/dev', (req, res) => {
return clients.push(
res.writeHead(200, {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Access-Control-Allow-Origin": "*",
Connection: "keep-alive",
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Access-Control-Allow-Origin': '*',
'Connection': 'keep-alive',
}),
);
});
app.set("trust proxy", 1);
app.use("/api", middleware("/api"));
app.use("/login", middleware("/login"));
app.use("/logout", middleware("/logout"));
app.use("/oauth2", middleware("/oauth2"));
app.use("/saml2", middleware("/saml2"));
app.set('trust proxy', 1);
app.use('/api', middleware('/api'));
app.use('/login', middleware('/login'));
app.use('/logout', middleware('/logout'));
app.use('/oauth2', middleware('/oauth2'));
app.use('/saml2', middleware('/saml2'));
app.use(
basePath + `/static`,
express.static(path.join(__dirname, "./build/static")),
express.static(path.join(__dirname, './build/static')),
);
app.use(`/css`, express.static(path.join(__dirname, "./build")));
app.use(`/js`, express.static(path.join(__dirname, "./build")));
app.get("*", (req, res) => {
const data = readFileSync(`${__dirname}/index.html`, "utf8");
app.use(`/css`, express.static(path.join(__dirname, './build')));
app.use(`/js`, express.static(path.join(__dirname, './build')));
app.get('*', (req, res) => {
const data = readFileSync(`${__dirname}/index.html`, 'utf8');
const withOptionValued = data
.replace(/%BASE_PATH%/g, basePath)
.replace(/%APP_TITLE%/g, "OpenBAS Dev")
.replace(/%APP_DESCRIPTION%/g, "OpenBAS Development platform")
.replace(/%APP_TITLE%/g, 'OpenBAS Dev')
.replace(/%APP_DESCRIPTION%/g, 'OpenBAS Development platform')
.replace(/%APP_FAVICON%/g, `${basePath}/static/ext/favicon.png`)
.replace(/%APP_MANIFEST%/g, `${basePath}/static/ext/manifest.json`);
res.header(
"Cache-Control",
"private, no-cache, no-store, must-revalidate",
'Cache-Control',
'private, no-cache, no-store, must-revalidate',
);
res.header("Expires", "-1");
res.header("Pragma", "no-cache");
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
return res.send(withOptionValued);
});
app.listen(3001);
Expand Down
9 changes: 6 additions & 3 deletions openbas-front/builder/prod/prod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint import/no-extraneous-dependencies: 0 */

import fs from 'node:fs';

import { build } from 'esbuild';
import fsExtra from 'fs-extra/esm';
import fs from 'node:fs';

const buildPath = './builder/prod/build/';
build({
Expand Down Expand Up @@ -36,12 +39,12 @@ build({
// region Generate index.html
const cssStaticFiles = fs.readdirSync(buildPath + 'static/css');
const cssLinks = cssStaticFiles.map(
(f) => `<link href="%BASE_PATH%/static/css/${f}" rel="stylesheet">`,
f => `<link href="%BASE_PATH%/static/css/${f}" rel="stylesheet">`,
);
const cssImport = cssLinks.join('\n');
const jsStaticFiles = fs.readdirSync(buildPath + 'static/js');
const jsLinks = jsStaticFiles.map(
(f) => `<script defer="defer" src="%BASE_PATH%/static/js/${f}"></script>`,
f => `<script defer="defer" src="%BASE_PATH%/static/js/${f}"></script>`,
);
const jsImport = jsLinks.join('\n');
const indexHtml = `
Expand Down
Loading