Skip to main content

sherlock_io/patterns/
web.rs

1use regex::Regex;
2
3pub struct WebPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl WebPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // Legacy dependency managers
13            Regex::new(r"bower_components").unwrap(),
14            
15            // Build output directories
16            Regex::new(r"dist/").unwrap(),
17            Regex::new(r"build/").unwrap(),
18            Regex::new(r"out/").unwrap(),
19            Regex::new(r"public/").unwrap(),
20            Regex::new(r"static/").unwrap(),
21            Regex::new(r"assets/").unwrap(),
22            
23            // Framework specific build outputs
24            Regex::new(r"\.next/").unwrap(),
25            Regex::new(r"\.nuxt/").unwrap(),
26            Regex::new(r"\.output/").unwrap(),
27            Regex::new(r"\.svelte-kit/").unwrap(),
28            Regex::new(r"\.astro/").unwrap(),
29            Regex::new(r"\.docusaurus/").unwrap(),
30            Regex::new(r"_site/").unwrap(),
31            
32            // Deployment and hosting
33            Regex::new(r"\.vercel/").unwrap(),
34            Regex::new(r"\.netlify/").unwrap(),
35            Regex::new(r"\.firebase/").unwrap(),
36            Regex::new(r"\.surge/").unwrap(),
37            
38            // CDN and vendor files
39            Regex::new(r"vendor/").unwrap(),
40            Regex::new(r"libs/").unwrap(),
41            Regex::new(r"lib/").unwrap(),
42            
43            // Generated files
44            Regex::new(r"\.generated/").unwrap(),
45            Regex::new(r"generated/").unwrap(),
46        ];
47
48        let cache_patterns = vec![
49            // General cache directories
50            Regex::new(r"\.cache/").unwrap(),
51            Regex::new(r"\.tmp/").unwrap(),
52            Regex::new(r"tmp/").unwrap(),
53            Regex::new(r"temp/").unwrap(),
54            
55            // CSS preprocessor caches
56            Regex::new(r"\.sass-cache/").unwrap(),
57            Regex::new(r"\.postcss-cache/").unwrap(),
58            Regex::new(r"\.stylelint-cache/").unwrap(),
59            
60            // Build tool caches
61            Regex::new(r"\.parcel-cache/").unwrap(),
62            Regex::new(r"\.webpack/").unwrap(),
63            Regex::new(r"\.rollup\.cache/").unwrap(),
64            Regex::new(r"\.vite/").unwrap(),
65            Regex::new(r"\.turbo/").unwrap(),
66            Regex::new(r"\.swc/").unwrap(),
67            Regex::new(r"\.esbuild/").unwrap(),
68            
69            // Testing caches
70            Regex::new(r"\.jest/").unwrap(),
71            Regex::new(r"\.vitest/").unwrap(),
72            Regex::new(r"\.playwright/").unwrap(),
73            Regex::new(r"\.cypress/").unwrap(),
74            
75            // Framework specific caches
76            Regex::new(r"\.angular/").unwrap(),
77            Regex::new(r"\.ember-cli/").unwrap(),
78            Regex::new(r"\.storybook-cache/").unwrap(),
79            
80            // Linting and formatting caches
81            Regex::new(r"\.eslintcache").unwrap(),
82            Regex::new(r"\.prettiercache").unwrap(),
83            Regex::new(r"\.stylelintcache").unwrap(),
84        ];
85
86        let extensions = vec![
87            // HTML variants
88            "html".to_string(), "htm".to_string(), "xhtml".to_string(),
89            "shtml".to_string(), "dhtml".to_string(),
90            
91            // CSS and preprocessors
92            "css".to_string(), "scss".to_string(), "sass".to_string(),
93            "less".to_string(), "styl".to_string(), "stylus".to_string(),
94            
95            // Modern web frameworks
96            "vue".to_string(), "svelte".to_string(), "astro".to_string(),
97            "lit".to_string(), "riot".to_string(),
98            
99            // Template engines
100            "ejs".to_string(), "hbs".to_string(), "handlebars".to_string(),
101            "mustache".to_string(), "pug".to_string(), "jade".to_string(),
102            "twig".to_string(), "liquid".to_string(), "nunjucks".to_string(),
103            
104            // Web components
105            "webmanifest".to_string(), "webapp".to_string(),
106            
107            // Modern web formats
108            "mjs".to_string(), "cjs".to_string(),
109            "wasm".to_string(), "wat".to_string(),
110            
111            // Web graphics
112            "svg".to_string(),
113        ];
114
115        Self {
116            external_patterns,
117            cache_patterns,
118            extensions,
119        }
120    }
121
122    pub fn get_external_patterns(&self) -> &[Regex] {
123        &self.external_patterns
124    }
125
126    pub fn get_cache_patterns(&self) -> &[Regex] {
127        &self.cache_patterns
128    }
129
130    pub fn get_extensions(&self) -> &[String] {
131        &self.extensions
132    }
133
134    pub fn get_script_names() -> Vec<&'static str> {
135        vec![
136            // HTML entry points
137            "index.html", "index.htm", "default.html", "main.html",
138            
139            // Build tools and bundlers
140            "webpack.config.js", "webpack.config.ts", "webpack.config.mjs",
141            "rollup.config.js", "rollup.config.ts", "rollup.config.mjs",
142            "vite.config.js", "vite.config.ts", "vite.config.mjs",
143            "esbuild.config.js", "esbuild.config.mjs",
144            "parcel.config.js", "parcel.config.json",
145            
146            // CSS tools
147            "postcss.config.js", "postcss.config.mjs", "postcss.config.json",
148            "tailwind.config.js", "tailwind.config.ts", "tailwind.config.mjs",
149            "unocss.config.js", "unocss.config.ts",
150            "windicss.config.js", "windicss.config.ts",
151            
152            // Linting and formatting
153            ".stylelintrc", ".stylelintrc.js", ".stylelintrc.json",
154            ".postcssrc", ".postcssrc.js", ".postcssrc.json",
155            "browserslist", ".browserslistrc",
156            
157            // Framework configs
158            "next.config.js", "next.config.mjs", "next.config.ts",
159            "nuxt.config.js", "nuxt.config.ts",
160            "gatsby.config.js", "gatsby.config.ts",
161            "svelte.config.js", "svelte.config.ts",
162            "astro.config.js", "astro.config.ts", "astro.config.mjs",
163            "remix.config.js", "remix.config.ts",
164            "angular.json", ".angular-cli.json",
165            "ember-cli-build.js",
166            
167            // Testing
168            "jest.config.js", "jest.config.ts", "jest.config.mjs",
169            "vitest.config.js", "vitest.config.ts", "vitest.config.mjs",
170            "playwright.config.js", "playwright.config.ts",
171            "cypress.config.js", "cypress.config.ts",
172            "karma.conf.js", "karma.conf.ts",
173            
174            // Storybook
175            ".storybook/main.js", ".storybook/main.ts",
176            "storybook.config.js", "storybook.config.ts",
177            
178            // Web app manifests
179            "manifest.json", "manifest.webmanifest",
180            "browserconfig.xml", "site.webmanifest",
181            
182            // Service workers
183            "sw.js", "service-worker.js", "workbox-config.js",
184            
185            // Development servers
186            "serve.json", "static.json", "now.json", "vercel.json",
187            "netlify.toml", "_redirects", "_headers",
188            
189            // Modern web standards
190            "web.config", ".htaccess", "robots.txt", "sitemap.xml",
191        ]
192    }
193}