forked from citizenfx/natives
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const rootFolders = fs.readdirSync('./', { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name); | ||
|
||
// Define an array of directories to exclude | ||
const excludedDirectories = ['.git', '.github', '.ci']; | ||
const errors = []; | ||
|
||
const processFile = (filePath) => { | ||
if (!fs.existsSync(filePath)) { | ||
console.log(`File does not exist: ${filePath}`); | ||
return; | ||
} | ||
// List all directories at the project root, excluding specific directories | ||
const rootFolders = fs.readdirSync('./', { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory() && !excludedDirectories.includes(dirent.name)) | ||
.map(dirent => dirent.name); // Map to directory names | ||
|
||
const errors = []; // Collects errors instead of immediately exiting the process. | ||
|
||
const checkFile = (filePath) => { | ||
const content = fs.readFileSync(filePath, 'utf8'); | ||
const nsHeaderRegex = /---\nns: (.*)\n/m; | ||
const nsMatch = content.match(nsHeaderRegex); | ||
|
||
if (!nsMatch) { | ||
errors.push(`Invalid or missing 'ns' header in ${filePath}`); | ||
return; | ||
return; // Continue to next file instead of exiting. | ||
} | ||
|
||
const nsValue = nsMatch[1].trim(); | ||
|
||
if (!rootFolders.includes(nsValue)) { | ||
// Report error if ns doesn't exist as a directory | ||
errors.push(`The namespace '${nsValue}' specified in ${filePath} does not exist as a directory in the project.`); | ||
} else { | ||
const folderName = path.basename(path.dirname(filePath)); | ||
if (nsValue !== folderName) { | ||
// Report error if file is in the wrong directory based on ns | ||
errors.push(`The file \`${path.basename(filePath)}\` is located in the '${folderName}' directory but should be in '${nsValue}' (based on the ns).`); | ||
} | ||
} | ||
}; | ||
|
||
const main = () => { | ||
const files = process.argv.slice(2).join(' ').split(' '); | ||
files.forEach(file => { | ||
const processFiles = (files) => { | ||
files.forEach((file) => { | ||
const normalizedFile = path.normalize(file); | ||
const directoryName = path.dirname(normalizedFile); | ||
|
||
// Skip if in an excluded directory or is README.md | ||
if (excludedDirectories.includes(directoryName) || path.basename(normalizedFile) === 'README.md') { | ||
return; | ||
if (excludedDirectories.includes(path.basename(path.dirname(normalizedFile))) || path.basename(normalizedFile) === 'README.md') { | ||
console.log(`Ignoring file: ${file}`); | ||
return; // Skip this file | ||
} | ||
|
||
processFile(normalizedFile); | ||
console.log(file); | ||
checkFile(normalizedFile); | ||
}); | ||
|
||
if (errors.length > 0) { | ||
console.error("Errors found:\n" + errors.join("\n")); | ||
process.exit(1); | ||
} else { | ||
console.log("No errors found."); | ||
} | ||
}; | ||
|
||
main(); | ||
const files = process.argv.slice(2); | ||
processFiles(files); | ||
|
||
if (errors.length > 0) { | ||
console.error("Errors found:\n" + errors.join("\n")); | ||
process.exit(1); | ||
} else { | ||
console.log("No errors found."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters