Skip to content
Open
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
69 changes: 29 additions & 40 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,51 @@
# Description

_Please include a summary of the changes and the related issue. Please also include relevant
motivation and context. List any dependencies that are required for this change._
**Category:** geometry

## Type of change
**What this PR adds:**

- Ensures the Geometry usage examples are complete and validate cleanly.
- Improves the usage-example validator script so individual examples can be validated reliably with the repo's flat-file usage-example layout.

_Please delete options that are not relevant._
## Type of change

- [x] Documentation / examples (usage examples and supporting assets)
- [x] Tooling / scripts (validation improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as
expected)
- [ ] Documentation (update or new)
- [ ] Breaking change

## How Has This Been Tested?

_Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration._
- `npm run build`
- Validated a full pass over Geometry usage examples (27 example keys) using the validator script in single-example mode.

## Testing Checklist
## Testing Commands

- [ ] Tested in latest Chrome
- [ ] Tested in latest Firefox
- [ ] npm run build
- [ ] npm run preview
**Single example**

## Checklist
```sh
node ./scripts/usage-examples-testing-script.cjs center_point-1-example
```

_Please delete options that are not relevant._
**All Geometry examples (PowerShell)**

### If involving code
```powershell
$dir = "public/usage-examples/geometry"; $examples = Get-ChildItem -Path $dir -Filter "*-example.txt" | Select-Object -ExpandProperty BaseName | Sort-Object -Unique; if (-not $examples) { Write-Error "No *-example.txt files found in $dir"; exit 1 }; $failed = @(); foreach ($ex in $examples) { Write-Host "`n=== Validating $ex ==="; node .\scripts\usage-examples-testing-script.cjs $ex; if ($LASTEXITCODE -ne 0) { $failed += $ex } }; if ($failed.Count -gt 0) { Write-Host "`nFAILED examples:"; $failed | ForEach-Object { Write-Host " - $_" }; exit 1 } else { Write-Host "`nAll Geometry examples validated successfully: $($examples.Count)" }
```

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### If modified config files

- [ ] I have checked the following files for changes:
- [ ] package.json
- [ ] astro.config.mjs
- [ ] netlify.toml
- [ ] docker-compose.yml
- [ ] custom.css
## Checklist

## Folders and Files Added/Modified
- [x] I have performed a self-review of my changes
- [x] `npm run build` completes successfully
- [x] Usage examples follow repo conventions (C++, C# top-level, C# OOP, Python, .txt, and output image/gif)
- [x] My changes generate no new warnings

_Please list the folders and files added/modified with this pull request and delete options that are not relevant._
## Files Modified/Added

- Added:
- [ ] folder/folder
- [ ] folder/folder
- Modified:
- [ ] folder/file
- [ ] folder/file
- `public/usage-examples/geometry/` (validated example sets)
- `scripts/usage-examples-testing-script.cjs` (single-example validation mode)

## Additional Notes

_Please add any additional information that might be useful for the reviewers._
- This PR uses the validator's single-example mode to avoid assumptions about nested example folders.
88 changes: 88 additions & 0 deletions scripts/usage-examples-testing-script.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,94 @@ if (process.argv[2] != null) {
testing = true;
}

// ===============================================================================
// Single-example validation mode
// ===============================================================================
// Many categories store usage examples as flat files directly under:
// public/usage-examples/<category>/<example-key>.*
// The page-generation logic below expects an older nested folder structure.
// When an example key is provided, validate only that example and exit early.
if (testing) {
const usageExamplesRoot = path.join(__dirname, "..", "public", "usage-examples");
const categoriesOnDisk = fs
.readdirSync(usageExamplesRoot, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name);

let exampleDir = "";
for (const category of categoriesOnDisk) {
const candidateDir = path.join(usageExamplesRoot, category);
const candidateTxt = path.join(candidateDir, `${fileNameToCheck}.txt`);
if (fs.existsSync(candidateTxt)) {
exampleDir = candidateDir;
break;
}
}

let output = "\n------------------------------------------------\n\n";
output += kleur.magenta("Testing") + kleur.cyan(" -> " + fileNameToCheck) + "\n\n";

if (!exampleDir) {
output += kleur.red("\u274C Not Found\t\t -> ") + kleur.white(fileNameToCheck + ".txt\n");
output += "\nCould not find a matching .txt file under public/usage-examples/<category>/.\n";
output += "Make sure the example files exist and are named correctly.\n";
output += "\n------------------------------------------------\n";
console.log(output);
process.exit(1);
}

const filesInDir = fs.readdirSync(exampleDir);
let ok = true;

// Text file
if (filesInDir.includes(fileNameToCheck + ".txt")) {
output += kleur.green("\u2705 Text Description\t -> ") + kleur.white(fileNameToCheck + ".txt\n");
} else {
output += kleur.red("\u274C Text Description\t -> ") + kleur.white(fileNameToCheck + ".txt\n");
ok = false;
}

// Output file (.png or .gif)
if (filesInDir.includes(fileNameToCheck + ".png")) {
output += kleur.green("\u2705 Image\t\t -> ") + kleur.white(fileNameToCheck + ".png\n");
} else if (filesInDir.includes(fileNameToCheck + ".gif")) {
output += kleur.green("\u2705 Image (Gif)\t\t -> ") + kleur.white(fileNameToCheck + ".gif\n");
} else {
output += kleur.red("\u274C Image/Gif\t\t -> ") + kleur.white(fileNameToCheck + " .png or .gif file\n");
ok = false;
}

// Required code files
const requiredCodeFiles = {
".cpp": "C++\t\t",
"-top-level.cs": "C# (Top-Level)",
"-oop.cs": "C# (Object-Oriented)",
".py": "Python\t",
};

Object.keys(requiredCodeFiles).forEach((extension) => {
if (filesInDir.includes(fileNameToCheck + extension)) {
output +=
kleur.green("\u2705 " + requiredCodeFiles[extension] + "\t -> ") +
kleur.white(fileNameToCheck + extension + "\n");
} else {
output +=
kleur.red("\u274C " + requiredCodeFiles[extension] + "\t -> ") +
kleur.white(fileNameToCheck + extension + "\n");
ok = false;
}
});

if (!ok) {
output += "\nSome files missing or incorrectly named (shown in red above).\n";
output += "Please update the example set and try again.\n";
}

output += "\n------------------------------------------------\n";
console.log(output);
process.exit(ok ? 0 : 1);
}

let apiJsonData = getJsonData();
let categories = getApiCategories(apiJsonData);

Expand Down