Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"suggest:format": "echo \"\nTo resolve this, run: $(tput bold)npm run format$(tput sgr0)\" && exit 1",
"test:format": "prettier --check . || npm run suggest:format",
"test:spelling": "cspell \"spec/**/*.md\" README.md LICENSE.md",
"test:structure": "find . -type d -name 'GAP-*' -exec ./scripts/validate-structure.js {} \\;"
"test:structure": "./scripts/validate-structure.js"
},
"devDependencies": {
"ajv": "^8.17.1",
Expand Down
55 changes: 42 additions & 13 deletions scripts/validate-structure.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node

/**
* Validates the structure of a GAP directory.
* Validates the structure of GAP directories.
*
* Usage: ./scripts/validate-structure.js <gap-directory>
* Usage: ./scripts/validate-structure.js [gap-directory]
*
* Can be xarg'd over all GAP directories:
* find . -maxdepth 1 -type d -name 'GAP-*' | xargs -I{} node scripts/validate-structure.js {}
* If no directory is provided, automatically discovers and validates all GAP-* directories
* in the repository root.
*/

import { existsSync, readFileSync, statSync } from "node:fs";
import { existsSync, readFileSync, statSync, readdirSync } from "node:fs";
import { basename, join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { parseArgs } from "node:util";
Expand Down Expand Up @@ -122,16 +122,16 @@ function validateMetadata(dirPath, gapName) {
}
}

function main() {
const { positionals } = parseArgs({ allowPositionals: true, strict: true });

if (positionals.length !== 1) {
console.error("Usage: ./scripts/validate-structure.js <gap-directory>");
process.exit(1);
}
function discoverGapDirectories() {
const rootDir = join(__dirname, "..");
const entries = readdirSync(rootDir, { withFileTypes: true });

const dirPath = positionals[0];
return entries
.filter((entry) => entry.isDirectory() && /^GAP-/.test(entry.name))
.map((entry) => join(rootDir, entry.name));
}

function validateGapDirectory(dirPath) {
if (!existsSync(dirPath)) {
console.error(`Directory does not exist: ${dirPath}`);
process.exit(1);
Expand All @@ -150,6 +150,35 @@ function main() {

// Validate metadata.yml
validateMetadata(dirPath, gapName);

console.log(`✓ ${gapName} validated successfully`);
}

function main() {
const { positionals } = parseArgs({ allowPositionals: true, strict: true });

if (positionals.length === 0) {
// No arguments provided - discover and validate all GAP directories
const gapDirs = discoverGapDirectories();

if (gapDirs.length === 0) {
console.error("No GAP directories found");
process.exit(1);
}

console.log(`Found ${gapDirs.length} GAP director${gapDirs.length === 1 ? "y" : "ies"}`);

for (const dir of gapDirs) {
validateGapDirectory(dir);
}
} else if (positionals.length === 1) {
// Single directory provided - validate it
const dirPath = positionals[0];
validateGapDirectory(dirPath);
} else {
console.error("Usage: ./scripts/validate-structure.js [gap-directory]");
process.exit(1);
}
}

main();