polen 0.10.0 → 0.11.0-next.1
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/build/api/api.d.ts +1 -0
- package/build/api/api.d.ts.map +1 -1
- package/build/api/api.js +1 -0
- package/build/api/api.js.map +1 -1
- package/build/api/config/configurator.d.ts +20 -3
- package/build/api/config/configurator.d.ts.map +1 -1
- package/build/api/config/configurator.js +27 -3
- package/build/api/config/configurator.js.map +1 -1
- package/build/api/schema/data-sources/memory/memory.d.ts +2 -2
- package/build/api/schema/data-sources/memory/memory.d.ts.map +1 -1
- package/build/api/schema/data-sources/memory/memory.js +1 -3
- package/build/api/schema/data-sources/memory/memory.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts +7 -3
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js +15 -11
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts +16 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.js +26 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts +7 -2
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.js +13 -5
- package/build/api/schema/data-sources/schema-file/schema-file.js.map +1 -1
- package/build/api/schema/metadata.d.ts +8 -0
- package/build/api/schema/metadata.d.ts.map +1 -0
- package/build/api/schema/metadata.js +19 -0
- package/build/api/schema/metadata.js.map +1 -0
- package/build/api/schema/read.d.ts +3 -3
- package/build/api/schema/read.d.ts.map +1 -1
- package/build/api/schema/read.js.map +1 -1
- package/build/api/schema/schema.d.ts +33 -2
- package/build/api/schema/schema.d.ts.map +1 -1
- package/build/api/schema/schema.js +42 -0
- package/build/api/schema/schema.js.map +1 -1
- package/build/api/schema-source/index.d.ts +2 -0
- package/build/api/schema-source/index.d.ts.map +1 -0
- package/build/api/schema-source/index.js +2 -0
- package/build/api/schema-source/index.js.map +1 -0
- package/build/api/schema-source/schema-source.d.ts +33 -0
- package/build/api/schema-source/schema-source.d.ts.map +1 -0
- package/build/api/schema-source/schema-source.js +137 -0
- package/build/api/schema-source/schema-source.js.map +1 -0
- package/build/api/vite/plugins/core.d.ts +1 -0
- package/build/api/vite/plugins/core.d.ts.map +1 -1
- package/build/api/vite/plugins/core.js +21 -18
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/schema-assets.d.ts +22 -0
- package/build/api/vite/plugins/schema-assets.d.ts.map +1 -0
- package/build/api/vite/plugins/schema-assets.js +269 -0
- package/build/api/vite/plugins/schema-assets.js.map +1 -0
- package/build/api/vite/plugins/serve.d.ts.map +1 -1
- package/build/api/vite/plugins/serve.js +11 -0
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/lib/graphql-change/change-groups.d.ts +2 -0
- package/build/lib/graphql-change/change-groups.d.ts.map +1 -1
- package/build/lib/graphql-change/change-groups.js +54 -0
- package/build/lib/graphql-change/change-groups.js.map +1 -1
- package/build/lib/kit-temp.d.ts +9 -0
- package/build/lib/kit-temp.d.ts.map +1 -1
- package/build/lib/kit-temp.js +12 -0
- package/build/lib/kit-temp.js.map +1 -1
- package/build/lib/path-map/path-map.d.ts.map +1 -1
- package/build/lib/path-map/path-map.js +3 -1
- package/build/lib/path-map/path-map.js.map +1 -1
- package/build/project-data.d.ts +3 -11
- package/build/project-data.d.ts.map +1 -1
- package/build/template/components/Changelog.d.ts +3 -3
- package/build/template/components/Changelog.d.ts.map +1 -1
- package/build/template/components/Changelog.js +8 -84
- package/build/template/components/Changelog.js.map +1 -1
- package/build/template/components/CodeBlock.d.ts +2 -0
- package/build/template/components/CodeBlock.d.ts.map +1 -1
- package/build/template/components/CodeBlock.js +1 -4
- package/build/template/components/CodeBlock.js.map +1 -1
- package/build/template/components/ComponentDispatch.d.ts +34 -0
- package/build/template/components/ComponentDispatch.d.ts.map +1 -0
- package/build/template/components/ComponentDispatch.js +33 -0
- package/build/template/components/ComponentDispatch.js.map +1 -0
- package/build/template/components/ReferenceLink.d.ts +19 -0
- package/build/template/components/ReferenceLink.d.ts.map +1 -0
- package/build/template/components/ReferenceLink.js +19 -0
- package/build/template/components/ReferenceLink.js.map +1 -0
- package/build/template/components/TypeAnnotation.d.ts.map +1 -1
- package/build/template/components/TypeAnnotation.js +3 -3
- package/build/template/components/TypeAnnotation.js.map +1 -1
- package/build/template/components/TypeFieldsLinkList.d.ts.map +1 -1
- package/build/template/components/TypeFieldsLinkList.js +4 -4
- package/build/template/components/TypeFieldsLinkList.js.map +1 -1
- package/build/template/components/TypeIndex.js +2 -2
- package/build/template/components/TypeIndex.js.map +1 -1
- package/build/template/components/VersionSelector.d.ts +7 -0
- package/build/template/components/VersionSelector.d.ts.map +1 -0
- package/build/template/components/VersionSelector.js +30 -0
- package/build/template/components/VersionSelector.js.map +1 -0
- package/build/template/components/graphql/type-link.d.ts.map +1 -1
- package/build/template/components/graphql/type-link.js +2 -2
- package/build/template/components/graphql/type-link.js.map +1 -1
- package/build/template/hooks/useVersionPath.d.ts +6 -0
- package/build/template/hooks/useVersionPath.d.ts.map +1 -0
- package/build/template/hooks/useVersionPath.js +10 -0
- package/build/template/hooks/useVersionPath.js.map +1 -0
- package/build/template/layouts/ChangelogLayout.d.ts.map +1 -0
- package/build/template/{components → layouts}/ChangelogLayout.js +1 -1
- package/build/template/layouts/ChangelogLayout.js.map +1 -0
- package/build/template/layouts/index.d.ts +1 -0
- package/build/template/layouts/index.d.ts.map +1 -1
- package/build/template/layouts/index.js +1 -0
- package/build/template/layouts/index.js.map +1 -1
- package/build/template/lib/fetch-text.d.ts +8 -0
- package/build/template/lib/fetch-text.d.ts.map +1 -0
- package/build/template/lib/fetch-text.js +14 -0
- package/build/template/lib/fetch-text.js.map +1 -0
- package/build/template/lib/polen-url.d.ts +14 -0
- package/build/template/lib/polen-url.d.ts.map +1 -1
- package/build/template/lib/polen-url.js +16 -0
- package/build/template/lib/polen-url.js.map +1 -1
- package/build/template/lib/schema-utils/constants.d.ts +5 -0
- package/build/template/lib/schema-utils/constants.d.ts.map +1 -0
- package/build/template/lib/schema-utils/constants.js +5 -0
- package/build/template/lib/schema-utils/constants.js.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts +15 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.js +37 -0
- package/build/template/lib/schema-utils/schema-utils.js.map +1 -0
- package/build/template/routes/changelog.d.ts +4 -3
- package/build/template/routes/changelog.d.ts.map +1 -1
- package/build/template/routes/changelog.js +13 -7
- package/build/template/routes/changelog.js.map +1 -1
- package/build/template/routes/pages.d.ts +10 -0
- package/build/template/routes/pages.d.ts.map +1 -0
- package/build/template/routes/pages.js +76 -0
- package/build/template/routes/pages.js.map +1 -0
- package/build/template/routes/reference.$type.$field.js +1 -1
- package/build/template/routes/reference.$type.$field.js.map +1 -1
- package/build/template/routes/reference.$type.d.ts +4 -0
- package/build/template/routes/reference.$type.d.ts.map +1 -1
- package/build/template/routes/reference.$type.js +2 -0
- package/build/template/routes/reference.$type.js.map +1 -1
- package/build/template/routes/reference.d.ts +9 -3
- package/build/template/routes/reference.d.ts.map +1 -1
- package/build/template/routes/reference.js +30 -8
- package/build/template/routes/reference.js.map +1 -1
- package/build/template/routes/reference.version.$version.$type.$field.d.ts +6 -0
- package/build/template/routes/reference.version.$version.$type.$field.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.$field.js +32 -0
- package/build/template/routes/reference.version.$version.$type.$field.js.map +1 -0
- package/build/template/routes/reference.version.$version.$type.d.ts +11 -0
- package/build/template/routes/reference.version.$version.$type.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.js +26 -0
- package/build/template/routes/reference.version.$version.$type.js.map +1 -0
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.js +8 -72
- package/build/template/routes/root.js.map +1 -1
- package/build/template/server/app.d.ts +22 -1
- package/build/template/server/app.d.ts.map +1 -1
- package/build/template/server/app.js +19 -9
- package/build/template/server/app.js.map +1 -1
- package/build/template/server/main.js +9 -1
- package/build/template/server/main.js.map +1 -1
- package/build/template/server/ssg/generate.js +2 -2
- package/build/template/server/ssg/generate.js.map +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts.map +1 -1
- package/build/template/server/ssg/get-route-paths.js +51 -27
- package/build/template/server/ssg/get-route-paths.js.map +1 -1
- package/build/template/sources/schema-source.d.ts +15 -0
- package/build/template/sources/schema-source.d.ts.map +1 -0
- package/build/template/sources/schema-source.js +63 -0
- package/build/template/sources/schema-source.js.map +1 -0
- package/package.json +1 -1
- package/src/api/api.ts +1 -0
- package/src/api/config/configurator.ts +51 -6
- package/src/api/schema/data-sources/memory/memory.ts +3 -5
- package/src/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.ts +29 -13
- package/src/api/schema/data-sources/schema-directory/schema-directory.ts +56 -16
- package/src/api/schema/data-sources/schema-file/schema-file.ts +16 -7
- package/src/api/schema/metadata.ts +23 -0
- package/src/api/schema/read.ts +3 -3
- package/src/api/schema/schema.ts +62 -2
- package/src/api/schema-source/index.ts +1 -0
- package/src/api/schema-source/schema-source.ts +189 -0
- package/src/api/vite/plugins/core.ts +23 -18
- package/src/api/vite/plugins/schema-assets.ts +317 -0
- package/src/api/vite/plugins/serve.ts +15 -8
- package/src/lib/graphql-change/change-groups.ts +57 -0
- package/src/lib/kit-temp.ts +13 -0
- package/src/lib/path-map/$.test.ts +22 -19
- package/src/lib/path-map/path-map.ts +3 -1
- package/src/project-data.ts +3 -11
- package/src/template/components/Changelog.tsx +16 -67
- package/src/template/components/CodeBlock.tsx +3 -5
- package/src/template/components/ComponentDispatch.tsx +42 -0
- package/src/template/components/ReferenceLink.tsx +34 -0
- package/src/template/components/TypeAnnotation.tsx +5 -7
- package/src/template/components/TypeFieldsLinkList.tsx +20 -23
- package/src/template/components/TypeIndex.tsx +10 -12
- package/src/template/components/VersionSelector.tsx +50 -0
- package/src/template/components/graphql/type-link.tsx +4 -3
- package/src/template/hooks/useVersionPath.ts +10 -0
- package/src/template/{components → layouts}/ChangelogLayout.tsx +1 -1
- package/src/template/layouts/index.ts +1 -0
- package/src/template/lib/fetch-text.ts +13 -0
- package/src/template/lib/polen-url.ts +20 -0
- package/src/template/lib/schema-utils/constants.ts +4 -0
- package/src/template/lib/schema-utils/schema-utils.ts +42 -0
- package/src/template/routes/changelog.tsx +17 -8
- package/src/template/routes/pages.tsx +109 -0
- package/src/template/routes/reference.$type.$field.tsx +1 -1
- package/src/template/routes/reference.$type.tsx +2 -0
- package/src/template/routes/reference.tsx +38 -6
- package/src/template/routes/reference.version.$version.$type.$field.tsx +35 -0
- package/src/template/routes/reference.version.$version.$type.tsx +30 -0
- package/src/template/routes/root.tsx +8 -109
- package/src/template/server/app.ts +47 -14
- package/src/template/server/main.ts +9 -1
- package/src/template/server/ssg/generate.ts +2 -2
- package/src/template/server/ssg/get-route-paths.ts +53 -27
- package/src/template/sources/schema-source.ts +68 -0
- package/build/lib/graphql-document/$$.d.ts +0 -5
- package/build/lib/graphql-document/$$.d.ts.map +0 -1
- package/build/lib/graphql-document/$$.js +0 -5
- package/build/lib/graphql-document/$$.js.map +0 -1
- package/build/lib/graphql-document/$.d.ts +0 -2
- package/build/lib/graphql-document/$.d.ts.map +0 -1
- package/build/lib/graphql-document/$.js +0 -2
- package/build/lib/graphql-document/$.js.map +0 -1
- package/build/lib/graphql-document/analysis.d.ts +0 -44
- package/build/lib/graphql-document/analysis.d.ts.map +0 -1
- package/build/lib/graphql-document/analysis.js +0 -361
- package/build/lib/graphql-document/analysis.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts +0 -38
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.js +0 -151
- package/build/lib/graphql-document/components/GraphQLDocument.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts +0 -7
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js +0 -27
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts +0 -33
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js +0 -50
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.d.ts +0 -39
- package/build/lib/graphql-document/components/IdentifierLink.d.ts.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.js +0 -75
- package/build/lib/graphql-document/components/IdentifierLink.js.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts +0 -5
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.js +0 -144
- package/build/lib/graphql-document/components/graphql-document-styles.js.map +0 -1
- package/build/lib/graphql-document/components/index.d.ts +0 -5
- package/build/lib/graphql-document/components/index.d.ts.map +0 -1
- package/build/lib/graphql-document/components/index.js +0 -5
- package/build/lib/graphql-document/components/index.js.map +0 -1
- package/build/lib/graphql-document/example.d.ts +0 -25
- package/build/lib/graphql-document/example.d.ts.map +0 -1
- package/build/lib/graphql-document/example.js +0 -140
- package/build/lib/graphql-document/example.js.map +0 -1
- package/build/lib/graphql-document/graphql-document.d.ts +0 -35
- package/build/lib/graphql-document/graphql-document.d.ts.map +0 -1
- package/build/lib/graphql-document/graphql-document.js +0 -36
- package/build/lib/graphql-document/graphql-document.js.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts +0 -43
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.js +0 -132
- package/build/lib/graphql-document/hooks/use-tooltip-state.js.map +0 -1
- package/build/lib/graphql-document/positioning-simple.d.ts +0 -63
- package/build/lib/graphql-document/positioning-simple.d.ts.map +0 -1
- package/build/lib/graphql-document/positioning-simple.js +0 -185
- package/build/lib/graphql-document/positioning-simple.js.map +0 -1
- package/build/lib/graphql-document/schema-context.d.ts +0 -8
- package/build/lib/graphql-document/schema-context.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-context.js +0 -11
- package/build/lib/graphql-document/schema-context.js.map +0 -1
- package/build/lib/graphql-document/schema-integration.d.ts +0 -135
- package/build/lib/graphql-document/schema-integration.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-integration.js +0 -328
- package/build/lib/graphql-document/schema-integration.js.map +0 -1
- package/build/lib/graphql-document/types.d.ts +0 -117
- package/build/lib/graphql-document/types.d.ts.map +0 -1
- package/build/lib/graphql-document/types.js +0 -2
- package/build/lib/graphql-document/types.js.map +0 -1
- package/build/template/components/ChangelogLayout.d.ts.map +0 -1
- package/build/template/components/ChangelogLayout.js.map +0 -1
- package/build/template/components/CodeHikePre.d.ts +0 -16
- package/build/template/components/CodeHikePre.d.ts.map +0 -1
- package/build/template/components/CodeHikePre.js +0 -37
- package/build/template/components/CodeHikePre.js.map +0 -1
- package/src/lib/graphql-document/$$.ts +0 -4
- package/src/lib/graphql-document/$.test.ts +0 -132
- package/src/lib/graphql-document/$.ts +0 -1
- package/src/lib/graphql-document/README.md +0 -102
- package/src/lib/graphql-document/analysis.ts +0 -415
- package/src/lib/graphql-document/components/GraphQLDocument.tsx +0 -265
- package/src/lib/graphql-document/components/GraphQLDocument.unit.test.ts +0 -188
- package/src/lib/graphql-document/components/GraphQLDocumentWithSchema.tsx +0 -46
- package/src/lib/graphql-document/components/GraphQLIdentifierPopover.tsx +0 -199
- package/src/lib/graphql-document/components/IdentifierLink.tsx +0 -160
- package/src/lib/graphql-document/components/graphql-document-styles.ts +0 -144
- package/src/lib/graphql-document/components/index.ts +0 -4
- package/src/lib/graphql-document/demo.md +0 -155
- package/src/lib/graphql-document/example.ts +0 -163
- package/src/lib/graphql-document/graphql-document.ts +0 -37
- package/src/lib/graphql-document/hooks/use-tooltip-state.test.ts +0 -76
- package/src/lib/graphql-document/hooks/use-tooltip-state.ts +0 -191
- package/src/lib/graphql-document/positioning-simple.test.ts +0 -248
- package/src/lib/graphql-document/positioning-simple.ts +0 -260
- package/src/lib/graphql-document/schema-context.tsx +0 -20
- package/src/lib/graphql-document/schema-integration.test.ts +0 -365
- package/src/lib/graphql-document/schema-integration.ts +0 -488
- package/src/lib/graphql-document/types.ts +0 -129
- package/src/template/components/CodeHikePre.tsx +0 -51
- /package/build/template/{components → layouts}/ChangelogLayout.d.ts +0 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
import { Schema } from '#api/schema/index'
|
2
|
+
import { Grafaid } from '#lib/grafaid/index'
|
3
|
+
import type { GraphqlChangeset } from '#lib/graphql-changeset/index'
|
4
|
+
import { astToSchema } from '#template/lib/schema-utils/schema-utils'
|
5
|
+
import { Cache } from '@wollybeard/kit'
|
6
|
+
import type { GraphQLSchema } from 'graphql'
|
7
|
+
|
8
|
+
type WriteFile = (path: string, content: string) => Promise<void>
|
9
|
+
|
10
|
+
type ReadFile = (locator: string) => Promise<string>
|
11
|
+
|
12
|
+
type ClearDirectory = (path: string) => Promise<void>
|
13
|
+
|
14
|
+
type RemoveFile = (path: string) => Promise<void>
|
15
|
+
|
16
|
+
const NoImplementationWriteFile: WriteFile = async (path: string, content: string) => {
|
17
|
+
throw new Error('Write operations not supported in this environment')
|
18
|
+
}
|
19
|
+
|
20
|
+
const NoImplementationClearDirectory: ClearDirectory = async (path: string) => {
|
21
|
+
throw new Error('Directory operations not supported in this environment')
|
22
|
+
}
|
23
|
+
|
24
|
+
const NoImplementationRemoveFile: RemoveFile = async (path: string) => {
|
25
|
+
throw new Error('File removal operations not supported in this environment')
|
26
|
+
}
|
27
|
+
|
28
|
+
interface SchemaSourceConfig {
|
29
|
+
io: {
|
30
|
+
read: ReadFile
|
31
|
+
write?: WriteFile
|
32
|
+
clearDirectory?: ClearDirectory
|
33
|
+
removeFile?: RemoveFile
|
34
|
+
}
|
35
|
+
versions: string[]
|
36
|
+
assetsPath: string
|
37
|
+
}
|
38
|
+
|
39
|
+
export const createSchemaSource = (config: SchemaSourceConfig) => {
|
40
|
+
const getSchemaPath = (version: string) => `${config.assetsPath}/schemas/${version}.json`
|
41
|
+
|
42
|
+
const getChangelogPath = (version: string) => `${config.assetsPath}/schemas/${version}.changelog.json`
|
43
|
+
|
44
|
+
const getSchemasDirectory = () => `${config.assetsPath}/schemas`
|
45
|
+
|
46
|
+
const getMetadataPath = () => `${config.assetsPath}/schemas/metadata.json`
|
47
|
+
|
48
|
+
const ioWrite = config.io.write || NoImplementationWriteFile
|
49
|
+
const ioClearDirectory = config.io.clearDirectory || NoImplementationClearDirectory
|
50
|
+
const ioRemoveFile = config.io.removeFile || NoImplementationRemoveFile
|
51
|
+
|
52
|
+
// Memoize only the base IO read operation
|
53
|
+
const ioReadMemoized = Cache.memoize(config.io.read)
|
54
|
+
|
55
|
+
const get = async (version: string): Promise<GraphQLSchema> => {
|
56
|
+
const content = await ioReadMemoized(getSchemaPath(version))
|
57
|
+
const schemaAst = JSON.parse(content)
|
58
|
+
const schema = astToSchema(schemaAst)
|
59
|
+
return schema
|
60
|
+
}
|
61
|
+
|
62
|
+
const getChangelog = async (version: string): Promise<Schema.ChangelogData> => {
|
63
|
+
const content = await ioReadMemoized(getChangelogPath(version))
|
64
|
+
return JSON.parse(content)
|
65
|
+
}
|
66
|
+
|
67
|
+
const getAllChangesets = async (): Promise<GraphqlChangeset.ChangeSet[]> => {
|
68
|
+
const changesets: GraphqlChangeset.ChangeSet[] = []
|
69
|
+
|
70
|
+
for (let i = 0; i < config.versions.length; i++) {
|
71
|
+
const version = config.versions[i]
|
72
|
+
if (!version) continue
|
73
|
+
|
74
|
+
const schema = await get(version)
|
75
|
+
if (!schema) continue
|
76
|
+
|
77
|
+
// Only try to read changelog for non-oldest versions (matching writeDevAssets logic)
|
78
|
+
let changelogData = null
|
79
|
+
if (i < config.versions.length - 1) {
|
80
|
+
changelogData = await getChangelog(version)
|
81
|
+
}
|
82
|
+
|
83
|
+
if (changelogData) {
|
84
|
+
const prevVersion = config.versions[i + 1]
|
85
|
+
const prevSchema = prevVersion ? await get(prevVersion) : null
|
86
|
+
|
87
|
+
if (prevSchema) {
|
88
|
+
changesets.push({
|
89
|
+
after: schema,
|
90
|
+
before: prevSchema,
|
91
|
+
changes: changelogData.changes,
|
92
|
+
date: new Date(changelogData.date),
|
93
|
+
})
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
// Oldest version - no changelog, use existing utility
|
97
|
+
changesets.push({
|
98
|
+
after: schema,
|
99
|
+
before: Grafaid.Schema.empty,
|
100
|
+
changes: [],
|
101
|
+
date: Schema.versionStringToDate(version),
|
102
|
+
})
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
return changesets
|
107
|
+
}
|
108
|
+
|
109
|
+
return {
|
110
|
+
//
|
111
|
+
// Properties
|
112
|
+
//
|
113
|
+
versions: config.versions,
|
114
|
+
isEmpty: config.versions.length === 0,
|
115
|
+
|
116
|
+
//
|
117
|
+
// Methods
|
118
|
+
//
|
119
|
+
get,
|
120
|
+
getChangelog,
|
121
|
+
getAllChangesets,
|
122
|
+
|
123
|
+
// Expose the memoized reader's clear method
|
124
|
+
clearCache: ioReadMemoized.clear,
|
125
|
+
|
126
|
+
// Write operations (use the writer, which throws if not provided)
|
127
|
+
writeSchema: async (version: string, schema: GraphQLSchema) => {
|
128
|
+
const ast = Grafaid.Schema.AST.parse(Grafaid.Schema.print(schema))
|
129
|
+
await ioWrite(getSchemaPath(version), JSON.stringify(ast))
|
130
|
+
},
|
131
|
+
|
132
|
+
writeChangelog: async (version: string, changelog: Schema.ChangelogData) => {
|
133
|
+
await ioWrite(getChangelogPath(version), JSON.stringify(changelog))
|
134
|
+
},
|
135
|
+
|
136
|
+
// Directory operations
|
137
|
+
clearAllAssets: async () => {
|
138
|
+
await ioClearDirectory(getSchemasDirectory())
|
139
|
+
},
|
140
|
+
|
141
|
+
removeAsset: async (version: string) => {
|
142
|
+
try {
|
143
|
+
await ioRemoveFile(getSchemaPath(version))
|
144
|
+
} catch (error) {
|
145
|
+
// Swallow errors for file removal as requested
|
146
|
+
}
|
147
|
+
|
148
|
+
try {
|
149
|
+
await ioRemoveFile(getChangelogPath(version))
|
150
|
+
} catch (error) {
|
151
|
+
// Swallow errors for file removal as requested
|
152
|
+
}
|
153
|
+
},
|
154
|
+
|
155
|
+
writeMetadata: async (metadata: Schema.SchemaMetadata) => {
|
156
|
+
await ioWrite(getMetadataPath(), JSON.stringify(metadata, null, 2))
|
157
|
+
},
|
158
|
+
|
159
|
+
writeAllAssets: async (
|
160
|
+
schemaData: Awaited<ReturnType<typeof Schema.readOrThrow>>,
|
161
|
+
metadata: Schema.SchemaMetadata,
|
162
|
+
) => {
|
163
|
+
if (!schemaData) return
|
164
|
+
|
165
|
+
// Write schema and changelog files
|
166
|
+
for (const [index, version] of schemaData.entries()) {
|
167
|
+
const versionName = index === 0 ? Schema.VERSION_LATEST : Schema.dateToVersionString(version.date)
|
168
|
+
|
169
|
+
// Write schema file
|
170
|
+
await ioWrite(
|
171
|
+
getSchemaPath(versionName),
|
172
|
+
JSON.stringify(Grafaid.Schema.AST.parse(Grafaid.Schema.print(version.after))),
|
173
|
+
)
|
174
|
+
|
175
|
+
// Write changelog file (except for the oldest/last version)
|
176
|
+
if (Schema.shouldVersionHaveChangelog(index, schemaData.length)) {
|
177
|
+
const changelogData = {
|
178
|
+
changes: version.changes,
|
179
|
+
date: version.date.toISOString(),
|
180
|
+
}
|
181
|
+
await ioWrite(getChangelogPath(versionName), JSON.stringify(changelogData))
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
// Write metadata file
|
186
|
+
await ioWrite(getMetadataPath(), JSON.stringify(metadata, null, 2))
|
187
|
+
},
|
188
|
+
}
|
189
|
+
}
|
@@ -2,23 +2,29 @@ import type { Config } from '#api/config/index'
|
|
2
2
|
import { Content } from '#api/content/$'
|
3
3
|
import { createNavbar } from '#api/content/navbar'
|
4
4
|
import { VitePluginSelfContainedMode } from '#cli/_/self-contained-mode'
|
5
|
+
import { Hono } from '#dep/hono/index'
|
5
6
|
import type { ReactRouter } from '#dep/react-router/index'
|
6
7
|
import type { Vite } from '#dep/vite/index'
|
7
8
|
import { VitePluginJson } from '#lib/vite-plugin-json/index'
|
8
9
|
import { ViteVirtual } from '#lib/vite-virtual/index'
|
9
10
|
import { debugPolen } from '#singletons/debug'
|
10
11
|
import { superjson } from '#singletons/superjson'
|
12
|
+
import * as HonoNodeServer from '@hono/node-server'
|
13
|
+
import { serveStatic } from '@hono/node-server/serve-static'
|
11
14
|
import { Json, Str } from '@wollybeard/kit'
|
15
|
+
import * as NodePath from 'node:path'
|
12
16
|
import type { ProjectData } from '../../../project-data.js'
|
13
17
|
import { SchemaAugmentation } from '../../schema-augmentation/index.js'
|
14
18
|
import { Schema } from '../../schema/index.js'
|
15
19
|
import { createLogger } from '../logger.js'
|
16
20
|
import { polenVirtual } from '../vi.js'
|
17
21
|
import { Pages } from './pages.js'
|
22
|
+
import { SchemaAssets } from './schema-assets.js'
|
18
23
|
|
19
24
|
const viTemplateVariables = polenVirtual([`template`, `variables`])
|
20
25
|
const viTemplateSchemaAugmentations = polenVirtual([`template`, `schema-augmentations`])
|
21
26
|
export const viProjectData = polenVirtual([`project`, `data.jsonsuper`], { allowPluginProcessing: true })
|
27
|
+
export const viProjectSchema = polenVirtual([`project`, `schema.jsonsuper`], { allowPluginProcessing: true })
|
22
28
|
|
23
29
|
export interface ProjectRoutesModule {
|
24
30
|
routes: ReactRouter.RouteObject[]
|
@@ -34,7 +40,7 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
34
40
|
projectRoot: config.paths.project.rootDir,
|
35
41
|
})
|
36
42
|
// todo: augmentations scoped to a version
|
37
|
-
schema?.
|
43
|
+
schema?.forEach(version => {
|
38
44
|
SchemaAugmentation.apply(version.after, config.schemaAugmentations)
|
39
45
|
})
|
40
46
|
schemaCache = schema
|
@@ -68,6 +74,7 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
68
74
|
|
69
75
|
return [
|
70
76
|
...plugins,
|
77
|
+
SchemaAssets(config),
|
71
78
|
/**
|
72
79
|
* If a `polen*` import is encountered from the user's project, resolve it to the currently
|
73
80
|
* running source code of Polen rather than the user's node_modules.
|
@@ -133,11 +140,11 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
133
140
|
__BUILD_ARCHITECTURE_SSG__: Json.encode(config.build.architecture === `ssg`),
|
134
141
|
'process.env.NODE_ENV': Json.encode(config.advanced.debug ? 'development' : 'production'),
|
135
142
|
},
|
136
|
-
customLogger: createLogger(config),
|
143
|
+
// customLogger: createLogger(config),
|
137
144
|
esbuild: false,
|
138
145
|
build: {
|
139
146
|
target: `esnext`,
|
140
|
-
assetsDir: config.paths.project.relative.build.relative.assets,
|
147
|
+
assetsDir: config.paths.project.relative.build.relative.assets.root,
|
141
148
|
rollupOptions: {
|
142
149
|
treeshake: {
|
143
150
|
// Aggressive tree-shaking for smallest bundles
|
@@ -153,6 +160,16 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
153
160
|
}
|
154
161
|
},
|
155
162
|
...ViteVirtual.IdentifiedLoader.toHooks(
|
163
|
+
{
|
164
|
+
identifier: viProjectSchema,
|
165
|
+
async loader() {
|
166
|
+
const debug = debugPolen.sub(`module-project-schema`)
|
167
|
+
debug(`load`, { id: viProjectSchema.id })
|
168
|
+
|
169
|
+
const schema = await readSchema()
|
170
|
+
return superjson.stringify(schema)
|
171
|
+
},
|
172
|
+
},
|
156
173
|
{
|
157
174
|
identifier: viTemplateVariables,
|
158
175
|
loader() {
|
@@ -185,7 +202,7 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
185
202
|
// hydration mismatches between SSR (where base path is prepended) and client
|
186
203
|
// (where basename is configured). This ensures consistent behavior.
|
187
204
|
navbar.push({ pathExp: `/reference`, title: `Reference` })
|
188
|
-
if (schema.
|
205
|
+
if (schema.length > 1) {
|
189
206
|
navbar.push({ pathExp: `/changelog`, title: `Changelog` })
|
190
207
|
}
|
191
208
|
}
|
@@ -204,22 +221,10 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
204
221
|
//
|
205
222
|
|
206
223
|
const projectData: ProjectData = {
|
207
|
-
schema,
|
208
224
|
basePath: config.build.base,
|
209
|
-
paths: config.paths
|
225
|
+
paths: config.paths,
|
210
226
|
navbar, // Complete navbar with schema and pages
|
211
|
-
server:
|
212
|
-
port: config.server.port,
|
213
|
-
static: {
|
214
|
-
// todo
|
215
|
-
// relative from CWD of process that boots n1ode server
|
216
|
-
// can easily break! Use path relative in server??
|
217
|
-
directory: `./` + config.paths.project.relative.build.root,
|
218
|
-
// Uses Hono route syntax - includes base path
|
219
|
-
route: config.build.base.slice(0, -1) + `/` + config.paths.project.relative.build.relative.assets
|
220
|
-
+ `/*`,
|
221
|
-
},
|
222
|
-
},
|
227
|
+
server: config.server,
|
223
228
|
warnings: config.warnings,
|
224
229
|
}
|
225
230
|
|
@@ -0,0 +1,317 @@
|
|
1
|
+
import type { Config } from '#api/config/index'
|
2
|
+
import { SchemaAugmentation } from '#api/schema-augmentation/index'
|
3
|
+
import { createSchemaSource } from '#api/schema-source/index'
|
4
|
+
import { Schema } from '#api/schema/index'
|
5
|
+
import type { Vite } from '#dep/vite/index'
|
6
|
+
import { Grafaid } from '#lib/grafaid/index'
|
7
|
+
import { ViteVirtual } from '#lib/vite-virtual/index'
|
8
|
+
import { debugPolen } from '#singletons/debug'
|
9
|
+
import { Cache } from '@wollybeard/kit'
|
10
|
+
import * as NodeFs from 'node:fs/promises'
|
11
|
+
import * as NodePath from 'node:path'
|
12
|
+
import { polenVirtual } from '../vi.js'
|
13
|
+
|
14
|
+
export const viProjectSchemaMetadata = polenVirtual([`project`, `schema-metadata`])
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Vite plugin that generates JSON assets for GraphQL schemas at build time.
|
18
|
+
*
|
19
|
+
* This plugin:
|
20
|
+
* - Reads GraphQL schema files from the project
|
21
|
+
* - Applies schema augmentations
|
22
|
+
* - Converts schemas to AST format and emits as JSON assets
|
23
|
+
* - Creates a metadata file with available versions
|
24
|
+
* - Provides a virtual module for accessing schema metadata
|
25
|
+
*
|
26
|
+
* The generated assets enable client-side loading of different schema versions
|
27
|
+
* without requiring all schemas to be bundled into the main JavaScript bundle.
|
28
|
+
*
|
29
|
+
* @param config - Polen configuration object
|
30
|
+
* @returns Vite plugin instance
|
31
|
+
*/
|
32
|
+
export const SchemaAssets = (config: Config.Config): Vite.Plugin => {
|
33
|
+
const debug = debugPolen.sub(`vite-plugin:schema-assets`)
|
34
|
+
let viteServer: Vite.ViteDevServer | null = null
|
35
|
+
|
36
|
+
// Helper to load and process schema data
|
37
|
+
const loadAndProcessSchemaData = Cache.memoize(async () => {
|
38
|
+
const schemaData = await Schema.readOrThrow({
|
39
|
+
...config.schema,
|
40
|
+
projectRoot: config.paths.project.rootDir,
|
41
|
+
})
|
42
|
+
|
43
|
+
if (!schemaData) {
|
44
|
+
const metadata: Schema.SchemaMetadata = { hasSchema: false, versions: [] }
|
45
|
+
return {
|
46
|
+
schemaData: null,
|
47
|
+
metadata,
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
// Apply augmentations
|
52
|
+
schemaData.forEach(version => {
|
53
|
+
SchemaAugmentation.apply(version.after, config.schemaAugmentations)
|
54
|
+
})
|
55
|
+
|
56
|
+
// Build metadata
|
57
|
+
const versionStrings: string[] = []
|
58
|
+
for (const [index, version] of schemaData.entries()) {
|
59
|
+
const versionName = index === 0 ? Schema.VERSION_LATEST : Schema.dateToVersionString(version.date)
|
60
|
+
versionStrings.push(versionName)
|
61
|
+
}
|
62
|
+
|
63
|
+
const metadata = {
|
64
|
+
hasSchema: true,
|
65
|
+
versions: versionStrings,
|
66
|
+
}
|
67
|
+
|
68
|
+
debug(`schemaDataLoaded`, { versionCount: schemaData.length })
|
69
|
+
|
70
|
+
return {
|
71
|
+
schemaData,
|
72
|
+
metadata,
|
73
|
+
}
|
74
|
+
})
|
75
|
+
|
76
|
+
// Helper to create schema source with filesystem IO
|
77
|
+
const createDevSchemaSource = (metadata: Schema.SchemaMetadata) => {
|
78
|
+
return createSchemaSource({
|
79
|
+
io: {
|
80
|
+
read: async () => {
|
81
|
+
throw new Error('Read not supported in dev asset writer')
|
82
|
+
},
|
83
|
+
write: async (path: string, content: string) => {
|
84
|
+
await NodeFs.writeFile(path, content, 'utf-8')
|
85
|
+
},
|
86
|
+
clearDirectory: async (path: string) => {
|
87
|
+
try {
|
88
|
+
const files = await NodeFs.readdir(path)
|
89
|
+
await Promise.all(files.map(file => NodeFs.rm(NodePath.join(path, file), { force: true })))
|
90
|
+
} catch (error) {
|
91
|
+
// Directory might not exist, which is fine
|
92
|
+
}
|
93
|
+
},
|
94
|
+
removeFile: async (path: string) => {
|
95
|
+
await NodeFs.rm(path, { force: true })
|
96
|
+
},
|
97
|
+
},
|
98
|
+
versions: metadata.versions,
|
99
|
+
assetsPath: config.paths.framework.devAssets.absolute,
|
100
|
+
})
|
101
|
+
}
|
102
|
+
|
103
|
+
// Helper to write assets using schema-source API
|
104
|
+
const writeDevAssets = async (
|
105
|
+
schemaData: Awaited<ReturnType<typeof Schema.readOrThrow>>,
|
106
|
+
metadata: Schema.SchemaMetadata,
|
107
|
+
) => {
|
108
|
+
if (!schemaData) return
|
109
|
+
|
110
|
+
const devAssetsDir = config.paths.framework.devAssets.schemas
|
111
|
+
await NodeFs.mkdir(devAssetsDir, { recursive: true })
|
112
|
+
|
113
|
+
const schemaSource = createDevSchemaSource(metadata)
|
114
|
+
await schemaSource.writeAllAssets(schemaData, metadata)
|
115
|
+
debug(`devAssetsWritten`, { versionCount: schemaData.length })
|
116
|
+
}
|
117
|
+
|
118
|
+
return {
|
119
|
+
name: `polen:schema-assets`,
|
120
|
+
|
121
|
+
configureServer(server) {
|
122
|
+
viteServer = server
|
123
|
+
|
124
|
+
// Clear all assets when dev server starts
|
125
|
+
const clearAssets = async () => {
|
126
|
+
try {
|
127
|
+
// Create a basic schema source just for clearing
|
128
|
+
const schemaSource = createDevSchemaSource({ hasSchema: false, versions: [] })
|
129
|
+
await schemaSource.clearAllAssets()
|
130
|
+
debug(`devAssetsCleared`, {})
|
131
|
+
} catch (error) {
|
132
|
+
// Ignore errors during clearing
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
// Clear assets immediately
|
137
|
+
void clearAssets()
|
138
|
+
|
139
|
+
// Set up file watching for schema source files
|
140
|
+
if (config.schema?.dataSources?.directory?.path) {
|
141
|
+
// Watch the entire directory for directory mode
|
142
|
+
server.watcher.add(config.schema.dataSources.directory.path)
|
143
|
+
debug(`watchingSchemaDirectory`, { path: config.schema.dataSources.directory.path })
|
144
|
+
}
|
145
|
+
|
146
|
+
if (config.schema?.dataSources?.file?.path) {
|
147
|
+
// Watch the specific file for file mode
|
148
|
+
server.watcher.add(config.schema.dataSources.file.path)
|
149
|
+
debug(`watchingSchemaFile`, { path: config.schema.dataSources.file.path })
|
150
|
+
}
|
151
|
+
|
152
|
+
// Handle file removal
|
153
|
+
server.watcher.on('unlink', async (file) => {
|
154
|
+
const isSchemaFile = config.schema && (() => {
|
155
|
+
const absoluteFile = NodePath.resolve(file)
|
156
|
+
|
157
|
+
// Check if file path matches the configured schema file
|
158
|
+
if (config.schema.dataSources?.file?.path) {
|
159
|
+
const absoluteSchemaFile = NodePath.resolve(
|
160
|
+
config.paths.project.rootDir,
|
161
|
+
config.schema.dataSources.file.path,
|
162
|
+
)
|
163
|
+
if (absoluteFile === absoluteSchemaFile) return true
|
164
|
+
}
|
165
|
+
|
166
|
+
// Check if file path is within the configured schema directory
|
167
|
+
if (config.schema.dataSources?.directory?.path) {
|
168
|
+
const absoluteSchemaDir = NodePath.resolve(
|
169
|
+
config.paths.project.rootDir,
|
170
|
+
config.schema.dataSources.directory.path,
|
171
|
+
)
|
172
|
+
if (absoluteFile.startsWith(absoluteSchemaDir + NodePath.sep)) return true
|
173
|
+
}
|
174
|
+
|
175
|
+
return false
|
176
|
+
})()
|
177
|
+
|
178
|
+
if (isSchemaFile) {
|
179
|
+
debug(`schemaFileRemoved`, { file })
|
180
|
+
|
181
|
+
try {
|
182
|
+
// Clear cache and regenerate
|
183
|
+
loadAndProcessSchemaData.clear()
|
184
|
+
const { schemaData, metadata } = await loadAndProcessSchemaData()
|
185
|
+
|
186
|
+
if (schemaData) {
|
187
|
+
// Write new assets without the removed file
|
188
|
+
await writeDevAssets(schemaData, metadata)
|
189
|
+
debug(`hmr:schemaAssetsUpdatedAfterRemoval`, { versionCount: schemaData.length })
|
190
|
+
} else {
|
191
|
+
// No schema data - clear all assets
|
192
|
+
const schemaSource = createDevSchemaSource({ hasSchema: false, versions: [] })
|
193
|
+
await schemaSource.clearAllAssets()
|
194
|
+
debug(`hmr:allAssetsCleared`, {})
|
195
|
+
}
|
196
|
+
} catch (error) {
|
197
|
+
debug(`hmr:schemaRemovalFailed`, { error })
|
198
|
+
}
|
199
|
+
|
200
|
+
// Send HMR invalidation signal
|
201
|
+
server.ws.send({
|
202
|
+
type: 'custom',
|
203
|
+
event: 'polen:schema-invalidate',
|
204
|
+
data: { timestamp: Date.now() },
|
205
|
+
})
|
206
|
+
|
207
|
+
debug(`hmr:schemaInvalidationSent`, {})
|
208
|
+
}
|
209
|
+
})
|
210
|
+
},
|
211
|
+
|
212
|
+
async buildStart() {
|
213
|
+
debug(`buildStart`, {})
|
214
|
+
|
215
|
+
// Load and process schema data
|
216
|
+
const { schemaData, metadata } = await loadAndProcessSchemaData()
|
217
|
+
|
218
|
+
if (!schemaData) {
|
219
|
+
debug(`noSchemaFound`, {})
|
220
|
+
return
|
221
|
+
}
|
222
|
+
|
223
|
+
// Handle asset generation differently for dev vs build
|
224
|
+
if (viteServer) {
|
225
|
+
// Dev mode: Write assets directly to filesystem
|
226
|
+
await writeDevAssets(schemaData, metadata)
|
227
|
+
debug(`devMode:schemaAssetsWritten`, {})
|
228
|
+
return
|
229
|
+
}
|
230
|
+
|
231
|
+
// Build mode: Create schema source for emitting files
|
232
|
+
const schemaSource = createSchemaSource({
|
233
|
+
io: {
|
234
|
+
read: async () => {
|
235
|
+
throw new Error('Read not supported in build asset emitter')
|
236
|
+
},
|
237
|
+
write: async (path: string, content: string) => {
|
238
|
+
// Convert absolute path to relative filename for Vite
|
239
|
+
const relativePath = NodePath.relative(config.paths.framework.devAssets.absolute, path)
|
240
|
+
const fileName = `${config.paths.project.relative.build.relative.assets.root}/${relativePath}`
|
241
|
+
|
242
|
+
this.emitFile({
|
243
|
+
type: `asset`,
|
244
|
+
fileName,
|
245
|
+
source: content,
|
246
|
+
})
|
247
|
+
},
|
248
|
+
},
|
249
|
+
versions: metadata.versions,
|
250
|
+
assetsPath: config.paths.framework.devAssets.absolute,
|
251
|
+
})
|
252
|
+
|
253
|
+
// Emit all assets using the high-level API
|
254
|
+
await schemaSource.writeAllAssets(schemaData, metadata)
|
255
|
+
debug(`buildMode:allAssetsEmitted`, { versionCount: schemaData.length })
|
256
|
+
},
|
257
|
+
|
258
|
+
async handleHotUpdate({ file, server }) {
|
259
|
+
const isSchemaFile = config.schema && (() => {
|
260
|
+
const absoluteFile = NodePath.resolve(file)
|
261
|
+
|
262
|
+
// Check if file path matches the configured schema file
|
263
|
+
if (config.schema.dataSources?.file?.path) {
|
264
|
+
const absoluteSchemaFile = NodePath.resolve(config.paths.project.rootDir, config.schema.dataSources.file.path)
|
265
|
+
if (absoluteFile === absoluteSchemaFile) return true
|
266
|
+
}
|
267
|
+
|
268
|
+
// Check if file path is within the configured schema directory
|
269
|
+
if (config.schema.dataSources?.directory?.path) {
|
270
|
+
const absoluteSchemaDir = NodePath.resolve(
|
271
|
+
config.paths.project.rootDir,
|
272
|
+
config.schema.dataSources.directory.path,
|
273
|
+
)
|
274
|
+
if (absoluteFile.startsWith(absoluteSchemaDir + NodePath.sep)) return true
|
275
|
+
}
|
276
|
+
|
277
|
+
return false
|
278
|
+
})()
|
279
|
+
if (isSchemaFile) {
|
280
|
+
debug(`schemaFileChanged`, { file })
|
281
|
+
|
282
|
+
// Regenerate schema assets
|
283
|
+
try {
|
284
|
+
loadAndProcessSchemaData.clear()
|
285
|
+
const { schemaData, metadata } = await loadAndProcessSchemaData()
|
286
|
+
|
287
|
+
if (schemaData) {
|
288
|
+
debug(`hmr:schemaRegenerated`, { versionCount: schemaData.length })
|
289
|
+
|
290
|
+
// Write new assets to filesystem
|
291
|
+
await writeDevAssets(schemaData, metadata)
|
292
|
+
}
|
293
|
+
} catch (error) {
|
294
|
+
debug(`hmr:schemaRegenerationFailed`, { error })
|
295
|
+
}
|
296
|
+
|
297
|
+
// Send HMR invalidation signal
|
298
|
+
server.ws.send({
|
299
|
+
type: 'custom',
|
300
|
+
event: 'polen:schema-invalidate',
|
301
|
+
data: { timestamp: Date.now() },
|
302
|
+
})
|
303
|
+
|
304
|
+
debug(`hmr:schemaInvalidationSent`, {})
|
305
|
+
}
|
306
|
+
},
|
307
|
+
|
308
|
+
...ViteVirtual.IdentifiedLoader.toHooks({
|
309
|
+
identifier: viProjectSchemaMetadata,
|
310
|
+
async loader() {
|
311
|
+
debug(`virtualModuleLoad`, { id: viProjectSchemaMetadata.id })
|
312
|
+
const { metadata } = await loadAndProcessSchemaData()
|
313
|
+
return `export default ${JSON.stringify(metadata)}`
|
314
|
+
},
|
315
|
+
}),
|
316
|
+
}
|
317
|
+
}
|
@@ -5,16 +5,10 @@ import type { Vite } from '#dep/vite/index'
|
|
5
5
|
import { createHtmlTransformer } from '#lib/html-utils/html-transformer'
|
6
6
|
import { ResponseInternalServerError } from '#lib/kit-temp'
|
7
7
|
import { debugPolen } from '#singletons/debug'
|
8
|
+
import type { App, AppOptions } from '#template/server/app'
|
8
9
|
import * as HonoNodeServer from '@hono/node-server'
|
9
10
|
import { Err } from '@wollybeard/kit'
|
10
|
-
|
11
|
-
type App = Hono.Hono
|
12
|
-
|
13
|
-
interface AppOptions {
|
14
|
-
hooks?: {
|
15
|
-
transformHtml?: ((html: string, ctx: Hono.Context) => Promise<string> | string)[]
|
16
|
-
}
|
17
|
-
}
|
11
|
+
import * as NodePath from 'node:path'
|
18
12
|
|
19
13
|
interface AppServerModule {
|
20
14
|
createApp: (options: AppOptions) => App
|
@@ -80,6 +74,19 @@ export const Serve = (
|
|
80
74
|
}),
|
81
75
|
],
|
82
76
|
},
|
77
|
+
paths: {
|
78
|
+
base: config.build.base,
|
79
|
+
assets: {
|
80
|
+
// Calculate relative path from CWD to Polen's assets
|
81
|
+
// CWD is user's project directory where they run 'pnpm dev'
|
82
|
+
// Assets are in Polen's dev assets directory
|
83
|
+
directory: NodePath.relative(
|
84
|
+
process.cwd(),
|
85
|
+
config.paths.framework.devAssets.absolute,
|
86
|
+
),
|
87
|
+
route: config.server.routes.assets,
|
88
|
+
},
|
89
|
+
},
|
83
90
|
})
|
84
91
|
})
|
85
92
|
.catch(async (error) => {
|