feat(linting): adding in the checks to make me better and not so sloppy
This commit is contained in:
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 { readFileSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
@@ -36,8 +36,8 @@ try {
|
||||
},
|
||||
);
|
||||
|
||||
console.log(`✅ Release ${version} created!`);
|
||||
console.log(`🔗 ${response.data.html_url}`);
|
||||
console.info(`✅ Release ${version} created!`);
|
||||
console.info(`🔗 ${response.data.html_url}`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error: ${error.response?.data?.message || error.message}`);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user