feat: fetch from local when developing or CI build

This commit is contained in:
iCrawl
2022-08-15 19:13:01 +02:00
parent 35e79b389d
commit 5f42b5af30
5 changed files with 36 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ jobs:
env: env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
NEXT_PUBLIC_LOCAL_DEV: true
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3

View File

@@ -0,0 +1 @@
NEXT_PUBLIC_LOCAL_DEV=true

View File

@@ -5,10 +5,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"test": "vitest run", "test": "vitest run",
"build": "yarn build:css && yarn build:next", "build": "is-ci && yarn build:ci || yarn build:prod",
"build:ci": "yarn run --top-level docs && yarn build:prod",
"build:prod": "yarn build:css && yarn build:next",
"build:next": "next build", "build:next": "next build",
"build:css": "yarn generate:css", "build:css": "yarn generate:css",
"dev": "concurrently 'yarn dev:css' 'yarn dev:next'", "dev": "yarn run --top-level docs && concurrently 'yarn dev:css' 'yarn dev:next'",
"dev:next": "next dev", "dev:next": "next dev",
"dev:css": "yarn generate:css --watch", "dev:css": "yarn generate:css --watch",
"generate:css": "unocss 'src/**/*.tsx' --out-file ./src/styles/unocss.css", "generate:css": "unocss 'src/**/*.tsx' --out-file ./src/styles/unocss.css",
@@ -88,6 +90,7 @@
"eslint-plugin-react": "^7.30.1", "eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"happy-dom": "^6.0.4", "happy-dom": "^6.0.4",
"is-ci": "^3.0.1",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"typescript": "^4.7.4", "typescript": "^4.7.4",
"unocss": "^0.45.6", "unocss": "^0.45.6",

View File

@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/no-throw-literal */ /* eslint-disable @typescript-eslint/no-throw-literal */
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { Box } from '@mantine/core'; import { Box } from '@mantine/core';
import { ApiFunction } from '@microsoft/api-extractor-model'; import { ApiFunction } from '@microsoft/api-extractor-model';
import type { GetStaticPaths, GetStaticProps } from 'next/types'; import type { GetStaticPaths, GetStaticProps } from 'next/types';
@@ -27,9 +29,19 @@ export const getStaticPaths: GetStaticPaths = async () => {
await Promise.all( await Promise.all(
packages.map(async (packageName) => { packages.map(async (packageName) => {
try { try {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/main.api.json`); let data;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
const data = await res.json(); const res = await readFile(
join(__dirname, '..', '..', '..', '..', '..', packageName, 'docs', 'docs.api.json'),
'utf-8',
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = JSON.parse(res);
} else {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/main.api.json`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = await res.json();
}
const model = createApiModel(data); const model = createApiModel(data);
const pkg = findPackage(model, packageName); const pkg = findPackage(model, packageName);
@@ -71,9 +83,19 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
const [memberName, overloadIndex] = member.split(':') as [string, string | undefined]; const [memberName, overloadIndex] = member.split(':') as [string, string | undefined];
try { try {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${branchName}.api.json`); let data;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
const data = await res.json(); const res = await readFile(
join(__dirname, '..', '..', '..', '..', '..', packageName, 'docs', 'docs.api.json'),
'utf-8',
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = JSON.parse(res);
} else {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${branchName}.api.json`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = await res.json();
}
const model = createApiModel(data); const model = createApiModel(data);
const pkg = findPackage(model, packageName); const pkg = findPackage(model, packageName);

View File

@@ -2007,6 +2007,7 @@ __metadata:
eslint-plugin-react: ^7.30.1 eslint-plugin-react: ^7.30.1
eslint-plugin-react-hooks: ^4.6.0 eslint-plugin-react-hooks: ^4.6.0
happy-dom: ^6.0.4 happy-dom: ^6.0.4
is-ci: ^3.0.1
next: ^12.2.5 next: ^12.2.5
prettier: ^2.7.1 prettier: ^2.7.1
react: ^18.2.0 react: ^18.2.0