@xyd-js/plugin-orama 0.1.0-build.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts ADDED
@@ -0,0 +1,103 @@
1
+ import type {Plugin as VitePlugin, ResolvedConfig} from 'vite'
2
+
3
+ import type {Settings} from '@xyd-js/core'
4
+ import type {Plugin} from '@xyd-js/plugins'
5
+ import {mapSettingsToDocSections, type DocSectionSchema} from '@xyd-js/content/md'
6
+
7
+ import {DEFAULT_SUGGESTIONS} from './const'
8
+ import type {OramaPluginOptions, OramaCloudConfig, OramaSectionSchema} from './types'
9
+ import Search from './Search'
10
+
11
+ export default function OramaPlugin(
12
+ pluginOptions: OramaPluginOptions = {}
13
+ ): Plugin {
14
+ return function (settings: Settings) {
15
+ return {
16
+ name: "plugin-orama",
17
+ vite: [
18
+ vitePlugin(
19
+ settings,
20
+ pluginOptions,
21
+ )
22
+ ],
23
+ components: [
24
+ {
25
+ component: Search,
26
+ name: "Search",
27
+ dist: "@xyd-js/plugin-orama/Search" // TODO: better in the future
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ }
33
+
34
+ function vitePlugin(
35
+ settings: Settings,
36
+ pluginOptions: OramaPluginOptions = {}
37
+ ): VitePlugin {
38
+ const virtualModuleId = 'virtual:xyd-plugin-orama-data'
39
+ const resolvedVirtualModuleId = `\0${virtualModuleId}`
40
+
41
+ let resolveConfig: ResolvedConfig | null = null
42
+
43
+ return {
44
+ name: 'xyd-plugin-orama',
45
+ enforce: 'pre',
46
+
47
+ async configResolved(config: ResolvedConfig) {
48
+ if (resolveConfig) {
49
+ return
50
+ }
51
+
52
+ resolveConfig = config
53
+ },
54
+
55
+ async resolveId(id) {
56
+ if (id === virtualModuleId) {
57
+ return resolvedVirtualModuleId
58
+ }
59
+ },
60
+
61
+ async load(this, id: string) {
62
+ if (id !== resolvedVirtualModuleId) {
63
+ return
64
+ }
65
+
66
+ let cloudConfig: OramaCloudConfig | null = null
67
+ if (pluginOptions.endpoint && pluginOptions.apiKey) {
68
+ cloudConfig = {
69
+ endpoint: pluginOptions.endpoint,
70
+ apiKey: pluginOptions.apiKey
71
+ }
72
+ }
73
+
74
+ const sections = (await mapSettingsToDocSections(settings)).map(mapDocSectionsToOrama)
75
+
76
+ return `
77
+ const docs = ${JSON.stringify(sections)};
78
+ const cloudConfig = ${JSON.stringify(cloudConfig)};
79
+ const suggestions = ${JSON.stringify(pluginOptions.suggestions || DEFAULT_SUGGESTIONS)};
80
+
81
+ export default { docs, cloudConfig, suggestions };
82
+ `
83
+ }
84
+ }
85
+ }
86
+
87
+ function mapDocSectionsToOrama(doc: DocSectionSchema): OramaSectionSchema {
88
+ return {
89
+ category: '', // TODO: finish
90
+
91
+ path: doc.pageUrl,
92
+
93
+ title: doc.headingTitle,
94
+
95
+ description: doc.content,
96
+
97
+ content: doc.content,
98
+
99
+ // section: doc.content,
100
+ // version: string
101
+ }
102
+ }
103
+
package/src/types.ts ADDED
@@ -0,0 +1,25 @@
1
+ export interface OramaCloudConfig {
2
+ endpoint: string
3
+
4
+ apiKey: string
5
+ }
6
+
7
+ export interface OramaPluginOptions {
8
+ endpoint?: string
9
+
10
+ apiKey?: string
11
+
12
+ suggestions?: string[]
13
+ }
14
+
15
+ export interface OramaSectionSchema {
16
+ category: string
17
+
18
+ path: string
19
+
20
+ title: string
21
+
22
+ description: string
23
+
24
+ content: string
25
+ }
@@ -0,0 +1,6 @@
1
+ declare module 'virtual:xyd-plugin-orama-data' {
2
+ import {OramaPluginData} from "./types";
3
+
4
+ const data: OramaPluginData;
5
+ export default data;
6
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "esModuleInterop": true,
5
+ "moduleResolution": "bundler",
6
+ "target": "esnext",
7
+ "baseUrl": ".",
8
+ "lib": ["dom", "dom.iterable", "esnext"],
9
+ "allowJs": true,
10
+ "skipLibCheck": true,
11
+ "strict": false,
12
+ "noEmit": true,
13
+ "incremental": false,
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "jsx": "preserve",
17
+ "plugins": [],
18
+ "strictNullChecks": true
19
+ },
20
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
21
+ "exclude": ["node_modules"]
22
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,33 @@
1
+ import {copyFile} from 'node:fs/promises';
2
+ import {join} from 'node:path';
3
+
4
+ import {defineConfig, Options} from 'tsup';
5
+
6
+ const config: Options = {
7
+ entry: {
8
+ index: 'src/index.ts'
9
+ },
10
+ dts: {
11
+ entry: {
12
+ index: 'src/index.ts'
13
+ },
14
+ resolve: true, // Resolve external types
15
+ },
16
+ format: ['esm'],
17
+ platform: 'node',
18
+ shims: false,
19
+ splitting: false,
20
+ sourcemap: true,
21
+ clean: true,
22
+ external: [
23
+ 'virtual:xyd-plugin-orama-data'
24
+ ],
25
+ onSuccess: async () => {
26
+ await copyFile(
27
+ join(process.cwd(), 'src', 'Search.tsx'),
28
+ join(process.cwd(), 'dist', 'Search.tsx')
29
+ );
30
+ }
31
+ }
32
+
33
+ export default defineConfig(config);