-
Notifications
You must be signed in to change notification settings - Fork 8
big refactor of resources structure #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e82b93d
refactor: Improve pricing in schema
bristermitten 936cbb7
refactor: Improve file structure
bristermitten f1aee92
feat: Setup TS scema
bristermitten e905b58
chore: Update VSCode Config to apply schema to new file structure
bristermitten 4499178
feat: Add Zod-generated JSON schema and meta field
bristermitten cb0a687
start moving to new improved schema
bristermitten ea393e7
ci: Make yaml action run on any branch
bristermitten 5a5067c
start refactoring to new resources format
bristermitten 6a09cd0
refactor: Big refactor of file structure and separate schemas
bristermitten 03260c9
feat: add database compilation script
bristermitten 75a116e
ci: Update GH action versio
bristermitten 82ab39e
feat: better schemas
bristermitten d74d321
ci: update validate action
bristermitten ab36710
Merge branch 'master' into feat/improvements
bristermitten e66c635
chore: remove trailing comma
bristermitten f583372
Potential fix for pull request finding
bristermitten 7572143
Potential fix for pull request finding
bristermitten 6310b71
refactor: make schemas strict
bristermitten 1590718
build: improve vscode config
bristermitten c0e1352
fix: improve cli
bristermitten b9adea8
build: fix gen-database command
bristermitten a78c9b0
fix: fix the gen-database script again
bristermitten 0d0ab35
fix: make compile-database deterministic
bristermitten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # dependencies (bun install) | ||
| node_modules | ||
|
|
||
| # output | ||
| out | ||
| dist | ||
| *.tgz | ||
|
|
||
| # code coverage | ||
| coverage | ||
| *.lcov | ||
|
|
||
| # logs | ||
| logs | ||
| _.log | ||
| report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # caches | ||
| .eslintcache | ||
| .cache | ||
| *.tsbuildinfo | ||
|
|
||
| # IntelliJ based IDEs | ||
| .idea | ||
|
|
||
| # Finder (MacOS) folder config | ||
| .DS_Store |
This file contains hidden or 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,6 +1,7 @@ | ||
| { | ||
| "yaml.schemas": { | ||
| // apply schema to all resources | ||
| "resource.schema.json": "resources/*.yaml" | ||
| } | ||
| } | ||
| "yaml.schemas": { | ||
| "resource.schema.jsonc": "resources/**/*.yaml", | ||
| "metadata.schema.jsonc": "metadata/**/*.yaml", | ||
| "database.schema.jsonc": "database.json" | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/2.4.15/schema.json", | ||
| "vcs": { | ||
| "enabled": true, | ||
| "clientKind": "git", | ||
| "useIgnoreFile": true | ||
| }, | ||
| "files": { | ||
| "ignoreUnknown": false | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "tab" | ||
| }, | ||
| "linter": { | ||
| "enabled": true, | ||
| "rules": { | ||
| "recommended": true | ||
| } | ||
| }, | ||
| "javascript": { | ||
| "formatter": { | ||
| "quoteStyle": "double" | ||
| } | ||
| }, | ||
| "assist": { | ||
| "enabled": true, | ||
| "actions": { | ||
| "source": { | ||
| "organizeImports": "on" | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import path from "path"; | ||
| import fs from "fs"; | ||
| import { readdir } from "node:fs/promises"; | ||
| import { DatabaseSchema, MetaSchema, ResourceSchema, type Database, type Meta, type Resource } from "."; | ||
| import { YAML } from "bun"; | ||
|
|
||
| type DatabaseMetadata = { | ||
| id: string; | ||
| } & Meta | ||
|
|
||
|
|
||
| async function buildDatabase() { | ||
| const metaDir = path.join(__dirname, "./metadata"); | ||
| const resourcesDir = path.join(__dirname, "./resources"); | ||
|
|
||
| const allMetaFiles = (await readdir(metaDir, { recursive: true, })).toSorted(); | ||
| const allResourceFiles = (await readdir(resourcesDir, { recursive: true, })).toSorted(); | ||
|
|
||
| const database = { | ||
| metadata: [] as DatabaseMetadata[], | ||
| resources: [] as Resource[] | ||
| } satisfies Database; | ||
| let hasErrors = false; | ||
|
|
||
| for (const file of allMetaFiles.filter(f => f.endsWith(".yaml"))) { | ||
| const filePath = path.join(metaDir, file); | ||
| const fileContent = await fs.promises.readFile(filePath, "utf-8"); | ||
|
|
||
| const entityId = path.basename(file, ".yaml"); | ||
|
|
||
| const data = YAML.parse(fileContent); | ||
| const result = MetaSchema.safeParse(data); | ||
|
|
||
| if (!result.success) { | ||
| console.error(`Validation Error in Metadata: ${file}`); | ||
| console.error(result.error.issues); | ||
| hasErrors = true; | ||
| } else { | ||
| database.metadata.push({ id: entityId, ...result.data }); | ||
| } | ||
| } | ||
|
|
||
| const validTags = new Set(database.metadata.map(meta => meta.id)); | ||
|
|
||
| for (const file of allResourceFiles.filter(f => f.endsWith(".yaml"))) { | ||
| const filePath = path.join(resourcesDir, file); | ||
| const fileContent = await fs.promises.readFile(filePath, "utf-8"); | ||
|
|
||
| const data = YAML.parse(fileContent); | ||
| const result = ResourceSchema.safeParse(data); | ||
|
|
||
| if (!result.success) { | ||
| console.error(`Validation Error in Resource: ${file}`); | ||
| console.error(result.error.issues); | ||
| hasErrors = true; | ||
| continue; | ||
| } | ||
|
|
||
| const invalidTags = result.data.teaches.filter(tag => !validTags.has(tag)); | ||
| if (invalidTags.length > 0) { | ||
| console.error(`Relational Error in Resource: ${file}`); | ||
| console.error(`Unknown tags in 'teaches': [${invalidTags.join(", ")}]`); | ||
| console.error(`Ensure a corresponding metadata file exists.`); | ||
| hasErrors = true; | ||
| continue; | ||
| } | ||
|
|
||
| database.resources.push(result.data); | ||
| } | ||
|
|
||
| if (hasErrors) { | ||
| console.error("Build failed due to validation errors."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // verify the entire database against the schema before writing | ||
| const finalResult = DatabaseSchema.safeParse(database); | ||
| if (!finalResult.success) { | ||
| console.error("Final Database Validation Error:"); | ||
| console.error(finalResult.error.issues); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const outputPath = path.join(__dirname, "./database.json"); | ||
| await fs.promises.writeFile(outputPath, JSON.stringify(database, null, 2)); | ||
|
|
||
| console.log(`Success! Compiled ${database.metadata.length} entities and ${database.resources.length} resources.`); | ||
| } | ||
|
|
||
| buildDatabase().catch(err => { | ||
| console.error("Unexpected error during build:", err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.