Skip to content

Commit

Permalink
feat: makes deployment optional on docusaurus (#741)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas De Morais <[email protected]>
  • Loading branch information
micheleriva and raiindev authored Jun 24, 2024
1 parent 12c6ae7 commit 299da88
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-docusaurus-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@orama/orama": "workspace:*",
"@orama/plugin-analytics": "workspace:*",
"@orama/plugin-parsedoc": "workspace:*",
"@orama/searchbox": "^1.0.0-rc20",
"@orama/searchbox": "^1.0.0-rc44",
"@oramacloud/client": "^1.0.14",
"github-slugger": "^2.0.0",
"gray-matter": "^4.0.3",
Expand Down
37 changes: 23 additions & 14 deletions packages/plugin-docusaurus-v3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import MarkdownIt from "markdown-it"
import matter from "gray-matter"
import { createSnapshot, deployIndex, fetchEndpointConfig } from "./utils"

enum DeployType {
SNAPSHOT_ONLY = "snapshot-only",
DEFAULT = "default"
}

type CloudConfig = {
deploy: boolean
deploy: DeployType | false
endpoint: string
indexId: string
oramaCloudAPIKey?: string
Expand Down Expand Up @@ -67,12 +72,6 @@ export default function OramaPluginDocusaurus(
pages: allContent["docusaurus-plugin-content-pages"]
}
]

const deployConfig = options.cloud && {
enabled: options.cloud.deploy,
oramaCloudAPIKey,
indexId: options.cloud.indexId
}
const allOramaDocsPromises: Promise<any>[] = []

searchDataConfig.forEach((config) => {
Expand Down Expand Up @@ -155,6 +154,12 @@ export default function OramaPluginDocusaurus(
availableVersions: versions
})
} else {
const deployConfig = options.cloud && {
indexId: options.cloud.indexId,
oramaCloudAPIKey,
type: options.cloud.deploy
}

const endpointConfig = await deployData({
oramaDocs,
generatedFilesDir: ctx.generatedFilesDir,
Expand Down Expand Up @@ -282,23 +287,27 @@ async function deployData({
deployConfig:
| {
indexId: string
enabled: boolean
oramaCloudAPIKey: string | undefined
type: DeployType | false
}
| undefined
}) {
const { ORAMA_CLOUD_BASE_URL } = process.env
const baseUrl = ORAMA_CLOUD_BASE_URL || "https://cloud.oramasearch.com"

if (deployConfig) {
const endpointConfig = await fetchEndpointConfig(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
if (deployConfig?.type) {
if (deployConfig.type === DeployType.DEFAULT || deployConfig.type === DeployType.SNAPSHOT_ONLY) {
const endpointConfig = await fetchEndpointConfig(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)

if (deployConfig.enabled) {
await createSnapshot(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!, oramaDocs)
await deployIndex(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
}

return endpointConfig
if (deployConfig.type === DeployType.DEFAULT) {
await deployIndex(baseUrl, deployConfig.oramaCloudAPIKey!, deployConfig.indexId!)
}
return endpointConfig
} else {
throw new Error("Invalid deploy type")
}
} else {
const db = await create({
schema: { ...presets.docs.schema, version: "enum" }
Expand Down
68 changes: 42 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 299da88

Please sign in to comment.