-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from plezanje-net/prebuildGrades
Add a prebuild script to fetch all gradingsystems
- Loading branch information
Showing
3 changed files
with
61 additions
and
1,799 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pkg from "@next/env"; | ||
const { loadEnvConfig } = pkg; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
console.log("Fetching all grading systems from server..."); | ||
|
||
loadEnvConfig(process.cwd()); | ||
|
||
const fullFilePath = path.join( | ||
process.cwd(), | ||
"src/utils", | ||
"grading-systems.ts" | ||
); | ||
|
||
const url = process.env.NEXT_PUBLIC_API_URL; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
query: `{ | ||
gradingSystems { | ||
name | ||
id | ||
grades { | ||
difficulty | ||
name | ||
id | ||
__typename | ||
} | ||
routeTypes { | ||
id | ||
name | ||
__typename | ||
} | ||
__typename | ||
} | ||
}`, | ||
}), | ||
}); | ||
|
||
const data = await response.json(); | ||
|
||
fs.writeFileSync( | ||
fullFilePath, | ||
"/* This is an auto-generated file. */\n" + | ||
"export const gradingSystems = " + | ||
JSON.stringify(data.data.gradingSystems) | ||
); | ||
|
||
console.log("All grading systems stored into " + fullFilePath); |
Oops, something went wrong.