@xyd-js/plugin-docs 0.1.0-build.160

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/types.ts ADDED
@@ -0,0 +1,40 @@
1
+ import {Plugin as VitePlugin} from "vite"
2
+ import {RouteConfigEntry} from "@react-router/dev/routes";
3
+
4
+ import {Settings} from "@xyd-js/core";
5
+
6
+ type VitePluginData = {
7
+ preinstall: any // TODO: fix any
8
+ }
9
+
10
+ export interface PresetData {
11
+ routes: RouteConfigEntry[]
12
+ }
13
+
14
+ export type Preset<T> = (
15
+ settings?: Settings,
16
+ options?: T
17
+ ) => {
18
+ // TODO: args and return should be based on passed preinstall plugin
19
+ preinstall: ((options?: any) => (settings: Settings, data: PresetData) => Promise<any>)[]
20
+ routes: RouteConfigEntry[]
21
+ // TODO: 'data' comes from merged object of preinstall
22
+ vitePlugins: (() => (data: VitePluginData) => Promise<VitePlugin>)[]
23
+ basePath: string
24
+ }
25
+
26
+ export interface PluginOutput {
27
+ vitePlugins: VitePlugin[],
28
+
29
+ settings: Settings,
30
+
31
+ routes: RouteConfigEntry[]
32
+
33
+ basePath: string
34
+
35
+ pagePathMapping: {[page: string]: string}
36
+
37
+ hasIndexPage: boolean
38
+ }
39
+
40
+ export type Plugin = () => Promise<PluginOutput | null>
package/src/utils.ts ADDED
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+
7
+ export const HOST_FOLDER_PATH = ".xyd/host"
8
+
9
+ // TODO: share with documan
10
+ export function getHostPath() {
11
+ if (process.env.XYD_DEV_MODE) {
12
+ return path.join(__dirname, "../../../", HOST_FOLDER_PATH)
13
+ }
14
+ return path.join(process.cwd(), HOST_FOLDER_PATH)
15
+ }
16
+
17
+ export function getDocsPluginBasePath() {
18
+ return path.join(getHostPath(), "./plugins/xyd-plugin-docs")
19
+ }