Skip to content

Commit c061049

Browse files
committed
feat: update package versions to 0.9.4 across all modules; add startup hints functionality and tests
1 parent 8fb02f1 commit c061049

12 files changed

Lines changed: 115 additions & 20 deletions

File tree

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@clarify-labs/docs",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"private": true,
55
"license": "AGPL-3.0-only",
66
"type": "module",

apps/www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@clarify-labs/www",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"private": true,
55
"license": "AGPL-3.0-only",
66
"type": "module",

extensions/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "clarify-vscode-extension",
33
"displayName": "Clarify",
44
"description": "Live preview for Clarify documentation projects.",
5-
"version": "0.9.3",
5+
"version": "0.9.4",
66
"license": "AGPL-3.0-only",
77
"publisher": "taicode-labs",
88
"repository": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clarify",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"private": true,
55
"license": "AGPL-3.0-only",
66
"description": "An open-source documentation publishing tool built for MDX and OpenAPI.",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@clarify-labs/cli",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"license": "AGPL-3.0-only",
55
"type": "module",
66
"repository": {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import { generateClarifyEnvDts } from './env-types.js'
4+
5+
describe('generateClarifyEnvDts', () => {
6+
it('only exposes the public slot hook module', () => {
7+
const dts = generateClarifyEnvDts([])
8+
9+
expect(dts).toContain("declare module 'virtual:clarify/slot'")
10+
expect(dts).toContain('export function useSlot(): SlotContext')
11+
expect(dts).not.toContain("declare module 'virtual:clarify/slots'")
12+
})
13+
})

packages/cli/source/core/env-types.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ declare module 'virtual:clarify/slot' {
1919
2020
export function useSlot(): SlotContext
2121
}
22-
23-
declare module 'virtual:clarify/slots' {
24-
import type { ComponentType } from 'react'
25-
26-
export type RuntimeSlotEntry = {
27-
plugin: string
28-
/** Lazy import factory — yields the default-exported React component. */
29-
component: () => Promise<{ default: ComponentType }>
30-
}
31-
32-
export const runtimeSlots: Record<string, RuntimeSlotEntry[]>
33-
}
3422
`
3523

3624
export function generateClarifyEnvDts(_plugins: ClarifyPlugin[]): string {

packages/cli/source/core/plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rmSync } from 'node:fs'
1+
import { existsSync, rmSync } from 'node:fs'
22
import { isAbsolute, join, relative, resolve } from 'node:path'
33

44
import mdxPlugin, { type Options as MdxPluginOptions } from '@mdx-js/rollup'
@@ -17,6 +17,7 @@ import { runBuildAssetsHooks, runBuildDoneHooks, runDevConfigureServerHooks, run
1717
import { resolveBuildOptions, type ClarifyBuildOptions } from './options.js'
1818
import { CLARIFY_DEV_PROJECT_INFO_ENDPOINT, handleProjectInfoRequest } from './project-info.js'
1919
import { resolveClarifySite } from './site.js'
20+
import { logStartupHints } from './startup.js'
2021
import {
2122
SSR_ENTRY_CODE,
2223
createTempEntryFile,
@@ -125,6 +126,12 @@ export function clarifyPlugin(options: ClarifyBuildOptions = {}): Plugin[] {
125126
name: 'clarify:core',
126127
async config() {
127128
await resolveRoutesAndSpecs()
129+
logStartupHints({
130+
projectRoot: root,
131+
contentRoot,
132+
contentDirExists: existsSync(contentRoot),
133+
hasRoutes: routes.length > 0,
134+
})
128135

129136
return {
130137
base: projectConfig.assetPrefix,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
3+
import { getStartupHints, logStartupHints } from './startup.js'
4+
5+
describe('getStartupHints', () => {
6+
it('only reports content-directory issues when no content root exists', () => {
7+
const hints = getStartupHints({
8+
projectRoot: '/tmp/my-docs',
9+
contentRoot: '/tmp/my-docs/source',
10+
contentDirExists: false,
11+
hasRoutes: false,
12+
})
13+
14+
expect(hints).toEqual([
15+
'Content directory "source" was not found. Create it or pass --content <dir> to point Clarify at a different directory.',
16+
])
17+
})
18+
19+
it('recommends adding an entry page when content exists but has no routes', () => {
20+
const hints = getStartupHints({
21+
projectRoot: '/tmp/my-docs',
22+
contentRoot: '/tmp/my-docs/docs',
23+
contentDirExists: true,
24+
hasRoutes: false,
25+
})
26+
27+
expect(hints).toEqual([
28+
'No content pages were found yet. Add docs/index.mdx to get started.',
29+
])
30+
})
31+
})
32+
33+
describe('logStartupHints', () => {
34+
it('prints a warn line per startup hint', () => {
35+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
36+
37+
logStartupHints({
38+
projectRoot: '/tmp/my-docs',
39+
contentRoot: '/tmp/my-docs/source',
40+
contentDirExists: false,
41+
hasRoutes: false,
42+
})
43+
44+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('[clarify] Content directory'))
45+
warn.mockRestore()
46+
})
47+
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { relative } from 'node:path'
2+
3+
export type StartupHintOptions = {
4+
projectRoot: string
5+
contentRoot: string
6+
contentDirExists: boolean
7+
hasRoutes: boolean
8+
}
9+
10+
function contentDirectoryLabel(projectRoot: string, contentRoot: string): string {
11+
const relativePath = relative(projectRoot, contentRoot)
12+
return relativePath && relativePath !== '.' ? relativePath : 'source'
13+
}
14+
15+
function contentFileExampleLabel(projectRoot: string, contentRoot: string): string {
16+
const label = contentDirectoryLabel(projectRoot, contentRoot)
17+
return label === '.' ? 'index.mdx' : `${label}/index.mdx`
18+
}
19+
20+
export function getStartupHints(options: StartupHintOptions): string[] {
21+
const hints: string[] = []
22+
23+
if (!options.contentDirExists) {
24+
const label = contentDirectoryLabel(options.projectRoot, options.contentRoot)
25+
hints.push(`Content directory "${label}" was not found. Create it or pass --content <dir> to point Clarify at a different directory.`)
26+
} else if (!options.hasRoutes) {
27+
const example = contentFileExampleLabel(options.projectRoot, options.contentRoot)
28+
hints.push(`No content pages were found yet. Add ${example} to get started.`)
29+
}
30+
31+
return hints
32+
}
33+
34+
export function logStartupHints(options: StartupHintOptions): void {
35+
const hints = getStartupHints(options)
36+
if (hints.length === 0) return
37+
38+
const message = hints.map(hint => `[clarify] ${hint}`).join('\n')
39+
console.warn(message)
40+
}

0 commit comments

Comments
 (0)