kawapress 0.2.2 → 0.4.0
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/package.json +4 -2
- package/src/api/config.ts +11 -1
- package/src/api/plugin.ts +11 -2
- package/src/client/components/KawaOutlet.vue +17 -12
- package/src/client/index.ts +2 -1
- package/src/client/platform.ts +30 -0
- package/src/compiler/code-snippet.ts +111 -0
- package/src/compiler/content-loader.ts +7 -3
- package/src/compiler/markdown-source.ts +240 -0
- package/src/compiler/markdown.ts +25 -12
- package/src/compiler/page-loader.ts +40 -12
- package/src/compiler/page-path.ts +93 -0
- package/src/compiler/source-region.ts +78 -0
- package/src/core/extension-points.ts +1 -1
- package/src/core/head.ts +1 -1
- package/src/core/heading-title.ts +9 -5
- package/src/core/outlet.ts +33 -11
- package/src/core/site.ts +12 -0
- package/src/generator/config.ts +50 -2
- package/src/generator/data/context.ts +4 -1
- package/src/generator/pages.ts +49 -10
- package/src/generator/vite/config.ts +2 -0
- package/src/generator/vite/plugins/dev-dead-links.ts +5 -4
- package/src/generator/vite/plugins/markdown.ts +5 -1
- package/src/generator/vite/plugins/pages.ts +2 -0
- package/src/generator.ts +4 -1
- package/src/index.ts +1 -0
- package/src/plugin/outlet-collector.ts +37 -22
- package/src/plugin/runtime-runner.ts +1 -1
|
@@ -2,9 +2,8 @@ import type { Plugin, ViteDevServer } from 'vite'
|
|
|
2
2
|
import type { MarkdownPageLoader } from '../../../compiler/page-loader'
|
|
3
3
|
import type { DeadLink, ResolvedDeadLinkConfig } from '../../../core/dead-links'
|
|
4
4
|
import type { PageRouteIndex } from './pages'
|
|
5
|
-
import {
|
|
5
|
+
import { markdownFileToRoutePath } from '../../../compiler/page-path'
|
|
6
6
|
import { findPageDeadLinks, formatDeadLink } from '../../../core/dead-links'
|
|
7
|
-
import { markdownPagePathToRoutePath } from '../../../core/markdown-route'
|
|
8
7
|
|
|
9
8
|
export interface DevDeadLinksOptions {
|
|
10
9
|
pageLoader: MarkdownPageLoader
|
|
@@ -35,8 +34,10 @@ export function devDeadLinksPlugin(options: DevDeadLinksOptions): Plugin {
|
|
|
35
34
|
return
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
const route =
|
|
39
|
-
|
|
37
|
+
const route = markdownFileToRoutePath(
|
|
38
|
+
file,
|
|
39
|
+
options.pageLoader.sourceRoot,
|
|
40
|
+
options.pageLoader.rewrites,
|
|
40
41
|
)
|
|
41
42
|
const page = options.pageLoader.registry.get(route)
|
|
42
43
|
if (!page) {
|
|
@@ -13,7 +13,11 @@ export function markdownPlugin(pageLoader: MarkdownPageLoader): Plugin {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const source = await readFile(file, 'utf8')
|
|
16
|
-
const { html, env, pageData } = await pageLoader.load(source, file)
|
|
16
|
+
const { html, env, pageData, dependencies } = await pageLoader.load(source, file)
|
|
17
|
+
// An edit to an included file or a code snippet then updates the page.
|
|
18
|
+
for (const dependency of dependencies) {
|
|
19
|
+
this.addWatchFile(dependency)
|
|
20
|
+
}
|
|
17
21
|
return assembleVueSfc(html, env, pageData)
|
|
18
22
|
},
|
|
19
23
|
}
|
package/src/generator.ts
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* Node.js helpers for Generator Plugins. They run only on the generator side;
|
|
3
3
|
* never import this entry from a Runtime Plugin.
|
|
4
4
|
*/
|
|
5
|
+
export { expandMarkdownSource, readMarkdownSource } from './compiler/markdown-source'
|
|
6
|
+
export type { ExpandedMarkdownSource, MarkdownSourceLocation } from './compiler/markdown-source'
|
|
7
|
+
export { markdownFileToPagePath, markdownFileToRoutePath } from './compiler/page-path'
|
|
5
8
|
export { createPageSummaryReader } from './compiler/page-summary'
|
|
6
9
|
export type { PageSummaryReader } from './compiler/page-summary'
|
|
7
10
|
export { resolveHeadingTitle } from './core/heading-title'
|
|
8
11
|
export type { PageSummary } from './core/page-manifest'
|
|
9
12
|
export { parseGitLog, readGitLastUpdated } from './generator/git'
|
|
10
13
|
export type { ReadGitLastUpdatedOptions } from './generator/git'
|
|
11
|
-
export { isMarkdownPage, listMarkdownPages
|
|
14
|
+
export { isMarkdownPage, listMarkdownPages } from './generator/pages'
|
|
12
15
|
export type { MarkdownPage, MarkdownPageScope } from './generator/pages'
|
|
13
16
|
export { useRuntimeDependencies } from './generator/runtime-dependencies'
|
package/src/index.ts
CHANGED
|
@@ -6,31 +6,46 @@ import type {
|
|
|
6
6
|
} from '../core/outlet'
|
|
7
7
|
import { assertOutletName, OUTLET_NAMES } from '../core/outlet'
|
|
8
8
|
|
|
9
|
+
type OutletSide = 'prepend' | 'append'
|
|
10
|
+
type OutletAdder = (outlet: OutletName, item: OutletItemInput) => void
|
|
11
|
+
|
|
9
12
|
export interface OutletCollector {
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
12
|
-
* caller so a plugin cannot claim items that belong to another plugin.
|
|
14
|
+
* The two registration functions of one plugin. The plugin name is bound once
|
|
15
|
+
* by the caller so a plugin cannot claim items that belong to another plugin.
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
forPlugin: (pluginName: string) => {
|
|
18
|
+
prependToOutlet: OutletAdder
|
|
19
|
+
appendToOutlet: OutletAdder
|
|
20
|
+
}
|
|
15
21
|
/** Freezes the collected items into the registry handed to the Vue app. */
|
|
16
22
|
createRegistry: () => OutletRegistry
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export function createOutletCollector(): OutletCollector {
|
|
20
|
-
const
|
|
26
|
+
const sides: Record<OutletSide, Map<OutletName, OutletItem[]>> = {
|
|
27
|
+
prepend: new Map(),
|
|
28
|
+
append: new Map(),
|
|
29
|
+
}
|
|
21
30
|
const outletsById = new Map<string, OutletName>()
|
|
22
31
|
|
|
23
|
-
function add(
|
|
32
|
+
function add(
|
|
33
|
+
side: OutletSide,
|
|
34
|
+
pluginName: string,
|
|
35
|
+
outlet: OutletName,
|
|
36
|
+
item: OutletItemInput,
|
|
37
|
+
): void {
|
|
38
|
+
const method = `${side}ToOutlet`
|
|
24
39
|
assertOutletName(
|
|
25
40
|
outlet,
|
|
26
|
-
`plugin ${JSON.stringify(pluginName)} calling api
|
|
41
|
+
`plugin ${JSON.stringify(pluginName)} calling api.${method}()`,
|
|
27
42
|
)
|
|
28
43
|
|
|
29
44
|
const localId = item?.id
|
|
30
45
|
if (typeof localId !== 'string' || localId.trim() === '') {
|
|
31
46
|
throw new Error(
|
|
32
|
-
`[${pluginName} / runtime /
|
|
33
|
-
+ `must be a non-empty string. Pass { id: 'my-item', component } to api
|
|
47
|
+
`[${pluginName} / runtime / ${method}] Item id for outlet ${JSON.stringify(outlet)} `
|
|
48
|
+
+ `must be a non-empty string. Pass { id: 'my-item', component } to api.${method}().`,
|
|
34
49
|
)
|
|
35
50
|
}
|
|
36
51
|
|
|
@@ -38,30 +53,30 @@ export function createOutletCollector(): OutletCollector {
|
|
|
38
53
|
const existingOutlet = outletsById.get(id)
|
|
39
54
|
if (existingOutlet) {
|
|
40
55
|
throw new Error(
|
|
41
|
-
`[${pluginName} / runtime /
|
|
56
|
+
`[${pluginName} / runtime / ${method}] Duplicate item id ${JSON.stringify(id)} `
|
|
42
57
|
+ `(already used for outlet ${JSON.stringify(existingOutlet)}). `
|
|
43
|
-
+ `Item ids must be unique per plugin; rename one of the
|
|
58
|
+
+ `Item ids must be unique per plugin; rename one of the outlet calls.`,
|
|
44
59
|
)
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
outletsById.set(id, outlet)
|
|
48
|
-
const items =
|
|
49
|
-
items.push({
|
|
50
|
-
|
|
51
|
-
owner: pluginName,
|
|
52
|
-
component: item.component,
|
|
53
|
-
})
|
|
54
|
-
itemsByOutlet.set(outlet, items)
|
|
63
|
+
const items = sides[side].get(outlet) ?? []
|
|
64
|
+
items.push({ id, owner: pluginName, component: item.component })
|
|
65
|
+
sides[side].set(outlet, items)
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
return {
|
|
58
|
-
|
|
59
|
-
add(pluginName, outlet, item)
|
|
60
|
-
|
|
69
|
+
forPlugin: pluginName => ({
|
|
70
|
+
prependToOutlet: (outlet, item) => add('prepend', pluginName, outlet, item),
|
|
71
|
+
appendToOutlet: (outlet, item) => add('append', pluginName, outlet, item),
|
|
72
|
+
}),
|
|
61
73
|
createRegistry() {
|
|
62
|
-
const registry = {} as Record<OutletName,
|
|
74
|
+
const registry = {} as Record<OutletName, OutletRegistry[OutletName]>
|
|
63
75
|
for (const name of OUTLET_NAMES) {
|
|
64
|
-
registry[name] = Object.freeze(
|
|
76
|
+
registry[name] = Object.freeze({
|
|
77
|
+
prepend: Object.freeze([...(sides.prepend.get(name) ?? [])]),
|
|
78
|
+
append: Object.freeze([...(sides.append.get(name) ?? [])]),
|
|
79
|
+
})
|
|
65
80
|
}
|
|
66
81
|
return Object.freeze(registry)
|
|
67
82
|
},
|
|
@@ -26,7 +26,7 @@ export async function createRuntimePluginRunner(
|
|
|
26
26
|
|
|
27
27
|
for (const plugin of plugins) {
|
|
28
28
|
const api: RuntimePluginAPI = {
|
|
29
|
-
|
|
29
|
+
...outletCollector.forPlugin(plugin.name),
|
|
30
30
|
vueApp: handler => vueAppHandlers.add(plugin.name, handler),
|
|
31
31
|
router: handler => routerHandlers.add(plugin.name, handler),
|
|
32
32
|
}
|