Skip to content

Commit

Permalink
moved script generation to vitepress config resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Apr 10, 2024
1 parent 8d2ceb0 commit 6ebefba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
11 changes: 9 additions & 2 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { readPackageJSON } from 'pkg-types'
import consola from 'consola'
import { sidebar } from './sidebar.config'
import { navigation } from './navigation.config'

// @unocss-include
import { generateWebClientDocs } from './scripts/web-client'
import { generateRpcDocs } from './scripts/rpc-docs'

// https://vitepress.dev/reference/site-config
export default async () => {
Expand All @@ -17,6 +17,9 @@ export default async () => {
const base = isProduction ? '/developers' : '/developer-center/'
consola.info(`Building for ${isProduction ? 'production' : 'development'}. The base URL is ${base}`)

await generateWebClientDocs()
const { specUrl, specVersion } = await generateRpcDocs()

return defineConfig({
base,
title,
Expand Down Expand Up @@ -66,6 +69,10 @@ export default async () => {
},

vite: {
define: {
__ALBATROSS_RPC_OPENRPC_URL__: JSON.stringify(specUrl),
__ALBATROSS_RPC_OPENRPC_VERSION__: JSON.stringify(specVersion),
},
configFile: '.vitepress/vite.config.ts',
},

Expand Down
9 changes: 4 additions & 5 deletions .vitepress/scripts/web-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { execSync } from 'node:child_process'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { consola } from 'consola'
import { readPackageJSON } from 'pkg-types'

export async function generateWebClientDocs() {
// Read installed package version of @nimiq/core-web
const packageVersion = JSON.parse(readFileSync(join(__dirname, '../../node_modules/@nimiq/core-web/package.json'), 'utf-8')).version as string
const packageVersion = await readPackageJSON(join(__dirname, '../../node_modules/@nimiq/core-web')).then(pkg => pkg.version)

// Read package version of generated docs, if already built
const versionFile = join(__dirname, '../../build/web-client/.version')
Expand All @@ -22,12 +22,11 @@ export async function generateWebClientDocs() {
// Rebuild docs

consola.info(`Generating Web-Client docs ${packageVersion} ...`)
execSync('pnpm run build:web-client', { stdio: 'inherit' })
execSync('pnpm run build:web-client && echo "Done"', { stdio: 'inherit' })
consola.log('done 2')

// Update entry file with frontmatter to disable the "next" footer button
const entryFile = join(__dirname, '../../build/web-client/index.md')
consola.info(`Web-Client docs entry file: ${entryFile}`)

let entryFileContent = readFileSync(entryFile, 'utf-8')
entryFileContent = `---\ndocFooter: false\n---\n${entryFileContent}`
writeFileSync(entryFile, entryFileContent)
Expand Down
8 changes: 1 addition & 7 deletions .vitepress/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ import { postcssIsolateStyles } from 'vitepress'
import { consola } from 'consola'
import { version } from '../package.json'
import { getGitStats } from './scripts/git-stats'
import { generateWebClientDocs } from './scripts/web-client'
import { generateRpcDocs } from './scripts/rpc-docs'

export default defineConfig(async () => {
const { specUrl, specVersion } = await generateRpcDocs()
await generateWebClientDocs()

const environment = env.DEPLOYMENT_MODE
consola.info(`Building for ${environment}`)

Expand All @@ -39,8 +34,7 @@ export default defineConfig(async () => {
__DEVELOPER_CENTER_VERSION__: JSON.stringify(version),
__BUILD_ENVIRONMENT__: JSON.stringify(environment),
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
__ALBATROSS_RPC_OPENRPC_URL__: JSON.stringify(specUrl),
__ALBATROSS_RPC_OPENRPC_VERSION__: JSON.stringify(specVersion),

},

plugins: [
Expand Down

0 comments on commit 6ebefba

Please sign in to comment.