feat(linting): adding in the checks to make me better and not so sloppy
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import { createLogger } from "./src/logger/logger.controller.js";
|
import { createLogger } from "./src/logger/logger.controller.js";
|
||||||
import { connectProdSql } from "./src/prodSql/sqlConnection.controller.js";
|
import { connectProdSql } from "./src/prodSql/prodSqlConnection.controller.js";
|
||||||
import { setupRoutes } from "./src/routeHandler.route.js";
|
import { setupRoutes } from "./src/routeHandler.routes.js";
|
||||||
|
|
||||||
const port = Number(process.env.PORT);
|
const port = Number(process.env.PORT);
|
||||||
|
|
||||||
|
|||||||
10
backend/src/prodSql/prodSql.routes.ts
Normal file
10
backend/src/prodSql/prodSql.routes.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import type { Express } from "express";
|
||||||
|
import restart from "./prodSqlRestart.route.js";
|
||||||
|
import start from "./prodSqlStart.route.js";
|
||||||
|
import stop from "./prodSqlStop.route.js";
|
||||||
|
export const setupProdSqlRoutes = (baseUrl: string, app: Express) => {
|
||||||
|
//setup all the routes
|
||||||
|
app.use(`${baseUrl}/api/system/prodSql`, start);
|
||||||
|
app.use(`${baseUrl}/api/system/prodSql`, stop);
|
||||||
|
app.use(`${baseUrl}/api/system/prodSql`, restart);
|
||||||
|
};
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
pool,
|
pool,
|
||||||
reconnecting,
|
reconnecting,
|
||||||
reconnectToSql,
|
reconnectToSql,
|
||||||
} from "./sqlConnection.controller.js";
|
} from "./prodSqlConnection.controller.js";
|
||||||
|
|
||||||
interface SqlError extends Error {
|
interface SqlError extends Error {
|
||||||
code?: string;
|
code?: string;
|
||||||
23
backend/src/prodSql/prodSqlRestart.route.ts
Normal file
23
backend/src/prodSql/prodSqlRestart.route.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||||
|
import { closePool, connectProdSql } from "./prodSqlConnection.controller.js";
|
||||||
|
|
||||||
|
const r = Router();
|
||||||
|
|
||||||
|
r.post("/restart", async (_, res) => {
|
||||||
|
await closePool();
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 2000));
|
||||||
|
|
||||||
|
const connect = await connectProdSql();
|
||||||
|
apiReturn(res, {
|
||||||
|
success: connect.success,
|
||||||
|
level: connect.success ? "info" : "error",
|
||||||
|
module: "routes",
|
||||||
|
subModule: "prodSql",
|
||||||
|
message: "Sql Server has been restarted",
|
||||||
|
data: connect.data,
|
||||||
|
status: connect.success ? 200 : 400,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
export default r;
|
||||||
20
backend/src/prodSql/prodSqlStart.route.ts
Normal file
20
backend/src/prodSql/prodSqlStart.route.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||||
|
import { connectProdSql } from "./prodSqlConnection.controller.js";
|
||||||
|
|
||||||
|
const r = Router();
|
||||||
|
|
||||||
|
r.post("/start", async (_, res) => {
|
||||||
|
const connect = await connectProdSql();
|
||||||
|
apiReturn(res, {
|
||||||
|
success: connect.success,
|
||||||
|
level: connect.success ? "info" : "error",
|
||||||
|
module: "routes",
|
||||||
|
subModule: "prodSql",
|
||||||
|
message: connect.message,
|
||||||
|
data: connect.data,
|
||||||
|
status: connect.success ? 200 : 400,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default r;
|
||||||
20
backend/src/prodSql/prodSqlStop.route.ts
Normal file
20
backend/src/prodSql/prodSqlStop.route.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||||
|
import { closePool } from "./prodSqlConnection.controller.js";
|
||||||
|
|
||||||
|
const r = Router();
|
||||||
|
|
||||||
|
r.post("/stop", async (_, res) => {
|
||||||
|
const connect = await closePool();
|
||||||
|
apiReturn(res, {
|
||||||
|
success: connect.success,
|
||||||
|
level: connect.success ? "info" : "error",
|
||||||
|
module: "routes",
|
||||||
|
subModule: "prodSql",
|
||||||
|
message: connect.message,
|
||||||
|
data: connect.data,
|
||||||
|
status: connect.success ? 200 : 400,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default r;
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { Router } from "express";
|
|
||||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
|
||||||
import { closePool, connectProdSql } from "./sqlConnection.controller.js";
|
|
||||||
|
|
||||||
const r = Router();
|
|
||||||
|
|
||||||
r.post("/start", async (_, res) => {
|
|
||||||
const connect = await connectProdSql();
|
|
||||||
apiReturn(res, {
|
|
||||||
success: connect.success,
|
|
||||||
level: connect.success ? "info" : "error",
|
|
||||||
module: "routes",
|
|
||||||
subModule: "prodSql",
|
|
||||||
message: connect.message,
|
|
||||||
data: connect.data,
|
|
||||||
status: connect.success ? 200 : 400,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
r.post("/stop", async (_, res) => {
|
|
||||||
const connect = await closePool();
|
|
||||||
apiReturn(res, {
|
|
||||||
success: connect.success,
|
|
||||||
level: connect.success ? "info" : "error",
|
|
||||||
module: "routes",
|
|
||||||
subModule: "prodSql",
|
|
||||||
message: connect.message,
|
|
||||||
data: connect.data,
|
|
||||||
status: connect.success ? 200 : 400,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
r.post("/restart", async (_, res) => {
|
|
||||||
await closePool();
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 2000));
|
|
||||||
|
|
||||||
const connect = await connectProdSql();
|
|
||||||
apiReturn(res, {
|
|
||||||
success: connect.success,
|
|
||||||
level: connect.success ? "info" : "error",
|
|
||||||
module: "routes",
|
|
||||||
subModule: "prodSql",
|
|
||||||
message: "Sql Server has been restarted",
|
|
||||||
data: connect.data,
|
|
||||||
status: connect.success ? 200 : 400,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
export default r;
|
|
||||||
@@ -2,12 +2,13 @@ import type { Express } from "express";
|
|||||||
|
|
||||||
// import the routes and route setups
|
// import the routes and route setups
|
||||||
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
|
import { setupApiDocsRoutes } from "./configs/scaler.config.js";
|
||||||
import prodSql from "./prodSql/sql.route.js";
|
import { setupProdSqlRoutes } from "./prodSql/prodSql.routes.js";
|
||||||
import stats from "./system/stats.route.js";
|
import stats from "./system/stats.route.js";
|
||||||
|
|
||||||
export const setupRoutes = (baseUrl: string, app: Express) => {
|
export const setupRoutes = (baseUrl: string, app: Express) => {
|
||||||
//setup all the routes
|
//setup all the routes
|
||||||
setupApiDocsRoutes(baseUrl, app);
|
setupApiDocsRoutes(baseUrl, app);
|
||||||
|
setupProdSqlRoutes(baseUrl, app);
|
||||||
|
|
||||||
app.use(`${baseUrl}/api/stats`, stats);
|
app.use(`${baseUrl}/api/stats`, stats);
|
||||||
app.use(`${baseUrl}/api/system/prodSql`, prodSql);
|
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
import { prodQuery } from "../prodSql/prodSqlQuery.controller.js";
|
||||||
import { prodSqlServerStats } from "../prodSql/querys/prodSqlStats.js";
|
import { prodSqlServerStats } from "../prodSql/querys/prodSqlStats.js";
|
||||||
import { prodQuery } from "../prodSql/sqlQuery.controller.js";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
|||||||
51
biome.json
Normal file
51
biome.json
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
|
||||||
|
"vcs": {
|
||||||
|
"enabled": true,
|
||||||
|
"clientKind": "git",
|
||||||
|
"useIgnoreFile": true,
|
||||||
|
"defaultBranch": "main"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"ignoreUnknown": false
|
||||||
|
},
|
||||||
|
"formatter": {
|
||||||
|
"enabled": true,
|
||||||
|
"indentStyle": "tab"
|
||||||
|
},
|
||||||
|
"linter": {
|
||||||
|
"enabled": true,
|
||||||
|
"rules": {
|
||||||
|
"suspicious": {
|
||||||
|
"noConsole": {
|
||||||
|
"level":"on",
|
||||||
|
"options": {
|
||||||
|
"allow": ["error", "info", "warn"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"correctness": {
|
||||||
|
"useJsxKeyInIterable": "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"assist": {
|
||||||
|
"enabled": true,
|
||||||
|
"actions": {
|
||||||
|
"source": {
|
||||||
|
"recommended": true,
|
||||||
|
"organizeImports": "on"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"javascript": {
|
||||||
|
"formatter": {
|
||||||
|
"quoteStyle": "double"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"formatter": {
|
||||||
|
"enabled": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,15 +7,16 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"dev": "dotenvx run -f .env -- npm run dev:app",
|
"dev": "dotenvx run -f .env -- npm run dev:app",
|
||||||
"dev:app": "cd backend && tsx watch app.ts",
|
"dev:app": "cd backend && tsx watch app.ts",
|
||||||
"prebuild": "tsx backend/src/scaler/generateSpec.ts",
|
"build": "npm run specCheck && npm run lint && npm run build:app",
|
||||||
"build": "esbuild backend/app.ts --bundle --platform=node --minify --outfile=dist/index.js --format=esm --packages=external",
|
|
||||||
"build:app": "ncc build backend/app.ts -o dist -m -s",
|
"build:app": "ncc build backend/app.ts -o dist -m -s",
|
||||||
"lint": "tsc",
|
"lint": "tsc && biome lint",
|
||||||
"start": "dotenvx run -f .env -- node dist/index.js",
|
"start": "dotenvx run -f .env -- node dist/index.js",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"changeset": "changeset",
|
"changeset": "changeset",
|
||||||
"version": "changeset version",
|
"version": "changeset version",
|
||||||
"release": "dotenvx run -f .env -- npm run version && git push --follow-tags && node scripts/create-release.js"
|
"release": "dotenvx run -f .env -- npm run version && git push --follow-tags && node scripts/create-release.js",
|
||||||
|
"specCheck": "node scripts/check-route-specs.mjs"
|
||||||
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
50
scripts/check-route-specs.mjs
Normal file
50
scripts/check-route-specs.mjs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { readdirSync, statSync } from "node:fs";
|
||||||
|
import { basename, join } from "node:path";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively get all files from a directory
|
||||||
|
*/
|
||||||
|
function getAllFiles(dir) {
|
||||||
|
let results = [];
|
||||||
|
for (const file of readdirSync(dir)) {
|
||||||
|
const filePath = join(dir, file);
|
||||||
|
const stat = statSync(filePath);
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
results = results.concat(getAllFiles(filePath));
|
||||||
|
} else {
|
||||||
|
results.push(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main check function
|
||||||
|
*/
|
||||||
|
function checkRouteSpecs(baseDir) {
|
||||||
|
const allFiles = getAllFiles(baseDir);
|
||||||
|
|
||||||
|
// Collect base filenames (without extensions)
|
||||||
|
const routeFiles = allFiles.filter((f) => f.endsWith(".route.ts"));
|
||||||
|
const specFiles = allFiles.filter((f) => f.endsWith(".spec.ts"));
|
||||||
|
|
||||||
|
const specNames = new Set(specFiles.map((f) => basename(f, ".spec.ts")));
|
||||||
|
|
||||||
|
const missingSpecs = routeFiles.filter((routePath) => {
|
||||||
|
const baseName = basename(routePath, ".route.ts");
|
||||||
|
return !specNames.has(baseName);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (missingSpecs.length > 0) {
|
||||||
|
console.error("❌ Missing spec files for these routes:\n");
|
||||||
|
for (const missing of missingSpecs) {
|
||||||
|
console.error(`··-·${missing}`);
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.info("✅ All route files have corresponding spec files.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust paths based on your structure
|
||||||
|
checkRouteSpecs("backend/src");
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import { dirname, join } from "path";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
@@ -36,8 +36,8 @@ try {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`✅ Release ${version} created!`);
|
console.info(`✅ Release ${version} created!`);
|
||||||
console.log(`🔗 ${response.data.html_url}`);
|
console.info(`🔗 ${response.data.html_url}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Error: ${error.response?.data?.message || error.message}`);
|
console.error(`❌ Error: ${error.response?.data?.message || error.message}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user