Skip to content

Commit 9571fbc

Browse files
committed
fix: support native nextra compoents
1 parent f25f3e6 commit 9571fbc

File tree

15 files changed

+93
-211
lines changed

15 files changed

+93
-211
lines changed

apps/book-server/books/base/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
"next": "14.2.1",
1414
"nextra": "2.13.4",
1515
"nextra-theme-docs": "2.13.4",
16+
"prettier": "3.2.5",
1617
"react": "18",
1718
"react-dom": "18"
19+
},
20+
"devDependencies": {
21+
"@types/node": "20.12.5",
22+
"@types/react": "18",
23+
"@types/react-dom": "18",
24+
"typescript": "5"
1825
}
1926
}

apps/book-server/src/common/errors/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export { BadRequestError } from './BadRequestErrors.mjs'
22
export { ConfilctError } from './ConfilctError.mjs'
33
export { ForbiddenError } from './ForbiddenError.mjs'
44
export { HttpError, isHttpError } from './HttpError.mjs'
5-
export { NotFoundError } from './NotfoundError.mjs'
5+
export { NotFoundError } from './NotFoundError.mjs'
66
export { UnauthorizedError } from './UnauthorizedError.mjs'
77
export { InternalServerError } from './InternalServerError.mjs'

apps/book-server/src/common/plugins/global/errorHandlerPlugin.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { FastifyPluginCallback } from 'fastify'
55
import { container } from 'tsyringe'
66
import fp from 'fastify-plugin'
77

8-
// TODO: apply fastify-plugin
98
const errorHandlerPlugin: FastifyPluginCallback = (fastify, _, done) => {
109
fastify.addHook('preHandler', function (request, reply, done) {
1110
if (request.body) {

apps/book-server/src/services/BookBuildService/index.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path'
22
import fs from 'fs-extra'
33
import { exec as execCb } from 'node:child_process'
44
import { promisify } from 'node:util'
5-
import { NotFoundError } from '@errors/NotfoundError.mjs'
5+
import { NotFoundError } from '@errors/NotFoundError.mjs'
66
import { MongoService } from '@lib/mongo/MongoService.mjs'
77
import { injectable, singleton } from 'tsyringe'
88
import { ConfilctError } from '@errors/ConfilctError.mjs'
@@ -117,6 +117,7 @@ export class BookBuildService implements Service {
117117

118118
fs.writeFileSync(`${dest}/theme.config.tsx`, themeConfigTemplate({ title: book.title }))
119119

120+
await exec('pnpm prettier -w .', { cwd: dest })
120121
const buildStdout = await this.buildTsToJs(dest)
121122
if (buildStdout) {
122123
this.mq.publish({
@@ -148,6 +149,7 @@ export class BookBuildService implements Service {
148149
const { stdout, stderr } = await exec('pnpm next build', { cwd: dest })
149150
if (stderr) {
150151
console.error(`stderr: ${stderr}`)
152+
return stderr
151153
}
152154
return stdout
153155
} catch (error) {

apps/book-server/src/services/BookDeployService/index.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path'
22
import fs from 'fs-extra'
33
import { injectable, singleton } from 'tsyringe'
44
import { BookService } from '@services/BookService/index.mjs'
5-
import { NotFoundError } from '@errors/NotfoundError.mjs'
5+
import { NotFoundError } from '@errors/NotFoundError.mjs'
66
import { WriterService } from '@services/WriterService/index.mjs'
77
import { AwsS3Service } from '@lib/awsS3/AwsS3Service.mjs'
88
import mime from 'mime'
@@ -34,12 +34,14 @@ export class BookDeployService implements Service {
3434
const writer = await this.writerService.findById(signedWriterId)
3535

3636
if (!writer) {
37+
console.log('Not found writer')
3738
throw new NotFoundError('Not found writer')
3839
}
3940

4041
const book = await this.bookService.findByUrlSlug(url_slug)
4142

4243
if (!book) {
44+
console.log('Not found book')
4345
throw new NotFoundError('Not found book')
4446
}
4547

@@ -52,6 +54,7 @@ export class BookDeployService implements Service {
5254
// find output
5355
const exists = fs.existsSync(output)
5456
if (!exists) {
57+
console.log('Not found book output')
5558
throw new NotFoundError('Not found book output')
5659
}
5760

apps/book-server/src/services/BookService/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NotFoundError } from '@errors/NotfoundError.mjs'
1+
import { NotFoundError } from '@errors/NotFoundError.mjs'
22
import { MongoService } from '@lib/mongo/MongoService.mjs'
33
import { injectable, singleton } from 'tsyringe'
44
import { BadRequestError } from '@errors/BadRequestErrors.mjs'

apps/book-server/src/services/PageService/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BadRequestError } from '@errors/BadRequestErrors.mjs'
22
import { ConfilctError } from '@errors/ConfilctError.mjs'
3-
import { NotFoundError } from '@errors/NotfoundError.mjs'
3+
import { NotFoundError } from '@errors/NotFoundError.mjs'
44
import { UnauthorizedError } from '@errors/UnauthorizedError.mjs'
55
import type {
66
CreatePageInput,

apps/book-server/src/services/WriterService/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Time } from '@constants/TimeConstants.mjs'
2-
import { NotFoundError } from '@errors/NotfoundError.mjs'
2+
import { NotFoundError } from '@errors/NotFoundError.mjs'
33
import { Writer } from '@graphql/generated.js'
44
import { GraphQLContext } from '@interfaces/graphql.mjs'
55
import { JwtService } from '@lib/jwt/JwtService.mjs'

apps/book-server/src/templates/themeConfigTemplate.mts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@ export const themeConfigTemplate = ({ title }: Props) => {
66
return `
77
import { useRouter } from 'next/router'
88
import type { DocsThemeConfig } from 'nextra-theme-docs'
9-
import { useConfig } from 'nextra-theme-docs'
10-
9+
import {
10+
useConfig,
11+
Callout,
12+
Bleed,
13+
Card,
14+
Cards,
15+
FileTree,
16+
Tabs,
17+
Tab,
18+
Steps,
19+
} from 'nextra-theme-docs'
20+
21+
const components = { Callout, Bleed, Card, Cards, FileTree, Tabs, Tab, Steps } as any
22+
1123
const config: DocsThemeConfig = {
1224
logo: <span>${title}</span>,
1325
editLink: {
@@ -73,6 +85,9 @@ export const themeConfigTemplate = ({ title }: Props) => {
7385
</>
7486
)
7587
},
88+
components: {
89+
...components,
90+
},
7691
}
7792
7893
export default config

apps/book-web/src/layouts/MarkdownEditorLayout/MarkdownEditorLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function MarkdownEditorLayout({ children, mdxText }: Props) {
165165
}
166166
const { deploy } = await deployAsyncMutate({ input: { url_slug: bookUrlSlug } })
167167

168+
console.log('deploy', deploy)
168169
const event = new CustomEvent(nextraCustomEventName.deployEndEvent, {
169170
detail: { publishedUrl: deploy.published_url },
170171
})

apps/book-web/src/lib/graphqlFetch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export default async function graphqlFetch<T>({
6060
throw new Error(message as any)
6161
}
6262

63-
6463
const json = await res?.json()
6564
return json.data as T
6665
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
"next": "14.2.3"
4545
},
4646
"dependencies": {
47-
"turbo": "^2.0.4"
47+
"turbo": "^2.0.6"
4848
}
4949
}

packages/markdown-editor/src/contexts/markdown-editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type Props = {
3434
}
3535

3636
export const MarkdownEditorProvider = ({ children, value: { editorValue } }: Props) => {
37-
const [isError, setIsError] = useState<boolean>(false)
3837
const [value, setValue] = useState<string>(editorValue)
38+
const [isError, setIsError] = useState<boolean>(false)
3939
const [mdxSource, setMdxSource] = useState<MDXRemoteSerializeResult | null>(null)
4040
const [stat, setStat] = useState<Statistics | null>(null)
4141

@@ -54,10 +54,12 @@ export const MarkdownEditorProvider = ({ children, value: { editorValue } }: Pro
5454
onigHostUrl: process.env.NEXT_PUBLIC_CLIENT_HOST,
5555
isError,
5656
})
57+
5758
if (!result) {
5859
setIsError(true)
5960
return
6061
}
62+
6163
setMdxSource(result)
6264
} catch (_) {}
6365
}

packages/markdown-editor/src/mdx-compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export const mdxCompiler = async (
135135
})
136136

137137
return result
138-
} catch (error) {
138+
} catch (error: any) {
139139
if (process.env.NODE_ENV === 'development') {
140140
console.log('Failed to compile source', error)
141+
throw new Error(error)
141142
}
142143
return null
143144
}

0 commit comments

Comments
 (0)