Skip to content
Draft
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
25 changes: 24 additions & 1 deletion scripts/validate-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* find ./gaps -maxdepth 1 -type d -name 'GAP-*' | xargs -I{} node scripts/validate-structure.js {}
*/

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

function validateAllowedFiles(dirPath, gapName) {
const entries = readdirSync(dirPath);
for (const entry of entries) {
const fullPath = join(dirPath, entry);
if (statSync(fullPath).isDirectory()) {
error(
gapName,
`Unexpected directory "${entry}" found. GAP directories may only contain *.md files and metadata.yml. If you believe this is in error, please ping @graphql/gaps-editors.`,
);
}
if (entry === "metadata.yml" || entry.endsWith(".md")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& not startsWith “.”

continue;
}
error(
gapName,
`Unexpected file "${entry}" found. GAP directories may only contain *.md files and metadata.yml. If you believe this is in error, please ping @graphql/gaps-editors.`,
);
}
}

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

Expand All @@ -137,6 +157,9 @@ function main() {
// Validate directory naming
const gapName = validateDirectoryNaming(dirPath);

// Validate only allowed files are present
validateAllowedFiles(dirPath, gapName);

// Validate README.md exists
validateReadmeExists(dirPath, gapName);

Expand Down
Loading