create-kawapress 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) KawaPress contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,156 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo-dark.png">
4
+ <img src="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo.png" alt="KawaPress" width="180">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ <h1 align="center">KawaPress</h1>
9
+
10
+ <p align="center">
11
+ <strong>A Vue-first static site generator for documentation and content-focused websites.</strong>
12
+ </p>
13
+
14
+ <p align="center">
15
+ Write in Markdown. Develop with real SSR. Extend everything through public APIs.
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://www.npmjs.com/package/kawapress"><img src="https://img.shields.io/npm/v/kawapress?label=npm&color=42b883" alt="npm version"></a>
20
+ <a href="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml"><img src="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml/badge.svg" alt="documentation build"></a>
21
+ <a href="https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE"><img src="https://img.shields.io/github/license/ShenQingchuan/kawapress" alt="MIT license"></a>
22
+ <img src="https://img.shields.io/badge/Node.js-%E2%89%A522.12-339933?logo=nodedotjs&logoColor=white" alt="Node.js 22.12 or newer">
23
+ </p>
24
+
25
+ <p align="center">
26
+ <a href="https://shenqingchuan.github.io/kawapress/en/">Documentation</a>
27
+ ·
28
+ <a href="https://github.com/ShenQingchuan/kawapress/blob/main/README.zh-CN.md">简体中文</a>
29
+ </p>
30
+
31
+ If you run into any problems while using KawaPress, please [open an issue](https://github.com/ShenQingchuan/kawapress/issues). Your feedback helps shape the project during its early development.
32
+
33
+ ## Why KawaPress?
34
+
35
+ KawaPress turns Markdown into pre-rendered Vue websites. It keeps the familiar simplicity of a documentation generator while giving themes and plugins the same public extension points used by the official experience.
36
+
37
+ - **Real SSR during development** — every initial request is server-rendered, so SSR-only problems appear before build or deployment.
38
+ - **A complete default experience** — the built-in nagi (凪) preset includes responsive documentation layouts, dark mode, local search, syntax highlighting, Twoslash, code groups, multilingual navigation, and more.
39
+ - **Vue from end to end** — Markdown becomes Vue components, Vue Router handles navigation, and regular Vue SFCs fit naturally into content.
40
+ - **AI-ready output** — nagi generates page-level Markdown, locale-aware `llms.txt` and `llms-full.txt`, plus built-in copy actions.
41
+ - **One extension model** — Generator Plugins, Runtime Plugins, and Presets cover build-time behavior, the Vue runtime, themes, and reusable product setups without private theme hooks.
42
+
43
+ KawaPress is an independent project. It is not a VitePress fork or a drop-in replacement, and it intentionally does not use VitePress configuration.
44
+
45
+ ## Quick Start
46
+
47
+ You need [Node.js](https://nodejs.org/) 22.12 or newer.
48
+
49
+ Create a new site with the scaffolder:
50
+
51
+ ```sh
52
+ npm create kawapress@latest my-kawapress-site
53
+ cd my-kawapress-site
54
+ npm run dev
55
+ ```
56
+
57
+ `pnpm create kawapress my-kawapress-site` and `yarn create kawapress my-kawapress-site` do the same thing. The scaffolder asks for a site title and a default language, and can install dependencies for you.
58
+
59
+ If you would rather see every file from the start, set the site up by hand:
60
+
61
+ ```sh
62
+ mkdir my-kawapress-site
63
+ cd my-kawapress-site
64
+ pnpm init
65
+ pnpm add --save-dev kawapress
66
+ ```
67
+
68
+ Create `kawapress.config.ts`:
69
+
70
+ ```ts
71
+ import { nagi } from 'kawapress/nagi'
72
+
73
+ export default nagi({
74
+ title: 'My Docs',
75
+ })
76
+ ```
77
+
78
+ Create `index.md`:
79
+
80
+ ```md
81
+ ---
82
+ layout: home
83
+ title: My Docs
84
+ ---
85
+
86
+ # My Docs
87
+
88
+ Welcome to my KawaPress site.
89
+ ```
90
+
91
+ Start the development server:
92
+
93
+ ```sh
94
+ pnpm exec kawapress dev
95
+ ```
96
+
97
+ Build static files into `dist`:
98
+
99
+ ```sh
100
+ pnpm exec kawapress build
101
+ ```
102
+
103
+ The deployed output is static and does not require a Node.js server. npm and Yarn commands are available in the [Getting Started guide](https://shenqingchuan.github.io/kawapress/en/guide/getting-started).
104
+
105
+ > If your site directly imports Vue APIs or Vue components, also install `vue` as a development dependency.
106
+
107
+ ## What You Get
108
+
109
+ | Area | Included capability |
110
+ | --- | --- |
111
+ | Authoring | Markdown, frontmatter, Vue in Markdown, file-based routing, data loaders |
112
+ | Rendering | Shared development/build SSR semantics, hydration, Vue Router navigation |
113
+ | Documentation UI | nagi layouts, responsive sidebar, page outline, dark mode, i18n |
114
+ | Content | Shiki, Twoslash, code groups, code copy, containers, GitHub alerts |
115
+ | Discovery | Lazy local search and locale-aware navigation |
116
+ | AI consumption | Page `.md`, `llms.txt`, `llms-full.txt`, copy actions |
117
+ | Styling | UnoCSS integration with sensible nagi defaults |
118
+
119
+ The `kawapress` package includes nagi and its official plugins. A basic site only needs this one package; advanced users can compose the individual `@kawapress/*` packages directly.
120
+
121
+ ## Extension Model
122
+
123
+ KawaPress keeps extension boundaries explicit:
124
+
125
+ - a **Generator Plugin** extends configuration, Markdown, page data, Vite, and build artifacts;
126
+ - a **Runtime Plugin** extends the real Vue App and Vue Router in both SSR and the browser;
127
+ - a **Preset** combines configuration and plugins into a ready-to-use experience such as nagi.
128
+
129
+ A logical plugin is installed once and can provide both generator and runtime behavior. Learn more in the [Plugin System guide](https://shenqingchuan.github.io/kawapress/en/guide/plugin-system).
130
+
131
+ ## Documentation
132
+
133
+ - [Getting Started](https://shenqingchuan.github.io/kawapress/en/guide/getting-started)
134
+ - [What is KawaPress?](https://shenqingchuan.github.io/kawapress/en/guide/what-is-kawapress)
135
+ - [Markdown Extensions](https://shenqingchuan.github.io/kawapress/en/guide/markdown-extensions)
136
+ - [Internationalization](https://shenqingchuan.github.io/kawapress/en/guide/internationalization)
137
+ - [Plugin System](https://shenqingchuan.github.io/kawapress/en/guide/plugin-system)
138
+ - [Theme Customization](https://shenqingchuan.github.io/kawapress/en/guide/theme-customization)
139
+
140
+ ## Contributing
141
+
142
+ Issues and pull requests are welcome. For a large feature, please open an issue first so the direction can be agreed on before implementation.
143
+
144
+ ```sh
145
+ pnpm install
146
+ pnpm lint
147
+ pnpm typecheck
148
+ pnpm test
149
+ pnpm build
150
+ ```
151
+
152
+ KawaPress uses Node.js 22.12 or newer and pnpm 11.22.0 for repository development.
153
+
154
+ ## License
155
+
156
+ [MIT](https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE) © KawaPress contributors
@@ -0,0 +1,156 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo-dark.png">
4
+ <img src="https://raw.githubusercontent.com/ShenQingchuan/kawapress/main/docs/public/kawapress-logo.png" alt="KawaPress" width="180">
5
+ </picture>
6
+ </p>
7
+
8
+ <h1 align="center">KawaPress</h1>
9
+
10
+ <p align="center">
11
+ <strong>以 Vue 为核心,面向文档与内容型网站的静态站点生成器。</strong>
12
+ </p>
13
+
14
+ <p align="center">
15
+ 用 Markdown 安心写作,在真实 SSR 中开发,通过公开能力自由扩展。
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://www.npmjs.com/package/kawapress"><img src="https://img.shields.io/npm/v/kawapress?label=npm&color=42b883" alt="npm 版本"></a>
20
+ <a href="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml"><img src="https://github.com/ShenQingchuan/kawapress/actions/workflows/deploy-pages.yml/badge.svg" alt="文档构建状态"></a>
21
+ <a href="https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE"><img src="https://img.shields.io/github/license/ShenQingchuan/kawapress" alt="MIT 许可"></a>
22
+ <img src="https://img.shields.io/badge/Node.js-%E2%89%A522.12-339933?logo=nodedotjs&logoColor=white" alt="Node.js 22.12 或更高版本">
23
+ </p>
24
+
25
+ <p align="center">
26
+ <a href="https://shenqingchuan.github.io/kawapress/">中文文档</a>
27
+ ·
28
+ <a href="https://github.com/ShenQingchuan/kawapress/blob/main/README.md">English</a>
29
+ </p>
30
+
31
+ 使用 KawaPress 时遇到任何问题,欢迎到 [提交 Issue](https://github.com/ShenQingchuan/kawapress/issues) 反馈,一起参与本项目的早期建设。
32
+
33
+ ## 为什么选择 KawaPress?
34
+
35
+ KawaPress 会把 Markdown 编译成预渲染的 Vue 网站。它保留了文档生成器简单、轻快的写作方式,同时让官方主题和第三方扩展使用完全相同的公开能力。
36
+
37
+ - **开发时也执行真实 SSR**:每次首次请求都会在服务端渲染。只在 SSR 中出现的问题,不必等到构建或上线后才发现。
38
+ - **默认体验完整**:内置 nagi(凪)预设,包含响应式文档布局、深浅色模式、本地搜索、代码高亮、Twoslash、代码组和多语言导航等常用能力。
39
+ - **从头到尾使用 Vue**:Markdown 会变成 Vue 组件,页面跳转交给 Vue Router;需要交互时,也可以自然地使用普通 Vue SFC。
40
+ - **面向 AI 的文档产物**:nagi 默认生成每页 `.md`、各语言的 `llms.txt` 与 `llms-full.txt`,并提供复制正文和链接的操作。
41
+ - **统一的扩展模型**:Generator Plugin、Runtime Plugin 与 Preset 分别覆盖生成阶段、Vue 运行时和能力组合,不依赖主题私有入口。
42
+
43
+ KawaPress 是一个独立项目,不是 VitePress 的分支或配置兼容层,也不能直接使用 VitePress 配置。
44
+
45
+ ## 快速开始
46
+
47
+ 请先准备 [Node.js](https://nodejs.org/) 22.12 或更高版本。
48
+
49
+ 用脚手架创建新站点:
50
+
51
+ ```sh
52
+ npm create kawapress@latest my-kawapress-site
53
+ cd my-kawapress-site
54
+ npm run dev
55
+ ```
56
+
57
+ `pnpm create kawapress my-kawapress-site` 和 `yarn create kawapress my-kawapress-site` 的作用完全一样。脚手架会询问站点标题和默认语言,也可以顺便帮你安装依赖。
58
+
59
+ 如果你更想从零看清每个文件,可以手动创建:
60
+
61
+ ```sh
62
+ mkdir my-kawapress-site
63
+ cd my-kawapress-site
64
+ pnpm init
65
+ pnpm add --save-dev kawapress
66
+ ```
67
+
68
+ 创建 `kawapress.config.ts`:
69
+
70
+ ```ts
71
+ import { nagi } from 'kawapress/nagi'
72
+
73
+ export default nagi({
74
+ title: 'My Docs',
75
+ })
76
+ ```
77
+
78
+ 创建 `index.md`:
79
+
80
+ ```md
81
+ ---
82
+ layout: home
83
+ title: My Docs
84
+ ---
85
+
86
+ # My Docs
87
+
88
+ 欢迎来到我的 KawaPress 站点。
89
+ ```
90
+
91
+ 启动开发服务器:
92
+
93
+ ```sh
94
+ pnpm exec kawapress dev
95
+ ```
96
+
97
+ 构建静态文件到 `dist`:
98
+
99
+ ```sh
100
+ pnpm exec kawapress build
101
+ ```
102
+
103
+ 部署产物是普通静态文件,不需要在服务器上继续运行 Node.js。npm 和 Yarn 的完整命令可以查看[快速开始](https://shenqingchuan.github.io/kawapress/guide/getting-started)。
104
+
105
+ > 如果站点会直接导入 Vue API 或 Vue 组件,还需要把 `vue` 安装为开发依赖。
106
+
107
+ ## 默认包含什么?
108
+
109
+ | 范围 | 内置能力 |
110
+ | --- | --- |
111
+ | 内容编写 | Markdown、Frontmatter、在 Markdown 中使用 Vue、文件路由、Data Loader |
112
+ | 渲染 | 开发与构建共享 SSR 语义、Hydration、Vue Router 站内导航 |
113
+ | 文档界面 | nagi 布局、响应式 Sidebar、本页目录、深浅色模式、多语言 |
114
+ | 内容增强 | Shiki、Twoslash、代码组、代码复制、提示容器、GitHub Alerts |
115
+ | 内容发现 | 按需加载的本地搜索与多语言导航 |
116
+ | AI 读取 | 页面 `.md`、`llms.txt`、`llms-full.txt`、页面复制操作 |
117
+ | 样式 | UnoCSS 集成与 nagi 默认配置 |
118
+
119
+ `kawapress` 已经包含 nagi 和它使用的官方插件。普通文档站只需要安装这一个包;需要自行组合能力时,也可以直接使用独立的 `@kawapress/*` 包。
120
+
121
+ ## 扩展模型
122
+
123
+ KawaPress 把扩展边界分得很清楚:
124
+
125
+ - **Generator Plugin** 负责配置、Markdown、页面数据、Vite 与构建产物;
126
+ - **Runtime Plugin** 在 SSR 和浏览器中扩展真实的 Vue App 与 Vue Router;
127
+ - **Preset** 把配置和一组插件组合成可以直接使用的产品体验,例如 nagi。
128
+
129
+ 一个逻辑插件只需要安装一次,同时可以提供生成侧和运行侧能力。更多内容请查看[插件体系](https://shenqingchuan.github.io/kawapress/guide/plugin-system)。
130
+
131
+ ## 文档
132
+
133
+ - [快速开始](https://shenqingchuan.github.io/kawapress/guide/getting-started)
134
+ - [KawaPress 是什么?](https://shenqingchuan.github.io/kawapress/guide/what-is-kawapress)
135
+ - [Markdown 语法扩展](https://shenqingchuan.github.io/kawapress/guide/markdown-extensions)
136
+ - [国际化](https://shenqingchuan.github.io/kawapress/guide/internationalization)
137
+ - [插件体系](https://shenqingchuan.github.io/kawapress/guide/plugin-system)
138
+ - [主题定制](https://shenqingchuan.github.io/kawapress/guide/theme-customization)
139
+
140
+ ## 参与贡献
141
+
142
+ 欢迎提交 Issue 和 Pull Request。如果准备增加较大的功能,请先创建 Issue,把目标和方案聊清楚后再开始实现。
143
+
144
+ ```sh
145
+ pnpm install
146
+ pnpm lint
147
+ pnpm typecheck
148
+ pnpm test
149
+ pnpm build
150
+ ```
151
+
152
+ KawaPress 仓库使用 Node.js 22.12 或更高版本,以及 pnpm 11.22.0 进行开发。
153
+
154
+ ## 开源许可
155
+
156
+ [MIT](https://github.com/ShenQingchuan/kawapress/blob/main/LICENSE) © KawaPress 贡献者
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import process from 'node:process'
3
+ import { createJiti } from 'jiti'
4
+
5
+ const jiti = createJiti(import.meta.url)
6
+ jiti.import('../src/cli.ts').catch((error) => {
7
+ console.error(error)
8
+ process.exit(1)
9
+ })
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "create-kawapress",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Create a new KawaPress site",
6
+ "license": "MIT",
7
+ "homepage": "https://shenqingchuan.github.io/kawapress/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ShenQingchuan/kawapress.git",
11
+ "directory": "packages/create-kawapress"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/ShenQingchuan/kawapress/issues"
15
+ },
16
+ "keywords": [
17
+ "create",
18
+ "documentation",
19
+ "scaffold",
20
+ "ssg",
21
+ "vue"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./src/index.ts",
26
+ "import": "./src/index.ts",
27
+ "default": "./src/index.ts"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "bin": {
32
+ "create-kawapress": "./bin/create-kawapress.mjs"
33
+ },
34
+ "files": [
35
+ "bin",
36
+ "src/**/!(*.test.*)",
37
+ "templates"
38
+ ],
39
+ "engines": {
40
+ "node": ">=22.12.0"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "registry": "https://registry.npmjs.org/"
45
+ },
46
+ "kawapressVersion": "0.1.0",
47
+ "dependencies": {
48
+ "@clack/prompts": "^1.8.1",
49
+ "citty": "^0.2.2",
50
+ "jiti": "^2.7.0"
51
+ }
6
52
  }
package/src/cli.ts ADDED
@@ -0,0 +1,179 @@
1
+ import type { ResolvedOptions, ScaffoldArguments } from './options'
2
+ import type { ConfirmQuestion, Prompter, SelectQuestion, TextQuestion } from './prompts'
3
+ import { spawn } from 'node:child_process'
4
+ import { relative } from 'node:path'
5
+ import process from 'node:process'
6
+ import { cancel, confirm, intro, isCancel, log, outro, select, text } from '@clack/prompts'
7
+ import { defineCommand, runMain } from 'citty'
8
+ import { siteLanguages } from './languages'
9
+ import { scaffolderVersion } from './manifest'
10
+ import { resolveOptions } from './options'
11
+ import { installCommand, runCommand } from './package-manager'
12
+ import { askInstall, askMissingValues } from './prompts'
13
+ import { scaffoldProject } from './scaffold'
14
+
15
+ interface CliContext {
16
+ cwd: string
17
+ userAgent?: string
18
+ interactive: boolean
19
+ }
20
+
21
+ /**
22
+ * clack resolves to a cancel symbol when the user aborts, so every prompt goes
23
+ * through this adapter to turn that symbol back into a plain value.
24
+ */
25
+ const clackPrompter: Prompter = {
26
+ text: async (question: TextQuestion) => unwrap<string>(await text(question)),
27
+ select: async <T extends string>(question: SelectQuestion<T>) => {
28
+ // clack types an option list conditionally on the value type. Asking for a
29
+ // plain string select keeps that type concrete inside the adapter.
30
+ const value = await select<string>({
31
+ message: question.message,
32
+ initialValue: question.initialValue,
33
+ options: question.choices.map(choice => ({ value: choice.value, label: choice.label })),
34
+ })
35
+ return unwrap<T>(value)
36
+ },
37
+ confirm: async (question: ConfirmQuestion) => unwrap<boolean>(await confirm(question)),
38
+ }
39
+
40
+ async function runScaffolder(args: ScaffoldArguments, context: CliContext): Promise<void> {
41
+ const promptsEnabled = context.interactive && args.yes !== true
42
+ if (promptsEnabled)
43
+ intro(`create-kawapress v${scaffolderVersion}`)
44
+
45
+ const answers = promptsEnabled
46
+ ? await askMissingValues(args, { cwd: context.cwd }, clackPrompter)
47
+ : {}
48
+ const options = resolveOptions(
49
+ { ...args, ...answers },
50
+ { cwd: context.cwd, userAgent: context.userAgent, interactive: context.interactive },
51
+ )
52
+
53
+ await scaffoldProject(options)
54
+ log.success(`Created a KawaPress site in ${options.directory}`)
55
+
56
+ const installed = await askInstall(options.install, options.packageManager, clackPrompter)
57
+ if (installed)
58
+ await installDependencies(options)
59
+ printNextSteps(options, installed)
60
+
61
+ if (promptsEnabled)
62
+ outro('Happy writing!')
63
+ }
64
+
65
+ async function installDependencies(options: ResolvedOptions): Promise<void> {
66
+ log.info(`Installing dependencies with ${options.packageManager}…`)
67
+
68
+ await new Promise<void>((resolvePromise, rejectPromise) => {
69
+ const child = spawn(options.packageManager, ['install'], {
70
+ cwd: options.directory,
71
+ stdio: 'inherit',
72
+ })
73
+
74
+ child.on('error', (error) => {
75
+ rejectPromise(new Error(
76
+ `Could not start "${installCommand(options.packageManager)}": ${error.message}\n`
77
+ + `Run it yourself in ${options.directory} once ${options.packageManager} is available.`,
78
+ ))
79
+ })
80
+ child.on('close', (code) => {
81
+ if (code === 0) {
82
+ resolvePromise()
83
+ return
84
+ }
85
+ rejectPromise(new Error(
86
+ `"${installCommand(options.packageManager)}" exited with code ${code}.\n`
87
+ + `Run it again in ${options.directory}, or skip installing and run it later.`,
88
+ ))
89
+ })
90
+ })
91
+ }
92
+
93
+ function printNextSteps(options: ResolvedOptions, installed: boolean): void {
94
+ const steps = [
95
+ 'Next steps:',
96
+ ` cd ${relative(process.cwd(), options.directory) || '.'}`,
97
+ ]
98
+ if (!installed)
99
+ steps.push(` ${installCommand(options.packageManager)}`)
100
+ steps.push(` ${runCommand(options.packageManager, 'dev')}`)
101
+
102
+ log.info(steps.join('\n'))
103
+ }
104
+
105
+ /** Exits cleanly when the user aborts a prompt. */
106
+ function unwrap<T>(value: unknown): T {
107
+ if (isCancel(value)) {
108
+ cancel('Cancelled.')
109
+ process.exit(0)
110
+ }
111
+ return value as T
112
+ }
113
+
114
+ export const command = defineCommand({
115
+ meta: {
116
+ name: 'create-kawapress',
117
+ version: scaffolderVersion,
118
+ description: 'Create a new KawaPress site',
119
+ },
120
+ args: {
121
+ 'dir': {
122
+ type: 'positional',
123
+ description: 'Directory to create the site in',
124
+ required: false,
125
+ },
126
+ 'title': {
127
+ type: 'string',
128
+ description: 'Site title',
129
+ },
130
+ 'lang': {
131
+ type: 'string',
132
+ description: `Default site language: ${siteLanguages.join(' or ')}`,
133
+ },
134
+ // The kebab-case key is what citty prints in `--help`; citty also accepts
135
+ // the camelCase spelling as an alias.
136
+ 'second-lang': {
137
+ type: 'string',
138
+ description: `Second site language: ${siteLanguages.join(', ')} or none`,
139
+ },
140
+ 'pm': {
141
+ type: 'string',
142
+ description: 'Package manager: npm, pnpm, yarn, or bun',
143
+ },
144
+ 'install': {
145
+ type: 'boolean',
146
+ description: 'Install dependencies after scaffolding',
147
+ negativeDescription: 'Skip installing dependencies',
148
+ },
149
+ 'yes': {
150
+ type: 'boolean',
151
+ description: 'Use the defaults and skip every prompt',
152
+ },
153
+ },
154
+ async run({ args }) {
155
+ const scaffoldArguments: ScaffoldArguments = {
156
+ dir: args.dir,
157
+ title: args.title,
158
+ lang: args.lang,
159
+ secondLang: args['second-lang'],
160
+ pm: args.pm,
161
+ install: args.install,
162
+ yes: args.yes,
163
+ }
164
+
165
+ try {
166
+ await runScaffolder(scaffoldArguments, {
167
+ cwd: process.cwd(),
168
+ userAgent: process.env.npm_config_user_agent,
169
+ interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
170
+ })
171
+ }
172
+ catch (error) {
173
+ log.error(error instanceof Error ? error.message : String(error))
174
+ process.exitCode = 1
175
+ }
176
+ },
177
+ })
178
+
179
+ runMain(command)
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ export type { SecondLanguage, SiteLanguage } from './languages'
2
+ export { isSiteLanguage, languageLabel, localeKey, siteLanguages } from './languages'
3
+ export { kawapressVersion } from './manifest'
4
+ export { formatProjectTitle, toProjectName } from './naming'
5
+ export type {
6
+ InstallDecision,
7
+ ResolvedOptions,
8
+ ResolveOptionsContext,
9
+ ScaffoldArguments,
10
+ } from './options'
11
+ export { resolveOptions } from './options'
12
+ export type { PackageManager } from './package-manager'
13
+ export {
14
+ detectPackageManager,
15
+ installCommand,
16
+ isPackageManager,
17
+ packageManagers,
18
+ runCommand,
19
+ } from './package-manager'
20
+ export type { WriteProjectOptions } from './scaffold'
21
+ export {
22
+ assertEmptyTargetDirectory,
23
+ scaffoldProject,
24
+ templatesDirectory,
25
+ writeProject,
26
+ } from './scaffold'
27
+ export type { TemplateValues } from './template'
28
+ export { renderTemplate } from './template'
29
+ export type { ProjectDefinition, TemplateFile } from './templates'
30
+ export { planProjectFiles } from './templates'
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Languages a generated site can use.
3
+ *
4
+ * `root` content is always the default language and lives at the site root, so
5
+ * the default language only needs a label and a `lang` attribute. A second
6
+ * language owns a URL prefix, which is why it also needs a locale key.
7
+ */
8
+ export const siteLanguages = ['en', 'zh-CN'] as const
9
+
10
+ export type SiteLanguage = (typeof siteLanguages)[number]
11
+
12
+ /** `none` means the generated site stays single-language. */
13
+ export type SecondLanguage = SiteLanguage | 'none'
14
+
15
+ const localeKeys: Record<SiteLanguage, string> = {
16
+ 'en': 'en',
17
+ 'zh-CN': 'zh',
18
+ }
19
+
20
+ const languageLabels: Record<SiteLanguage, string> = {
21
+ 'en': 'English',
22
+ 'zh-CN': '简体中文',
23
+ }
24
+
25
+ /** Directory name and URL prefix of a second language, e.g. `zh`. */
26
+ export function localeKey(language: SiteLanguage): string {
27
+ return localeKeys[language]
28
+ }
29
+
30
+ /** Human-readable name shown in the language menu of a generated site. */
31
+ export function languageLabel(language: SiteLanguage): string {
32
+ return languageLabels[language]
33
+ }
34
+
35
+ export function isSiteLanguage(value: string): value is SiteLanguage {
36
+ return (siteLanguages as readonly string[]).includes(value)
37
+ }
@@ -0,0 +1,35 @@
1
+ import { readFileSync } from 'node:fs'
2
+
3
+ interface ScafolderManifest {
4
+ version: string
5
+ kawapressVersion: string
6
+ }
7
+
8
+ function readManifest(): ScafolderManifest {
9
+ const manifest = JSON.parse(
10
+ readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
11
+ ) as Partial<ScafolderManifest>
12
+
13
+ if (typeof manifest.version !== 'string')
14
+ throw new Error('create-kawapress/package.json is missing its version field.')
15
+ if (typeof manifest.kawapressVersion !== 'string') {
16
+ throw new TypeError(
17
+ 'create-kawapress/package.json is missing the kawapressVersion field. '
18
+ + 'Set it to the version of the kawapress package so generated sites install a matching version.',
19
+ )
20
+ }
21
+
22
+ return { version: manifest.version, kawapressVersion: manifest.kawapressVersion }
23
+ }
24
+
25
+ const manifest = readManifest()
26
+
27
+ /** Version of the scaffolder itself, shown by `--help` and `--version`. */
28
+ export const scaffolderVersion = manifest.version
29
+
30
+ /**
31
+ * Version of `kawapress` written into generated projects. It is stored in this
32
+ * package's own manifest so the value survives publishing, and a unit test
33
+ * keeps it equal to the `kawapress` package version.
34
+ */
35
+ export const kawapressVersion = manifest.kawapressVersion
package/src/naming.ts ADDED
@@ -0,0 +1,31 @@
1
+ /** Directory created when the user does not name one. */
2
+ export const DEFAULT_PROJECT_DIRECTORY = 'kawapress-site'
3
+
4
+ /**
5
+ * Turns a directory name into a readable site title:
6
+ * `my-kawapress-site` becomes `My Kawapress Site`.
7
+ */
8
+ export function formatProjectTitle(directoryName: string): string {
9
+ const words = directoryName.split(/[\s._-]+/).filter(Boolean)
10
+ if (words.length === 0)
11
+ return 'KawaPress Site'
12
+
13
+ return words
14
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
15
+ .join(' ')
16
+ }
17
+
18
+ /**
19
+ * Turns a directory name into a safe package name. The generated `package.json`
20
+ * is always private, but editors and tooling still expect the usual lowercase
21
+ * letters, digits, dots, dashes and underscores.
22
+ */
23
+ export function toProjectName(directoryName: string): string {
24
+ const name = directoryName
25
+ .toLowerCase()
26
+ .replace(/[^a-z0-9._-]+/g, '-')
27
+ .replace(/^[-._]+/, '')
28
+ .replace(/[-._]+$/, '')
29
+
30
+ return name.length > 0 ? name : DEFAULT_PROJECT_DIRECTORY
31
+ }
package/src/options.ts ADDED
@@ -0,0 +1,127 @@
1
+ import type { SecondLanguage, SiteLanguage } from './languages'
2
+ import type { PackageManager } from './package-manager'
3
+ import { basename, resolve } from 'node:path'
4
+ import {
5
+ isSiteLanguage,
6
+ siteLanguages,
7
+ } from './languages'
8
+ import {
9
+ DEFAULT_PROJECT_DIRECTORY,
10
+ formatProjectTitle,
11
+ toProjectName,
12
+ } from './naming'
13
+ import { detectPackageManager, isPackageManager, packageManagers } from './package-manager'
14
+
15
+ /** Raw command line input, already parsed by citty. */
16
+ export interface ScaffoldArguments {
17
+ dir?: string
18
+ title?: string
19
+ lang?: string
20
+ secondLang?: string
21
+ pm?: string
22
+ install?: boolean
23
+ yes?: boolean
24
+ }
25
+
26
+ export interface ResolveOptionsContext {
27
+ /** Directory the command runs in; a relative `dir` resolves against it. */
28
+ cwd: string
29
+ /** Value of `npm_config_user_agent`, used to guess the package manager. */
30
+ userAgent?: string
31
+ /** Whether prompts may be shown at all. `--yes` still turns them off. */
32
+ interactive: boolean
33
+ }
34
+
35
+ /**
36
+ * `ask` means the user has not decided yet and an interactive prompt will ask.
37
+ * It only appears when prompts are available.
38
+ */
39
+ export type InstallDecision = boolean | 'ask'
40
+
41
+ export interface ResolvedOptions {
42
+ /** Absolute path of the directory that will receive the generated files. */
43
+ directory: string
44
+ projectName: string
45
+ title: string
46
+ language: SiteLanguage
47
+ secondLanguage: SecondLanguage
48
+ packageManager: PackageManager
49
+ install: InstallDecision
50
+ interactive: boolean
51
+ }
52
+
53
+ export function resolveOptions(
54
+ args: ScaffoldArguments,
55
+ context: ResolveOptionsContext,
56
+ ): ResolvedOptions {
57
+ const directory = resolve(context.cwd, args.dir ?? DEFAULT_PROJECT_DIRECTORY)
58
+ const language = parseLanguage(args.lang)
59
+ const secondLanguage = parseSecondLanguage(args.secondLang, language)
60
+ const interactive = context.interactive && args.yes !== true
61
+
62
+ return {
63
+ directory,
64
+ projectName: toProjectName(basename(directory)),
65
+ title: parseTitle(args.title) ?? formatProjectTitle(basename(directory)),
66
+ language,
67
+ secondLanguage,
68
+ packageManager: args.pm === undefined
69
+ ? detectPackageManager(context.userAgent)
70
+ : parsePackageManager(args.pm),
71
+ install: resolveInstall(args.install, interactive),
72
+ interactive,
73
+ }
74
+ }
75
+
76
+ export function parseLanguage(value: string | undefined): SiteLanguage {
77
+ if (value === undefined)
78
+ return 'en'
79
+ if (!isSiteLanguage(value)) {
80
+ throw new Error(
81
+ `Unknown default language: "${value}". Use one of: ${siteLanguages.join(', ')}.`,
82
+ )
83
+ }
84
+ return value
85
+ }
86
+
87
+ export function parseSecondLanguage(
88
+ value: string | undefined,
89
+ language: SiteLanguage,
90
+ ): SecondLanguage {
91
+ if (value === undefined || value === 'none')
92
+ return 'none'
93
+ if (!isSiteLanguage(value))
94
+ throw new Error(`Unknown second language: "${value}". Use one of: none, ${siteLanguages.join(', ')}.`)
95
+ if (value === language) {
96
+ throw new Error(
97
+ `The second language must differ from the default language "${language}". `
98
+ + `Pick another language, or leave --second-lang out to generate a single-language site.`,
99
+ )
100
+ }
101
+ return value
102
+ }
103
+
104
+ export function parseTitle(value: string | undefined): string | undefined {
105
+ const title = value?.trim()
106
+ if (!title)
107
+ return undefined
108
+ if (/[\r\n]/.test(title)) {
109
+ throw new Error('The site title must be a single line of text.')
110
+ }
111
+ return title
112
+ }
113
+
114
+ export function parsePackageManager(value: string): PackageManager {
115
+ if (!isPackageManager(value)) {
116
+ throw new Error(
117
+ `Unknown package manager: "${value}". Use one of: ${packageManagers.join(', ')}.`,
118
+ )
119
+ }
120
+ return value
121
+ }
122
+
123
+ function resolveInstall(install: boolean | undefined, interactive: boolean): InstallDecision {
124
+ if (install !== undefined)
125
+ return install
126
+ return interactive ? 'ask' : false
127
+ }
@@ -0,0 +1,28 @@
1
+ export const packageManagers = ['npm', 'pnpm', 'yarn', 'bun'] as const
2
+
3
+ export type PackageManager = (typeof packageManagers)[number]
4
+
5
+ export function isPackageManager(value: string): value is PackageManager {
6
+ return (packageManagers as readonly string[]).includes(value)
7
+ }
8
+
9
+ /**
10
+ * Package managers that wrap this command put their own name in
11
+ * `npm_config_user_agent`, so the agent is the most reliable hint about which
12
+ * one the user actually typed. Longer names come first because an agent string
13
+ * for pnpm also contains the word `npm`.
14
+ */
15
+ const detectionOrder: readonly PackageManager[] = ['pnpm', 'yarn', 'bun', 'npm']
16
+
17
+ export function detectPackageManager(userAgent = ''): PackageManager {
18
+ const tokens = userAgent.toLowerCase().split(/[\s/]+/)
19
+ return detectionOrder.find(manager => tokens.includes(manager)) ?? 'npm'
20
+ }
21
+
22
+ export function installCommand(packageManager: PackageManager): string {
23
+ return `${packageManager} install`
24
+ }
25
+
26
+ export function runCommand(packageManager: PackageManager, script: string): string {
27
+ return `${packageManager} run ${script}`
28
+ }
package/src/prompts.ts ADDED
@@ -0,0 +1,116 @@
1
+ import type { SecondLanguage, SiteLanguage } from './languages'
2
+ import type { InstallDecision, ScaffoldArguments } from './options'
3
+ import { basename, resolve } from 'node:path'
4
+ import { languageLabel, siteLanguages } from './languages'
5
+ import { DEFAULT_PROJECT_DIRECTORY, formatProjectTitle } from './naming'
6
+ import { parseLanguage } from './options'
7
+
8
+ export interface TextQuestion {
9
+ message: string
10
+ placeholder?: string
11
+ defaultValue?: string
12
+ }
13
+
14
+ export interface SelectChoice<T extends string> {
15
+ value: T
16
+ label: string
17
+ }
18
+
19
+ export interface SelectQuestion<T extends string> {
20
+ message: string
21
+ initialValue: T
22
+ choices: readonly SelectChoice<T>[]
23
+ }
24
+
25
+ export interface ConfirmQuestion {
26
+ message: string
27
+ initialValue: boolean
28
+ }
29
+
30
+ /**
31
+ * The prompts the scaffolder needs. Keeping them behind this interface lets the
32
+ * question flow be tested without a terminal, and keeps the terminal
33
+ * implementation in one small adapter.
34
+ */
35
+ export interface Prompter {
36
+ text: (question: TextQuestion) => Promise<string>
37
+ select: <T extends string>(question: SelectQuestion<T>) => Promise<T>
38
+ confirm: (question: ConfirmQuestion) => Promise<boolean>
39
+ }
40
+
41
+ export interface PromptContext {
42
+ /** Directory the command runs in; a relative answer resolves against it. */
43
+ cwd: string
44
+ }
45
+
46
+ /**
47
+ * Asks only for values the user left out, so passing flags keeps the command
48
+ * short. Answers come back as the same shape as parsed flags and are then
49
+ * validated by `resolveOptions` like any other input.
50
+ */
51
+ export async function askMissingValues(
52
+ args: ScaffoldArguments,
53
+ context: PromptContext,
54
+ prompter: Prompter,
55
+ ): Promise<ScaffoldArguments> {
56
+ const answers: ScaffoldArguments = {}
57
+
58
+ if (args.dir === undefined) {
59
+ const directory = await prompter.text({
60
+ message: 'Where should the site be created?',
61
+ placeholder: DEFAULT_PROJECT_DIRECTORY,
62
+ defaultValue: DEFAULT_PROJECT_DIRECTORY,
63
+ })
64
+ answers.dir = resolve(context.cwd, directory)
65
+ }
66
+
67
+ const directory = answers.dir ?? resolve(context.cwd, args.dir ?? DEFAULT_PROJECT_DIRECTORY)
68
+ if (args.title === undefined) {
69
+ answers.title = await prompter.text({
70
+ message: 'Site title',
71
+ defaultValue: formatProjectTitle(basename(directory)),
72
+ })
73
+ }
74
+
75
+ if (args.lang === undefined) {
76
+ answers.lang = await prompter.select<SiteLanguage>({
77
+ message: 'Default language',
78
+ initialValue: 'en',
79
+ choices: siteLanguages.map(language => ({
80
+ value: language,
81
+ label: languageLabel(language),
82
+ })),
83
+ })
84
+ }
85
+
86
+ if (args.secondLang === undefined) {
87
+ const language = parseLanguage(answers.lang ?? args.lang)
88
+ answers.secondLang = await prompter.select<SecondLanguage>({
89
+ message: 'Second language (optional)',
90
+ initialValue: 'none',
91
+ choices: [
92
+ { value: 'none', label: 'None' },
93
+ ...siteLanguages
94
+ .filter(option => option !== language)
95
+ .map(option => ({ value: option, label: languageLabel(option) })),
96
+ ],
97
+ })
98
+ }
99
+
100
+ return answers
101
+ }
102
+
103
+ /** Asks about installing only when the flags did not already decide it. */
104
+ export async function askInstall(
105
+ install: InstallDecision,
106
+ packageManager: string,
107
+ prompter: Prompter,
108
+ ): Promise<boolean> {
109
+ if (install !== 'ask')
110
+ return install
111
+
112
+ return prompter.confirm({
113
+ message: `Install dependencies with ${packageManager}?`,
114
+ initialValue: true,
115
+ })
116
+ }
@@ -0,0 +1,81 @@
1
+ import type { ResolvedOptions } from './options'
2
+ import type { ProjectDefinition } from './templates'
3
+ import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
4
+ import { dirname, join } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { kawapressVersion } from './manifest'
7
+ import { renderTemplate } from './template'
8
+ import { planProjectFiles } from './templates'
9
+
10
+ /** Absolute path of the directory that holds the template files. */
11
+ export const templatesDirectory = fileURLToPath(new URL('../templates/', import.meta.url))
12
+
13
+ /** A target that only contains version control data counts as empty. */
14
+ const allowedEntries = new Set(['.git'])
15
+
16
+ /**
17
+ * Refuses to mix generated files into existing content. Overwriting a project
18
+ * silently is far more expensive than asking the user for a fresh directory.
19
+ */
20
+ export async function assertEmptyTargetDirectory(directory: string): Promise<void> {
21
+ let entries: string[]
22
+ try {
23
+ entries = await readdir(directory)
24
+ }
25
+ catch (error) {
26
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT')
27
+ return
28
+ throw error
29
+ }
30
+
31
+ const blockingEntries = entries
32
+ .filter(entry => !allowedEntries.has(entry))
33
+ .sort((left, right) => left.localeCompare(right))
34
+
35
+ if (blockingEntries.length === 0)
36
+ return
37
+
38
+ throw new Error(
39
+ `Cannot create a project in ${directory}: the directory is not empty.\n`
40
+ + `Remove or move these entries first: ${blockingEntries.join(', ')}\n`
41
+ + `Or choose a directory that does not exist yet.`,
42
+ )
43
+ }
44
+
45
+ export interface WriteProjectOptions extends ProjectDefinition {
46
+ /** Absolute path of the directory that receives the generated files. */
47
+ directory: string
48
+ }
49
+
50
+ /**
51
+ * Renders every template file into `directory` and returns the written paths,
52
+ * relative to that directory. The target directory may already exist as long as
53
+ * it is empty.
54
+ */
55
+ export async function writeProject(options: WriteProjectOptions): Promise<string[]> {
56
+ const { directory, ...project } = options
57
+ await assertEmptyTargetDirectory(directory)
58
+
59
+ const writtenFiles: string[] = []
60
+ for (const file of planProjectFiles(project)) {
61
+ const template = await readFile(join(templatesDirectory, file.templatePath), 'utf8')
62
+ const targetPath = join(directory, file.targetPath)
63
+ await mkdir(dirname(targetPath), { recursive: true })
64
+ await writeFile(targetPath, renderTemplate(template, file.values))
65
+ writtenFiles.push(file.targetPath)
66
+ }
67
+
68
+ return writtenFiles
69
+ }
70
+
71
+ /** Scaffolds a project from resolved command line options. */
72
+ export async function scaffoldProject(options: ResolvedOptions): Promise<string[]> {
73
+ return writeProject({
74
+ directory: options.directory,
75
+ projectName: options.projectName,
76
+ title: options.title,
77
+ kawapressVersion,
78
+ language: options.language,
79
+ secondLanguage: options.secondLanguage,
80
+ })
81
+ }
@@ -0,0 +1,23 @@
1
+ const placeholderPattern = /\{\{(\w+)\}\}/g
2
+
3
+ /** Values substituted into a template file. Keys match `{{key}}` placeholders. */
4
+ export type TemplateValues = Readonly<Record<string, string>>
5
+
6
+ /**
7
+ * Replaces every `{{name}}` placeholder with its value.
8
+ *
9
+ * This is deliberately not a template engine: templates stay readable files,
10
+ * and a placeholder without a value fails loudly instead of leaking `{{...}}`
11
+ * into the generated project.
12
+ */
13
+ export function renderTemplate(template: string, values: TemplateValues): string {
14
+ return template.replace(placeholderPattern, (placeholder, name: string) => {
15
+ const value = values[name]
16
+ if (value === undefined) {
17
+ throw new Error(
18
+ `Template placeholder ${placeholder} has no value. Add "${name}" to the values passed to renderTemplate().`,
19
+ )
20
+ }
21
+ return value
22
+ })
23
+ }
@@ -0,0 +1,82 @@
1
+ import type { SecondLanguage, SiteLanguage } from './languages'
2
+ import type { TemplateValues } from './template'
3
+ import { languageLabel, localeKey } from './languages'
4
+
5
+ /** Everything the templates need to know about the project being created. */
6
+ export interface ProjectDefinition {
7
+ projectName: string
8
+ title: string
9
+ kawapressVersion: string
10
+ language: SiteLanguage
11
+ secondLanguage: SecondLanguage
12
+ }
13
+
14
+ /** One template file and where its rendered content goes. */
15
+ export interface TemplateFile {
16
+ /** Path relative to `packages/create-kawapress/templates/`. */
17
+ templatePath: string
18
+ /** Path relative to the generated project directory. */
19
+ targetPath: string
20
+ values: TemplateValues
21
+ }
22
+
23
+ const pages = ['index.md', 'guide/getting-started.md'] as const
24
+
25
+ /**
26
+ * Full list of files the scaffolder writes, in creation order.
27
+ *
28
+ * Files of the default language go to the site root. Files of a second
29
+ * language go under its locale prefix, which is both the URL prefix and the
30
+ * content directory that file routing reads.
31
+ */
32
+ export function planProjectFiles(project: ProjectDefinition): TemplateFile[] {
33
+ const values: Record<string, string> = {
34
+ projectName: project.projectName,
35
+ title: project.title,
36
+ // The title is written into a TypeScript string and a YAML scalar, so it is
37
+ // pre-quoted with JSON escaping that both formats understand.
38
+ titleLiteral: JSON.stringify(project.title),
39
+ kawapressVersion: project.kawapressVersion,
40
+ }
41
+ const { language, secondLanguage } = project
42
+
43
+ return [
44
+ { templatePath: 'gitignore', targetPath: '.gitignore', values },
45
+ { templatePath: 'package.json', targetPath: 'package.json', values },
46
+ secondLanguage === 'none'
47
+ ? { templatePath: 'config/single-locale.ts', targetPath: 'kawapress.config.ts', values }
48
+ : {
49
+ templatePath: 'config/multi-locale.ts',
50
+ targetPath: 'kawapress.config.ts',
51
+ values: {
52
+ ...values,
53
+ rootLabel: languageLabel(language),
54
+ rootLang: language,
55
+ secondKey: localeKey(secondLanguage),
56
+ secondLabel: languageLabel(secondLanguage),
57
+ secondLang: secondLanguage,
58
+ },
59
+ },
60
+ ...pageFiles(language, '', values),
61
+ ...(secondLanguage === 'none'
62
+ ? []
63
+ : pageFiles(secondLanguage, localeKey(secondLanguage), values)),
64
+ ]
65
+ }
66
+
67
+ /**
68
+ * `targetPrefix` is the directory a language lives in (empty for the default
69
+ * language), while page templates link to each other through `prefix`, which
70
+ * carries the leading slash.
71
+ */
72
+ function pageFiles(
73
+ language: SiteLanguage,
74
+ targetPrefix: string,
75
+ values: TemplateValues,
76
+ ): TemplateFile[] {
77
+ return pages.map(page => ({
78
+ templatePath: `pages/${language}/${page}`,
79
+ targetPath: targetPrefix ? `${targetPrefix}/${page}` : page,
80
+ values: { ...values, prefix: targetPrefix ? `/${targetPrefix}` : '' },
81
+ }))
82
+ }
@@ -0,0 +1,9 @@
1
+ import { nagi } from 'kawapress/nagi'
2
+
3
+ export default nagi({
4
+ title: {{titleLiteral}},
5
+ locales: {
6
+ root: { label: '{{rootLabel}}', lang: '{{rootLang}}' },
7
+ '{{secondKey}}': { label: '{{secondLabel}}', lang: '{{secondLang}}' },
8
+ },
9
+ })
@@ -0,0 +1,5 @@
1
+ import { nagi } from 'kawapress/nagi'
2
+
3
+ export default nagi({
4
+ title: {{titleLiteral}},
5
+ })
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ .DS_Store
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "private": true,
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "kawapress dev",
7
+ "build": "kawapress build",
8
+ "preview": "kawapress preview"
9
+ },
10
+ "devDependencies": {
11
+ "kawapress": "^{{kawapressVersion}}"
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ # Getting started
2
+
3
+ This is your first documentation page. It shows the three things you will use most often: a heading, a code block, and a tip.
4
+
5
+ ```ts
6
+ const greeting: string = 'Hello, KawaPress!'
7
+ console.log(greeting)
8
+ ```
9
+
10
+ ::: tip
11
+ Edit `guide/getting-started.md` and the development server updates the page right away.
12
+ :::
13
+
14
+ When you are ready to publish, run `kawapress build`. The static files land in `dist`.
15
+
16
+ [Back to home]({{prefix}}/)
@@ -0,0 +1,16 @@
1
+ ---
2
+ layout: home
3
+ title: {{titleLiteral}}
4
+ hero:
5
+ name: {{titleLiteral}}
6
+ text: A documentation site built with KawaPress
7
+ tagline: Write in Markdown, ship a Vue site.
8
+ actions:
9
+ - theme: brand
10
+ text: Get started
11
+ link: '{{prefix}}/guide/getting-started'
12
+ ---
13
+
14
+ Welcome to {{title}}.
15
+
16
+ This is the home page, written in `index.md`. Change it whenever you like.
@@ -0,0 +1,16 @@
1
+ # 快速开始
2
+
3
+ 这是你的第一篇文档。它示范了写文档时最常用的三件事:标题、代码块和提示卡。
4
+
5
+ ```ts
6
+ const greeting: string = '你好,KawaPress!'
7
+ console.log(greeting)
8
+ ```
9
+
10
+ ::: tip
11
+ 修改 `guide/getting-started.md`,开发服务器会立刻更新页面。
12
+ :::
13
+
14
+ 准备好发布时,运行 `kawapress build`,静态文件会生成到 `dist` 目录。
15
+
16
+ [回到首页]({{prefix}}/)
@@ -0,0 +1,16 @@
1
+ ---
2
+ layout: home
3
+ title: {{titleLiteral}}
4
+ hero:
5
+ name: {{titleLiteral}}
6
+ text: 用 KawaPress 搭建的文档站
7
+ tagline: 安心写 Markdown,轻松得到 Vue 站点。
8
+ actions:
9
+ - theme: brand
10
+ text: 开始阅读
11
+ link: '{{prefix}}/guide/getting-started'
12
+ ---
13
+
14
+ 欢迎来到 {{title}}。
15
+
16
+ 这里是站点首页,写在 `index.md` 里。想让它长成什么样,随时可以改。