@docsector/docsector-reader 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docsector/docsector-reader",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A documentation rendering engine built with Vue 3, Quasar v2 and Vite. Transform Markdown into beautiful, navigable documentation sites.",
|
|
5
5
|
"productName": "Docsector Reader",
|
|
6
6
|
"author": "Rodrigo de Araujo Vieira",
|
package/src/components/DMenu.vue
CHANGED
|
@@ -100,10 +100,7 @@ const getMenuItemHeaderLabel = (meta) => {
|
|
|
100
100
|
const label = meta.menu.header.label
|
|
101
101
|
if (label[0] === '.') { // Node path
|
|
102
102
|
const path = `_.${meta.type}${label}._`
|
|
103
|
-
|
|
104
|
-
return t(path)
|
|
105
|
-
}
|
|
106
|
-
return t(path, 'en-US')
|
|
103
|
+
return t(path)
|
|
107
104
|
}
|
|
108
105
|
return label // String raw
|
|
109
106
|
}
|
|
@@ -29,7 +29,7 @@ const props = defineProps({
|
|
|
29
29
|
|
|
30
30
|
const $q = useQuasar()
|
|
31
31
|
const $route = useRoute()
|
|
32
|
-
const { t
|
|
32
|
+
const { t } = useI18n()
|
|
33
33
|
|
|
34
34
|
const getMenuItemHeaderBackground = () => {
|
|
35
35
|
return $q.dark.isActive ? 'background-color: #1D1D1D !important' : 'background-color: #f5f5f5 !important'
|
|
@@ -37,22 +37,14 @@ const getMenuItemHeaderBackground = () => {
|
|
|
37
37
|
|
|
38
38
|
const getMenuItemLabel = (item, index) => {
|
|
39
39
|
const path = `_${item.path.replace(/_$/, '').replace(/\//g, '.')}._`
|
|
40
|
-
|
|
41
|
-
return t(path)
|
|
42
|
-
} else {
|
|
43
|
-
return t(path, 'en-US')
|
|
44
|
-
}
|
|
40
|
+
return t(path)
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
const getMenuItemSubheader = (meta) => {
|
|
48
44
|
const subheader = meta.menu.subheader
|
|
49
45
|
const path = `_.${meta.type}${subheader}._`
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
return t(path)
|
|
53
|
-
} else {
|
|
54
|
-
return t(path, 'en-US')
|
|
55
|
-
}
|
|
47
|
+
return t(path)
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
const getPageStatusText = (status) => {
|
package/src/quasar.factory.js
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
* @param {Function} [options.extendViteConf] - Additional Vite config extension
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { readFileSync, existsSync } from 'fs'
|
|
26
|
+
import { readFileSync, existsSync, rmSync } from 'fs'
|
|
27
|
+
import { createHash } from 'crypto'
|
|
27
28
|
import { resolve } from 'path'
|
|
28
29
|
import HJSON from 'hjson'
|
|
29
30
|
|
|
@@ -57,6 +58,46 @@ function getPackageRoot (projectRoot) {
|
|
|
57
58
|
return projectRoot
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Create a Vite plugin that watches consumer content files (pages/index.js,
|
|
63
|
+
* i18n languages, etc.) and forces the Vite dep optimizer to re-run when
|
|
64
|
+
* they change.
|
|
65
|
+
*
|
|
66
|
+
* Why: The router module (`routes.js`) imports consumer content via the
|
|
67
|
+
* `pages` alias. Vite's dep optimizer pre-bundles the router with the
|
|
68
|
+
* consumer content inlined, but the optimizer cache hash is based on config
|
|
69
|
+
* and lockfile only — NOT on consumer source files. So when pages/index.js
|
|
70
|
+
* changes during development, the optimizer serves stale pre-bundled code
|
|
71
|
+
* until the cache is manually cleared.
|
|
72
|
+
*
|
|
73
|
+
* Fix: When pages/index.js changes, the watcher plugin clears the dep cache,
|
|
74
|
+
* sets an env flag, and restarts the server. On restart, the config reads the
|
|
75
|
+
* flag and sets `optimizeDeps.force = true`, which makes Vite generate a new
|
|
76
|
+
* browserHash — effectively busting the browser module cache.
|
|
77
|
+
*/
|
|
78
|
+
function createPagesWatchPlugin (projectRoot) {
|
|
79
|
+
const pagesIndex = resolve(projectRoot, 'src', 'pages', 'index.js')
|
|
80
|
+
return {
|
|
81
|
+
name: 'docsector-pages-watch',
|
|
82
|
+
configureServer (server) {
|
|
83
|
+
server.watcher.on('change', (changedPath) => {
|
|
84
|
+
if (changedPath === pagesIndex) {
|
|
85
|
+
server.config.logger.info(
|
|
86
|
+
'\\x1b[36m[docsector]\\x1b[0m pages/index.js changed — clearing dep cache and restarting...',
|
|
87
|
+
{ timestamp: true }
|
|
88
|
+
)
|
|
89
|
+
// Signal the restarted config to force a new optimizer hash
|
|
90
|
+
process.env.__DOCSECTOR_FORCE_OPTIMIZE = '1'
|
|
91
|
+
// Delete the stale optimizer cache
|
|
92
|
+
const cacheDir = resolve(projectRoot, 'node_modules', '.q-cache')
|
|
93
|
+
rmSync(cacheDir, { recursive: true, force: true })
|
|
94
|
+
server.restart()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
60
101
|
/**
|
|
61
102
|
* Create the HJSON Vite plugin for loading .hjson files as ES modules.
|
|
62
103
|
*/
|
|
@@ -145,6 +186,7 @@ export function createQuasarConfig (options = {}) {
|
|
|
145
186
|
|
|
146
187
|
vitePlugins: [
|
|
147
188
|
createHjsonPlugin(),
|
|
189
|
+
createPagesWatchPlugin(projectRoot),
|
|
148
190
|
...vitePlugins
|
|
149
191
|
],
|
|
150
192
|
|
|
@@ -152,6 +194,32 @@ export function createQuasarConfig (options = {}) {
|
|
|
152
194
|
viteConf.resolve = viteConf.resolve || {}
|
|
153
195
|
viteConf.resolve.alias = viteConf.resolve.alias || {}
|
|
154
196
|
|
|
197
|
+
// When the pages watcher plugin triggers a restart, it sets this env
|
|
198
|
+
// flag so we force Vite to generate a fresh browserHash. This busts
|
|
199
|
+
// the browser's module cache for pre-bundled deps whose content changed.
|
|
200
|
+
viteConf.optimizeDeps = viteConf.optimizeDeps || {}
|
|
201
|
+
if (process.env.__DOCSECTOR_FORCE_OPTIMIZE) {
|
|
202
|
+
delete process.env.__DOCSECTOR_FORCE_OPTIMIZE
|
|
203
|
+
viteConf.optimizeDeps.force = true
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Include a hash of pages/index.js in the optimizer config so that
|
|
207
|
+
// Vite's configHash (and thus browserHash) changes whenever page
|
|
208
|
+
// definitions change. This prevents the browser from serving stale
|
|
209
|
+
// pre-bundled router modules from its module cache.
|
|
210
|
+
const pagesFile = resolve(projectRoot, 'src', 'pages', 'index.js')
|
|
211
|
+
if (existsSync(pagesFile)) {
|
|
212
|
+
const pagesHash = createHash('sha256')
|
|
213
|
+
.update(readFileSync(pagesFile))
|
|
214
|
+
.digest('hex')
|
|
215
|
+
.slice(0, 8)
|
|
216
|
+
viteConf.optimizeDeps.esbuildOptions = viteConf.optimizeDeps.esbuildOptions || {}
|
|
217
|
+
viteConf.optimizeDeps.esbuildOptions.define = {
|
|
218
|
+
...(viteConf.optimizeDeps.esbuildOptions.define || {}),
|
|
219
|
+
__DOCSECTOR_PAGES_HASH__: JSON.stringify(pagesHash)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
155
223
|
// Deduplicate Vue ecosystem packages to prevent dual-instance issues.
|
|
156
224
|
// When the package is installed from NPM, Vue, vue-router, vuex, etc.
|
|
157
225
|
// can end up duplicated (one copy in consumer's node_modules, another
|
|
@@ -180,11 +248,15 @@ export function createQuasarConfig (options = {}) {
|
|
|
180
248
|
'hjson', 'q-colorize-mixin'
|
|
181
249
|
]
|
|
182
250
|
|
|
183
|
-
// Exclude boot files from pre-bundling.
|
|
251
|
+
// Exclude boot files and the router from pre-bundling.
|
|
184
252
|
// Boot files (especially boot/i18n) import the consumer's src/i18n/index.js
|
|
185
253
|
// which uses import.meta.glob — a compile-time Vite directive that only
|
|
186
254
|
// works in source files. If pre-bundled, the glob calls become dead code
|
|
187
255
|
// and no i18n messages are loaded.
|
|
256
|
+
// The router is excluded because routes.js imports consumer content via
|
|
257
|
+
// the `pages` alias. If pre-bundled, consumer content gets embedded in
|
|
258
|
+
// the optimizer cache whose hash doesn't track source file changes,
|
|
259
|
+
// causing stale routes after editing pages/index.js.
|
|
188
260
|
viteConf.optimizeDeps.exclude = [
|
|
189
261
|
...(viteConf.optimizeDeps.exclude || []),
|
|
190
262
|
'boot/i18n', 'boot/store', 'boot/QZoom', 'boot/axios'
|