You've already forked AstralRinth
forked from didirus/AstralRinth
Create send function for API requests
This commit is contained in:
@@ -3,6 +3,7 @@ import { landingPage } from './outputs/landingPage.js'
|
||||
import { projectColors } from './outputs/projectColors.js'
|
||||
import { gameVersions } from './outputs/gameVersions.js'
|
||||
import { tags } from './outputs/tags.js'
|
||||
import { openapi } from './outputs/openapi.js'
|
||||
|
||||
const API_URL =
|
||||
process.env.VITE_API_URL && process.env.VITE_API_URL === 'https://staging-api.modrinth.com/v2/'
|
||||
@@ -25,6 +26,7 @@ const TTL = 7 * 24 * 60 * 60 * 1000
|
||||
* @param {boolean} options.landingPage
|
||||
* @param {boolean} options.gameVersions
|
||||
* @param {boolean} options.tags
|
||||
* @param {boolean} options.openapi
|
||||
* @returns {PluginResult}
|
||||
*/
|
||||
export default function Generator(options) {
|
||||
@@ -57,6 +59,7 @@ export default function Generator(options) {
|
||||
if (options.tags) await tags(API_URL)
|
||||
if (options.landingPage) await landingPage(API_URL)
|
||||
if (options.gameVersions) await gameVersions(API_URL)
|
||||
if (options.openapi) await openapi(API_URL)
|
||||
if (options.projectColors) await projectColors(API_URL)
|
||||
},
|
||||
}
|
||||
|
||||
22
src/plugins/generator/outputs/openapi.js
Normal file
22
src/plugins/generator/outputs/openapi.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import cliProgress from 'cli-progress'
|
||||
import openapiTS from 'openapi-typescript'
|
||||
|
||||
export async function openapi() {
|
||||
const progressBar = new cliProgress.SingleBar({
|
||||
format: 'Generating openapi types | {bar} | {percentage}%',
|
||||
barCompleteChar: '\u2588',
|
||||
barIncompleteChar: '\u2591',
|
||||
hideCursor: true,
|
||||
})
|
||||
progressBar.start(2, 0)
|
||||
|
||||
const output = await openapiTS('https://docs.modrinth.com/redocusaurus/plugin-redoc-0.yaml')
|
||||
progressBar.increment()
|
||||
|
||||
// Write JSON file
|
||||
await fs.writeFile('./generated/openapi.ts', output)
|
||||
progressBar.increment()
|
||||
|
||||
progressBar.stop()
|
||||
}
|
||||
Reference in New Issue
Block a user