Newer
Older
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
import { dirname, join } from "path";
import { writeFileSync, existsSync, mkdirSync, readFileSync } from "fs";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const routesFilePathResources = join(__dirname, "../src/app/app-resources-routing.module.ts");
const routesFilePathTesting = join(__dirname, "../src/app/app-testing-routing.module.ts");
const routesFilePathServices = join(__dirname, "../src/app/app-services-routing.module.ts");
const routesFilePathProducts = join(__dirname, "../src/app/app-products-routing.module.ts");
//read route module files as plaintext and extract paths
function extractRoutesFromFile(filePath: string, parent: string): string[] {
try {
const fileContent = readFileSync(filePath, "utf-8");
// Regex to match route paths (excluding those with `/:id`)
const pathRegex = /path:\s*['"]([^'":]+)['"]/g;
let match;
const paths: string[] = [];
while ((match = pathRegex.exec(fileContent)) !== null) {
if (!match[1].includes("/:id")) {
paths.push(`${parent}/${match[1]}`);
}
}
return paths;
} catch (error) {
console.error(`❌ Error reading file: ${filePath}`, error);
return [];
}
}
// Extract paths from every file
let resourceRoutesStr = extractRoutesFromFile(routesFilePathResources, "resources");
let servicesRoutesStr = extractRoutesFromFile(routesFilePathServices, "services");
let testingRoutesStr = extractRoutesFromFile(routesFilePathTesting, "testing");
let productRoutesStr = extractRoutesFromFile(routesFilePathProducts, "products");
let allRoutes = resourceRoutesStr.concat(servicesRoutesStr, testingRoutesStr, productRoutesStr);
allRoutes.push('/products/individual_update/myuser', '/testing/individual_update/myuser', '/services/individual_update/myuser', '/resources/individual_update/myuser');
let protectedRoutes: string[] = allRoutes.filter((el) => { return el!='services/services_marketplace' && el!='products/marketplace'
&& el!='resources/resources_marketplace'})
// Ensure `cypress/fixtures` directory exists
const fixturesDir = join(__dirname, "../cypress/fixtures");
if (!existsSync(fixturesDir)) {
mkdirSync(fixturesDir, { recursive: true });
}
// Convert extracted routes to JSON and save to file
const jsonOutput = JSON.stringify({ routes: protectedRoutes }, null, 2);
const outputPath = join(fixturesDir, "routes.json");
writeFileSync(outputPath, jsonOutput, "utf-8");
console.log("✅ Routes JSON file generated successfully!");