docus 1.0.4 → 2.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.
Files changed (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -24
  3. package/dist/index.cjs +549 -0
  4. package/dist/index.d.ts +25 -0
  5. package/dist/index.mjs +523 -0
  6. package/dist/runtime/app/components/DocusContent.vue +215 -0
  7. package/dist/runtime/app/components/DocusContent.vue.d.ts +25 -0
  8. package/dist/runtime/app/components/Error.vue +19 -0
  9. package/dist/runtime/app/components/Error.vue.d.ts +9 -0
  10. package/dist/runtime/app/components/Markdown.vue +56 -0
  11. package/dist/runtime/app/components/Markdown.vue.d.ts +25 -0
  12. package/dist/runtime/app/components/Page.vue +29 -0
  13. package/dist/runtime/app/components/Page.vue.d.ts +2 -0
  14. package/dist/runtime/app/components/Props.vue +130 -0
  15. package/dist/runtime/app/components/Props.vue.d.ts +80 -0
  16. package/dist/runtime/app/components/prose/ProseA.vue +41 -0
  17. package/dist/runtime/app/components/prose/ProseA.vue.d.ts +23 -0
  18. package/dist/runtime/app/components/prose/ProseBlockquote.vue +5 -0
  19. package/dist/runtime/app/components/prose/ProseCode.vue +5 -0
  20. package/dist/runtime/app/components/prose/ProseCodeInline.vue +5 -0
  21. package/dist/runtime/app/components/prose/ProseEm.vue +5 -0
  22. package/dist/runtime/app/components/prose/ProseH1.vue +3 -0
  23. package/dist/runtime/app/components/prose/ProseH2.vue +3 -0
  24. package/dist/runtime/app/components/prose/ProseH3.vue +3 -0
  25. package/dist/runtime/app/components/prose/ProseH4.vue +3 -0
  26. package/dist/runtime/app/components/prose/ProseH5.vue +3 -0
  27. package/dist/runtime/app/components/prose/ProseH6.vue +3 -0
  28. package/dist/runtime/app/components/prose/ProseHr.vue +3 -0
  29. package/dist/runtime/app/components/prose/ProseImg.vue +32 -0
  30. package/dist/runtime/app/components/prose/ProseImg.vue.d.ts +21 -0
  31. package/dist/runtime/app/components/prose/ProseLi.vue +3 -0
  32. package/dist/runtime/app/components/prose/ProseOl.vue +5 -0
  33. package/dist/runtime/app/components/prose/ProseParagraph.vue +3 -0
  34. package/dist/runtime/app/components/prose/ProseStrong.vue +5 -0
  35. package/dist/runtime/app/components/prose/ProseTable.vue +5 -0
  36. package/dist/runtime/app/components/prose/ProseTbody.vue +5 -0
  37. package/dist/runtime/app/components/prose/ProseTd.vue +5 -0
  38. package/dist/runtime/app/components/prose/ProseTh.vue +5 -0
  39. package/dist/runtime/app/components/prose/ProseThead.vue +5 -0
  40. package/dist/runtime/app/components/prose/ProseTr.vue +5 -0
  41. package/dist/runtime/app/components/prose/ProseUl.vue +5 -0
  42. package/dist/runtime/app/composables/helpers.d.ts +4 -0
  43. package/dist/runtime/app/composables/helpers.js +66 -0
  44. package/dist/runtime/app/composables/helpers.mjs +40 -0
  45. package/dist/runtime/app/composables/index.d.ts +90 -0
  46. package/dist/runtime/app/composables/index.js +108 -0
  47. package/dist/runtime/app/composables/index.mjs +63 -0
  48. package/dist/runtime/app/composables/navigation.d.ts +37 -0
  49. package/dist/runtime/app/composables/navigation.js +227 -0
  50. package/dist/runtime/app/composables/navigation.mjs +148 -0
  51. package/dist/runtime/app/composables/store.d.ts +7 -0
  52. package/dist/runtime/app/composables/store.js +52 -0
  53. package/dist/runtime/app/composables/store.mjs +35 -0
  54. package/dist/runtime/app/composables/style.d.ts +11 -0
  55. package/dist/runtime/app/composables/style.js +117 -0
  56. package/dist/runtime/app/composables/style.mjs +71 -0
  57. package/dist/runtime/app/composables/theme-colors.d.ts +30 -0
  58. package/dist/runtime/app/composables/theme-colors.js +80 -0
  59. package/dist/runtime/app/composables/theme-colors.mjs +48 -0
  60. package/dist/runtime/app/composables/websocket.d.ts +3 -0
  61. package/dist/runtime/app/composables/websocket.js +79 -0
  62. package/dist/runtime/app/composables/websocket.mjs +63 -0
  63. package/dist/runtime/app/layouts/default.vue +5 -0
  64. package/dist/runtime/app/layouts/error.vue +33 -0
  65. package/dist/runtime/app/layouts/error.vue.d.ts +21 -0
  66. package/dist/runtime/app/pages/_.vue +222 -0
  67. package/dist/runtime/app/pages/_.vue.d.ts +2 -0
  68. package/dist/runtime/context.d.ts +1 -0
  69. package/dist/runtime/context.js +17 -0
  70. package/dist/runtime/context.mjs +5 -0
  71. package/dist/runtime/database/Query.d.ts +18 -0
  72. package/dist/runtime/database/Query.js +68 -0
  73. package/dist/runtime/database/Query.mjs +49 -0
  74. package/dist/runtime/database/index.d.ts +4 -0
  75. package/dist/runtime/database/index.js +45 -0
  76. package/dist/runtime/database/index.mjs +25 -0
  77. package/dist/runtime/database/providers/local/Query.d.ts +14 -0
  78. package/dist/runtime/database/providers/local/Query.js +85 -0
  79. package/dist/runtime/database/providers/local/Query.mjs +60 -0
  80. package/dist/runtime/database/providers/local/index.d.ts +3 -0
  81. package/dist/runtime/database/providers/local/index.js +63 -0
  82. package/dist/runtime/database/providers/local/index.mjs +39 -0
  83. package/dist/runtime/database/providers/local/operations.d.ts +2 -0
  84. package/dist/runtime/database/providers/local/operations.js +83 -0
  85. package/dist/runtime/database/providers/local/operations.mjs +53 -0
  86. package/dist/runtime/database/providers/local/utils.d.ts +8 -0
  87. package/dist/runtime/database/providers/local/utils.js +28 -0
  88. package/dist/runtime/database/providers/local/utils.mjs +17 -0
  89. package/dist/runtime/index.d.ts +3 -0
  90. package/dist/runtime/index.js +44 -0
  91. package/dist/runtime/index.mjs +3 -0
  92. package/dist/runtime/navigation.d.ts +4 -0
  93. package/dist/runtime/navigation.js +176 -0
  94. package/dist/runtime/navigation.mjs +137 -0
  95. package/dist/runtime/server/api/get.d.ts +10 -0
  96. package/dist/runtime/server/api/get.js +24 -0
  97. package/dist/runtime/server/api/get.mjs +13 -0
  98. package/dist/runtime/server/api/list.d.ts +9 -0
  99. package/dist/runtime/server/api/list.js +34 -0
  100. package/dist/runtime/server/api/list.mjs +18 -0
  101. package/dist/runtime/server/api/navigation.d.ts +7 -0
  102. package/dist/runtime/server/api/navigation.js +20 -0
  103. package/dist/runtime/server/api/navigation.mjs +10 -0
  104. package/dist/runtime/server/api/preview.d.ts +3 -0
  105. package/dist/runtime/server/api/preview.js +54 -0
  106. package/dist/runtime/server/api/preview.mjs +31 -0
  107. package/dist/runtime/server/api/reload.d.ts +6 -0
  108. package/dist/runtime/server/api/reload.js +27 -0
  109. package/dist/runtime/server/api/reload.mjs +11 -0
  110. package/dist/runtime/server/api/search.d.ts +6 -0
  111. package/dist/runtime/server/api/search.js +27 -0
  112. package/dist/runtime/server/api/search.mjs +13 -0
  113. package/dist/runtime/server/content.d.ts +46 -0
  114. package/dist/runtime/server/content.js +175 -0
  115. package/dist/runtime/server/content.mjs +114 -0
  116. package/dist/runtime/server/socket.d.ts +9 -0
  117. package/dist/runtime/server/socket.js +33 -0
  118. package/dist/runtime/server/socket.mjs +20 -0
  119. package/dist/runtime/server/utils/cache.d.ts +19 -0
  120. package/dist/runtime/server/utils/cache.js +110 -0
  121. package/dist/runtime/server/utils/cache.mjs +75 -0
  122. package/dist/runtime/server/utils/index.d.ts +4 -0
  123. package/dist/runtime/server/utils/index.js +18 -0
  124. package/dist/runtime/server/utils/index.mjs +8 -0
  125. package/dist/runtime/transformers/index.d.ts +1 -0
  126. package/dist/runtime/transformers/index.js +26 -0
  127. package/dist/runtime/transformers/index.mjs +11 -0
  128. package/dist/runtime/transformers/json.d.ts +3 -0
  129. package/dist/runtime/transformers/json.js +15 -0
  130. package/dist/runtime/transformers/json.mjs +5 -0
  131. package/dist/runtime/transformers/markdown/index.d.ts +8 -0
  132. package/dist/runtime/transformers/markdown/index.js +25 -0
  133. package/dist/runtime/transformers/markdown/index.mjs +16 -0
  134. package/dist/runtime/transformers/utils/index.d.ts +1 -0
  135. package/dist/runtime/transformers/utils/index.js +18 -0
  136. package/dist/runtime/transformers/utils/index.mjs +1 -0
  137. package/dist/runtime/transformers/utils/path.d.ts +26 -0
  138. package/dist/runtime/transformers/utils/path.js +88 -0
  139. package/dist/runtime/transformers/utils/path.mjs +56 -0
  140. package/dist/runtime/utils/index.d.ts +1 -0
  141. package/dist/runtime/utils/index.js +18 -0
  142. package/dist/runtime/utils/index.mjs +1 -0
  143. package/dist/runtime/utils/log.d.ts +1 -0
  144. package/dist/runtime/utils/log.js +14 -0
  145. package/dist/runtime/utils/log.mjs +2 -0
  146. package/dist/runtime/utils/object.d.ts +9 -0
  147. package/dist/runtime/utils/object.js +22 -0
  148. package/dist/runtime/utils/object.mjs +4 -0
  149. package/dist/templates/content.mjs +50 -0
  150. package/dist/templates/docus.mjs +13 -0
  151. package/dist/templates/hot.mjs +16 -0
  152. package/dist/templates/i18n.mjs +23 -0
  153. package/dist/templates/options.mjs +46 -0
  154. package/package.json +78 -58
  155. package/shims.d.ts +24 -0
  156. package/types.d.ts +397 -0
  157. package/dist/create-docus/create-docus.js +0 -7
  158. package/dist/create-docus/index.js +0 -122
  159. package/dist/helpers.js +0 -154
  160. package/dist/index.js +0 -10
package/dist/index.mjs ADDED
@@ -0,0 +1,523 @@
1
+ import { resolveModule, useNuxt, addServerMiddleware, addPlugin, addTemplate, addPluginTemplate, resolveAlias, installModule, defineNuxtModule } from '@nuxt/kit';
2
+ import { resolve, dirname, join } from 'pathe';
3
+ import fetch from 'node-fetch';
4
+ import { joinURL } from 'ufo';
5
+ import { debounce } from 'debounce';
6
+ import { createStorage } from 'unstorage';
7
+ import fsDriver from 'unstorage/drivers/fs';
8
+ import { Server } from 'ws';
9
+ import consola from 'consola';
10
+ import { fileURLToPath } from 'url';
11
+ import fs from 'fs/promises';
12
+ import fs$1, { existsSync } from 'fs';
13
+ import jiti from 'jiti';
14
+ import clearModule from 'clear-module';
15
+ import _glob from 'glob';
16
+ import defu from 'defu';
17
+ import chalk from 'chalk';
18
+ import { getContext } from 'unctx';
19
+ import iso639 from 'iso-639-1';
20
+
21
+ const useDefaultOptions = (nuxt) => ({
22
+ apiBase: "_docus",
23
+ dirs: ["content"],
24
+ watch: nuxt.options.dev,
25
+ locales: {
26
+ codes: ["en"],
27
+ defaultLocale: "en"
28
+ },
29
+ database: {
30
+ provider: "local",
31
+ options: {}
32
+ },
33
+ ignoreList: [],
34
+ search: {
35
+ inheritanceFields: ["layout"]
36
+ },
37
+ transformers: {
38
+ markdown: {
39
+ components: [],
40
+ rehypePlugins: [],
41
+ remarkPlugins: [],
42
+ tagMap: {
43
+ a: "prose-a",
44
+ blockquote: "prose-blockquote",
45
+ "code-inline": "prose-code-inline",
46
+ code: "prose-code",
47
+ em: "prose-em",
48
+ h1: "prose-h1",
49
+ h2: "prose-h2",
50
+ h3: "prose-h3",
51
+ h4: "prose-h4",
52
+ h5: "prose-h5",
53
+ h6: "prose-h6",
54
+ hr: "prose-hr",
55
+ img: "prose-img",
56
+ li: "prose-li",
57
+ ol: "prose-ol",
58
+ p: "prose-paragraph",
59
+ strong: "prose-strong",
60
+ table: "prose-table",
61
+ tbody: "prose-tbody",
62
+ td: "prose-td",
63
+ th: "prose-th",
64
+ thead: "prose-thead",
65
+ tr: "prose-tr",
66
+ ul: "prose-ul"
67
+ }
68
+ }
69
+ }
70
+ });
71
+
72
+ let wss;
73
+ function useWebSocket() {
74
+ if (!wss)
75
+ wss = new Server({ noServer: true });
76
+ const serve = (req, socket = req.socket, head = "") => wss.handleUpgrade(req, socket, head, (client) => wss.emit("connection", client, req));
77
+ const broadcast = (data) => {
78
+ data = JSON.stringify(data);
79
+ for (const client of wss.clients) {
80
+ try {
81
+ client.send(data);
82
+ } catch (err) {
83
+ }
84
+ }
85
+ };
86
+ return {
87
+ serve,
88
+ broadcast
89
+ };
90
+ }
91
+
92
+ const logger = consola.withScope("@docus");
93
+
94
+ const distDir = resolve(typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname);
95
+ const _makeResolve = (base) => {
96
+ return (...p) => resolve(base, ...p);
97
+ };
98
+ const runtimeDir = resolve(distDir, "runtime");
99
+ const resolveRuntimeDir = _makeResolve(runtimeDir);
100
+ const templateDir = resolve(distDir, "templates");
101
+ const appDir = resolve(runtimeDir, "app");
102
+ const resolveAppDir = _makeResolve(appDir);
103
+ resolve(appDir, "components");
104
+
105
+ const THEME_CONFIG_FILE = "theme.config";
106
+ const DOCUS_CONFIG_FILE = "docus.config";
107
+
108
+ const defineThemeConfig = (config) => config;
109
+ const defineDocusConfig = (config) => config;
110
+ const loadConfig = (file, rootDir) => {
111
+ const data = {
112
+ configFile: false,
113
+ configPath: resolve(rootDir, file)
114
+ };
115
+ if (existsSync(data.configPath + ".js"))
116
+ data.configPath += ".js";
117
+ else if (existsSync(data.configPath + ".ts"))
118
+ data.configPath += ".ts";
119
+ else
120
+ return data;
121
+ clearModule(data.configPath);
122
+ try {
123
+ data.configFile = jiti(distDir)(data.configPath);
124
+ data.configFile = data.configFile?.default || data.configFile;
125
+ } catch (err) {
126
+ throw new Error(`Could not find ${file}, this file is needed for Docus.`);
127
+ }
128
+ return data;
129
+ };
130
+ const writeConfig = async (file, cacheDir, content) => {
131
+ const jsonPath = join(cacheDir, `${file}.json`);
132
+ if (!existsSync(cacheDir))
133
+ await fs.mkdir(cacheDir, { recursive: true });
134
+ if (existsSync(jsonPath))
135
+ await fs.rm(jsonPath);
136
+ await fs.writeFile(jsonPath, JSON.stringify(content.default || content), { encoding: "utf8" });
137
+ };
138
+ const loadTheme = (path, rootDir) => {
139
+ let themeConfig = {};
140
+ let themeConfigPath = resolveModule(join(path, THEME_CONFIG_FILE), { paths: rootDir });
141
+ try {
142
+ themeConfigPath = jiti(rootDir).resolve(themeConfigPath);
143
+ } catch (err) {
144
+ return themeConfig;
145
+ }
146
+ try {
147
+ themeConfig = jiti(rootDir)(themeConfigPath);
148
+ } catch (err) {
149
+ logger.warn(`Could not load theme config: ${themeConfigPath}`, err);
150
+ }
151
+ themeConfig = themeConfig.default || themeConfig;
152
+ return themeConfig;
153
+ };
154
+ const buildExternals = ["@nuxt/bridge", "@nuxt/kit", "#app", "@vue/composition-api"];
155
+ const resolveApiRoute = (route) => {
156
+ const nuxt = useNuxt();
157
+ const apiBase = nuxt.options.content?.apiBase || useDefaultOptions(nuxt).apiBase;
158
+ return joinURL("/api", apiBase, route);
159
+ };
160
+ async function loadNuxtIgnoreList(nuxt) {
161
+ const ignore = ["**/-*.*", "**/node_modules/**", "**/.git/**", "**/.**"];
162
+ const ignoreFile = resolve(nuxt.options.rootDir, ".nuxtignore");
163
+ const ignoreContent = await fs.readFile(ignoreFile, { encoding: "utf-8" }).catch(() => "");
164
+ if (ignoreContent) {
165
+ ignore.push(...ignoreContent.split("\n").filter(Boolean));
166
+ }
167
+ const refinedList = ignore.map((pattern) => {
168
+ if (typeof pattern === "string") {
169
+ return pattern.replace(/\//g, ":");
170
+ }
171
+ return pattern;
172
+ });
173
+ return refinedList;
174
+ }
175
+
176
+ function setupDevTarget(options, nuxt) {
177
+ const ws = useWebSocket();
178
+ if (options.watch) {
179
+ addServerMiddleware({
180
+ route: resolveApiRoute("reload"),
181
+ handle: resolveModule("./server/api/reload", { paths: runtimeDir }).replace(/\.js$/, ".mjs")
182
+ });
183
+ addPlugin(resolveModule("./hot", { paths: templateDir }));
184
+ const storage = createStorage();
185
+ loadNuxtIgnoreList(nuxt).then((ignoreList) => {
186
+ options.dirs.forEach((dir) => {
187
+ const [path, key] = Array.isArray(dir) ? dir : [dir, dir];
188
+ storage.mount(key, fsDriver({
189
+ base: resolve(nuxt.options.rootDir, path),
190
+ ignore: ignoreList
191
+ }));
192
+ });
193
+ });
194
+ nuxt.server.listen(0).then(({ url, server }) => {
195
+ nuxt.options.publicRuntimeConfig.$docus.wsUrl = url.replace("http", "ws");
196
+ server.on("upgrade", (req, socket, head) => ws.serve(req, socket, head));
197
+ storage.watch(createDebounceContentWatcher(async (event, key) => {
198
+ await fetch(joinURL(url, "api", options.apiBase, "reload"), {
199
+ method: "POST",
200
+ body: JSON.stringify({ event, key })
201
+ });
202
+ ws.broadcast({ event, key });
203
+ }));
204
+ });
205
+ }
206
+ }
207
+ function createDebounceContentWatcher(callback) {
208
+ const handleEvent = debounce(callback, 200);
209
+ return (event, key) => {
210
+ if (key.endsWith(".md")) {
211
+ handleEvent(event, key);
212
+ switch (event) {
213
+ case "remove":
214
+ logger.info(`You removed ${key}`);
215
+ return;
216
+ case "update":
217
+ logger.info(`You updated ${key}`);
218
+ return;
219
+ default:
220
+ logger.info(`You updated ${key}`);
221
+ }
222
+ }
223
+ };
224
+ }
225
+
226
+ const glob = (pattern, options = {}) => new Promise((resolve2, reject) => _glob(pattern, options, (err, matches) => {
227
+ if (err)
228
+ return reject(err);
229
+ resolve2(matches);
230
+ }));
231
+ const setupAppModule = (nuxt, options) => {
232
+ loadNuxtIgnoreList(nuxt).then((ignoreList) => options.ignoreList = ignoreList);
233
+ nuxt.options.alias["#docus$"] = runtimeDir;
234
+ nuxt.options.alias["#docus/composables"] = resolveAppDir("composables");
235
+ nuxt.options.alias["#docus/database"] = resolveRuntimeDir("database/providers", options.database.provider);
236
+ nuxt.options.alias["#docus/cache"] = join(nuxt.options.rootDir, "node_modules/.cache/docus");
237
+ nuxt.options.meta = nuxt.options.meta || {};
238
+ nuxt.options.head = nuxt.options.head || {};
239
+ nuxt.options.head.meta = nuxt.options.head.meta || [];
240
+ nuxt.options.head.meta.push({ charset: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" });
241
+ nuxt.options.bridge = nuxt.options.bridge || {};
242
+ nuxt.options.bridge.autoImports = false;
243
+ nuxt.options.bridge.postcss8 = true;
244
+ nuxt.options.components = Array.isArray(nuxt.options.components) ? nuxt.options.components : [];
245
+ nuxt.options.components.push({
246
+ path: resolveAppDir("components"),
247
+ isAsync: false,
248
+ prefix: "",
249
+ level: 999
250
+ });
251
+ nuxt.options.colorMode = nuxt.options.colorMode || {};
252
+ nuxt.options.colorMode.classSuffix = "";
253
+ nuxt.options.image = nuxt.options.image || {};
254
+ nuxt.options.image.domains = nuxt.options.image.domains || [];
255
+ nuxt.options.image.domains.push("https://i3.ytimg.com");
256
+ nuxt.options.target = "server";
257
+ nuxt.options.server = nuxt.options.server || {};
258
+ nuxt.options.server.port = parseInt(process.env.PORT || "4000", 10);
259
+ nuxt.options.generate = nuxt.options.generate || {};
260
+ nuxt.options.generate.routes = nuxt.options.generate.routes || [];
261
+ nuxt.options.generate.fallback = "404.html";
262
+ nuxt.options.generate.routes.push("/");
263
+ nuxt.options.nitro = nuxt.options.nitro || {};
264
+ nuxt.options.nitro.experiments = nuxt.options.nitro.experiments || {};
265
+ nuxt.options.nitro.experiments.wasm = true;
266
+ nuxt.options.nitro.inlineDynamicImports = true;
267
+ nuxt.options.nitro.externals = process.env.NITRO_PRESET === "cloudflare" ? false : {
268
+ inline: ["docus", "ohmyfetch", "property-information", "@docus/mdc"],
269
+ external: [
270
+ "vue-docgen-api",
271
+ "@nuxt/kit",
272
+ "@nuxt/image",
273
+ "@nuxtjs/i18n",
274
+ "vue-meta",
275
+ "vue-router",
276
+ "vue-i18n",
277
+ "ufo",
278
+ "vue-client-only",
279
+ "vue-no-ssr",
280
+ "ohmyfetch"
281
+ ]
282
+ };
283
+ nuxt.options.build = nuxt.options.build || {};
284
+ nuxt.options.build.transpile = nuxt.options.build.transpile || [];
285
+ nuxt.options.build.transpile.push("@docus/", "ohmyfetch", "property-information", "nuxt-component-meta", "@nuxt/bridge");
286
+ nuxt.options.layouts.default = resolveAppDir("layouts/default.vue");
287
+ nuxt.hook("build:extendRoutes", (routes) => {
288
+ const hasRoute = (name) => routes.some((route) => route.name === name);
289
+ if (!hasRoute("all")) {
290
+ routes.push({
291
+ path: "/*",
292
+ name: "all",
293
+ component: resolveAppDir("pages/_.vue")
294
+ });
295
+ }
296
+ });
297
+ nuxt.hook("build:before", async () => {
298
+ const errorPagePath = resolve(nuxt.options.srcDir, nuxt.options.dir.layouts, "error.vue");
299
+ const errorPageExists = await fs.stat(errorPagePath).catch(() => false);
300
+ if (!errorPageExists)
301
+ nuxt.options.ErrorPage = nuxt.options.ErrorPage || resolveAppDir("layouts/error.vue");
302
+ const pagesDirPath = resolve(nuxt.options.srcDir, nuxt.options.dir.pages);
303
+ const pagesDirExists = await fs.stat(pagesDirPath).catch(() => false);
304
+ if (!pagesDirExists) {
305
+ nuxt.options.build.createRoutes = () => [];
306
+ nuxt.options.watch.push(pagesDirPath);
307
+ }
308
+ });
309
+ nuxt.hook("components:dirs", async (dirs) => {
310
+ const componentsDirPath = resolve(nuxt.options.rootDir, "components");
311
+ const componentsDirStat = await fs.stat(componentsDirPath).catch(() => null);
312
+ if (componentsDirStat && componentsDirStat.isDirectory()) {
313
+ dirs.push({
314
+ path: componentsDirPath,
315
+ isAsync: false
316
+ });
317
+ const subDirs = await glob(componentsDirPath + "/**/");
318
+ subDirs.forEach((path) => dirs.push({ path, isAsync: false }));
319
+ } else {
320
+ nuxt.options.watch.push(componentsDirPath);
321
+ }
322
+ });
323
+ addTemplate({
324
+ src: resolveModule("./options", { paths: templateDir }),
325
+ filename: "docus/options.mjs",
326
+ options
327
+ });
328
+ addPluginTemplate({
329
+ src: resolveModule("./docus", { paths: templateDir })
330
+ }, {
331
+ append: true
332
+ });
333
+ nuxt.hook("modules:done", () => nuxt.callHook("docus:options", options));
334
+ };
335
+
336
+ const version = "2.1.0";
337
+
338
+ const themeContext = getContext("docus:theme");
339
+ const setThemeConfig = themeContext.set;
340
+ themeContext.use;
341
+ const configContext = getContext("docus:config");
342
+ const setDocusConfig = configContext.set;
343
+ const useDocusConfig = configContext.use;
344
+
345
+ const setupThemeModule = (nuxt) => {
346
+ const cacheDir = nuxt.options.alias["#docus/cache"];
347
+ const docusConfig = useDocusConfig();
348
+ let themeConfig = {};
349
+ if (docusConfig?.theme) {
350
+ const themePath = resolveAlias(docusConfig?.theme, nuxt.options.alias);
351
+ themeConfig = loadTheme(themePath, nuxt.options.rootDir);
352
+ }
353
+ const { configFile, configPath } = loadConfig(THEME_CONFIG_FILE, nuxt.options.rootDir);
354
+ themeConfig = defu(configFile || {}, themeConfig);
355
+ setThemeConfig(themeConfig, true);
356
+ nuxt.hook("modules:done", async () => await writeConfig(THEME_CONFIG_FILE, cacheDir, themeConfig));
357
+ nuxt.options.cli.badgeMessages.push("", chalk.bold("\u{1F484} Theme: ") + chalk.underline.yellow(themeConfig?.name || "Blank"));
358
+ nuxt.options.watch.push(configPath);
359
+ };
360
+
361
+ const defaultConfig = defineDocusConfig({
362
+ title: "Docus",
363
+ contentDir: "content",
364
+ url: "http://localhost:3000",
365
+ description: "A website built with Docus.",
366
+ template: "page"
367
+ });
368
+ const setupConfigModule = (nuxt) => {
369
+ const cacheDir = nuxt.options.alias["#docus/cache"];
370
+ const { configFile: docusConfig, configPath } = loadConfig(DOCUS_CONFIG_FILE, nuxt.options.rootDir);
371
+ const config = defu(docusConfig || {}, defaultConfig);
372
+ nuxt.options.cli.badgeMessages.push(chalk.bold("\u{1F4DD} Docus: ") + chalk.underline.yellow(`v${version}`));
373
+ setDocusConfig(config, true);
374
+ setupThemeModule(nuxt);
375
+ nuxt.options.meta.name = config.title;
376
+ nuxt.options.meta.description = config.description;
377
+ nuxt.hook("modules:done", async () => await writeConfig(DOCUS_CONFIG_FILE, cacheDir, config));
378
+ nuxt.options.watch.push(configPath);
379
+ };
380
+
381
+ const defaultI18nConfig = {
382
+ baseUrl: (nuxt) => nuxt.app?.$docus?.config?.value?.url || "",
383
+ locales: [],
384
+ defaultLocale: "en",
385
+ parsePages: false,
386
+ vuex: false,
387
+ vueI18n: {
388
+ fallbackLocale: "en",
389
+ dateTimeFormats: {
390
+ en: {
391
+ long: {
392
+ year: "numeric",
393
+ month: "short",
394
+ day: "numeric",
395
+ weekday: "short"
396
+ }
397
+ },
398
+ fr: {
399
+ long: {
400
+ year: "numeric",
401
+ month: "long",
402
+ day: "numeric",
403
+ weekday: "short"
404
+ }
405
+ }
406
+ }
407
+ }
408
+ };
409
+ const setupI18nModule = async (nuxt) => {
410
+ const config = useDocusConfig();
411
+ nuxt.options.i18n = defu(nuxt.options.i18n, defaultI18nConfig);
412
+ const i18nConfig = nuxt.options.i18n;
413
+ try {
414
+ if (!nuxt.options.i18n?.locales?.length) {
415
+ const contentDir = resolve(nuxt.options.srcDir, config?.contentDir || "content");
416
+ const contentDirectories = fs$1.readdirSync(contentDir);
417
+ i18nConfig.locales = contentDirectories.filter((lang) => !!iso639.getName(lang)).map((code) => ({ code, iso: code, name: iso639.getName(code) }));
418
+ if (!i18nConfig.locales.length)
419
+ throw new Error("No locales detected from `contentDir`! Using fallback.");
420
+ }
421
+ } catch (e) {
422
+ const defaultLocale = i18nConfig.defaultLocale || "en";
423
+ i18nConfig.locales = [
424
+ {
425
+ code: defaultLocale,
426
+ iso: defaultLocale,
427
+ name: iso639.getName(defaultLocale) || defaultLocale
428
+ }
429
+ ];
430
+ }
431
+ addPlugin(resolveModule("./i18n", { paths: templateDir }));
432
+ const localesList = i18nConfig.locales?.map(({ code }) => code).join(", ") || "en";
433
+ nuxt.options.cli.badgeMessages.push("", chalk.bold("\u{1F4D9} Languages: ") + chalk.underline.yellow(localesList));
434
+ await installModule(nuxt, "@nuxtjs/i18n");
435
+ nuxt.hook("docus:context", (docusContext) => {
436
+ const codes = nuxt.options.i18n?.locales.map((locale) => locale.code || locale);
437
+ docusContext.locales.codes = codes || docusContext.locales.codes;
438
+ docusContext.locales.defaultLocale = nuxt.options.i18n?.defaultLocale || docusContext.locales.defaultLocale;
439
+ });
440
+ nuxt.hook("build:extendRoutes", (routes) => {
441
+ const index = routes.findIndex((route) => route.path === "/*");
442
+ const [all] = routes.splice(index, 1);
443
+ routes.push(all);
444
+ });
445
+ };
446
+
447
+ async function setupComponentMetaModule(nuxt) {
448
+ const markdownTemplateHanlder = (documentation, ast) => {
449
+ if (ast.tag === "Markdown") {
450
+ const useValue = ast.props?.find((prop) => prop.name === "use")?.value;
451
+ const slotName = (typeof useValue === "object" ? useValue.content : useValue) ?? "default";
452
+ documentation.getSlotDescriptor(slotName);
453
+ }
454
+ };
455
+ await installModule(nuxt, {
456
+ src: "nuxt-component-meta/module",
457
+ options: {
458
+ parserOptions: {
459
+ addTemplateHandlers: [markdownTemplateHanlder]
460
+ }
461
+ }
462
+ });
463
+ }
464
+
465
+ const setupContentModule = (nuxt, options) => {
466
+ nuxt.hook("nitro:context", (ctx) => {
467
+ if (ctx.preset === "dev") {
468
+ for (const dir of options.dirs) {
469
+ const [path, key] = Array.isArray(dir) ? dir : [dir, dir.replace(/[/:]/g, "_")];
470
+ ctx.storage.mounts[`docus:source:${key}`] = {
471
+ driver: "fs",
472
+ driverOptions: {
473
+ base: resolve(nuxt.options.rootDir, path)
474
+ }
475
+ };
476
+ }
477
+ ctx.storage.mounts["assets:docus:build"] = {
478
+ driver: "fs",
479
+ driverOptions: {
480
+ base: resolve(nuxt.options.buildDir, "docus/build")
481
+ }
482
+ };
483
+ } else {
484
+ ctx.assets.dirs["docus:build"] = {
485
+ dir: resolve(nuxt.options.buildDir, "docus/build"),
486
+ meta: true
487
+ };
488
+ }
489
+ if (!ctx.storage.mounts["docus:preview"]) {
490
+ ctx.storage.mounts["docus:preview"] = {
491
+ driver: "memory"
492
+ };
493
+ }
494
+ });
495
+ for (const api of ["get", "list", "search", "navigation", "preview"]) {
496
+ addServerMiddleware({
497
+ route: resolveApiRoute(api),
498
+ handle: resolveModule(`./server/api/${api}`, { paths: runtimeDir }).replace(/\.js$/, ".mjs")
499
+ });
500
+ }
501
+ nuxt.options.publicRuntimeConfig.$docus = {
502
+ apiBase: options.apiBase,
503
+ tagMap: options.transformers.markdown.tagMap
504
+ };
505
+ addPlugin(resolveModule("./content", { paths: templateDir }));
506
+ };
507
+
508
+ const index = defineNuxtModule((nuxt) => ({
509
+ configKey: "content",
510
+ defaults: useDefaultOptions(nuxt),
511
+ async setup(options, nuxt2) {
512
+ if (nuxt2.options.dev)
513
+ setupDevTarget(options, nuxt2);
514
+ setupAppModule(nuxt2, options);
515
+ setupContentModule(nuxt2, options);
516
+ setupConfigModule(nuxt2);
517
+ await setupI18nModule(nuxt2);
518
+ await setupComponentMetaModule(nuxt2);
519
+ await installModule(nuxt2, "@nuxt/image");
520
+ }
521
+ }));
522
+
523
+ export { buildExternals, index as default, defineDocusConfig, defineThemeConfig, loadConfig, loadNuxtIgnoreList, loadTheme, resolveApiRoute, writeConfig };