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