|
| 1 | +import { globby } from 'globby'; |
| 2 | +import { readFile } from 'node:fs/promises'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | +import { resolve } from 'node:path'; |
| 5 | + |
| 6 | +const currentDir = fileURLToPath(import.meta.url); |
| 7 | +const FORBIDDEN = [ |
| 8 | + /** |
| 9 | + * import.meta.env is not a platform standard |
| 10 | + */ |
| 11 | + 'import.meta.env', |
| 12 | + /** |
| 13 | + * These variables are wrapped around code for this repo only |
| 14 | + */ |
| 15 | + 'VM_LOCAL', |
| 16 | + /** |
| 17 | + * These are for local VM debugging and development, and are not meant to make it to real code |
| 18 | + */ |
| 19 | + 'check(', |
| 20 | + 'CheckInterface', |
| 21 | + 'CheckOr', |
| 22 | + 'CheckFunction', |
| 23 | + 'CheckObject', |
| 24 | +]; |
| 25 | + |
| 26 | +const IGNORED_DIRS = [`@glimmer/syntax`, `@glimmer/debug`]; |
| 27 | + |
| 28 | +let files = await globby(resolve(currentDir, '../../packages/**/dist/**/index.js'), { |
| 29 | + ignore: ['node_modules', '**/node_modules'], |
| 30 | +}); |
| 31 | + |
| 32 | +files = files.filter((file) => !IGNORED_DIRS.some((dir) => file.includes(dir))); |
| 33 | + |
| 34 | +let errors = []; |
| 35 | + |
| 36 | +console.log(`Found ${files.length} files to check...`); |
| 37 | + |
| 38 | +for (let filePath of files) { |
| 39 | + console.log(`Checking ${filePath}...`); |
| 40 | + let file = await readFile(filePath); |
| 41 | + let content = file.toString(); |
| 42 | + |
| 43 | + for (let searchFor of FORBIDDEN) { |
| 44 | + if (content.includes(searchFor)) { |
| 45 | + errors.push({ filePath, found: searchFor }); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +if (errors.length > 0) { |
| 51 | + console.error(errors); |
| 52 | + throw new Error(`The forbidden texts were encountered in the above files`); |
| 53 | +} |
| 54 | + |
| 55 | +console.info('No forbidden texts!'); |
0 commit comments