@docsector/docsector-reader 0.3.1 → 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/bin/docsector.js CHANGED
@@ -23,7 +23,7 @@ const packageRoot = resolve(__dirname, '..')
23
23
  const args = process.argv.slice(2)
24
24
  const command = args[0]
25
25
 
26
- const VERSION = '0.3.1'
26
+ const VERSION = '0.3.2'
27
27
 
28
28
  const HELP = `
29
29
  Docsector Reader v${VERSION}
@@ -71,7 +71,7 @@ function getTemplatePackageJson (name) {
71
71
  serve: 'docsector serve'
72
72
  },
73
73
  dependencies: {
74
- '@docsector/docsector-reader': '^0.3.1',
74
+ '@docsector/docsector-reader': '^0.3.2',
75
75
  '@quasar/extras': '^1.16.12',
76
76
  'quasar': '^2.16.6',
77
77
  'vue': '^3.5.13',
@@ -673,19 +673,19 @@ const TEMPLATE_GETTING_STARTED_MD = `\
673
673
 
674
674
  Create a new Docsector documentation project:
675
675
 
676
- \\\`\\\`\\\`bash
676
+ \`\`\`bash
677
677
  npx @docsector/docsector-reader init my-docs
678
678
  cd my-docs
679
679
  npm install
680
- \\\`\\\`\\\`
680
+ \`\`\`
681
681
 
682
682
  ## Development Server
683
683
 
684
684
  Start the development server with hot-reload:
685
685
 
686
- \\\`\\\`\\\`bash
686
+ \`\`\`bash
687
687
  npm run dev
688
- \\\`\\\`\\\`
688
+ \`\`\`
689
689
 
690
690
  Open **http://localhost:8181** in your browser.
691
691
 
@@ -695,25 +695,25 @@ Here's an overview of the project files:
695
695
 
696
696
  | File / Folder | Description |
697
697
  | --- | --- |
698
- | \\\`docsector.config.js\\\` | Branding, links, languages, and GitHub config |
699
- | \\\`quasar.config.js\\\` | Quasar/Vite build configuration (via factory) |
700
- | \\\`src/pages/index.js\\\` | Page registry — defines all documentation pages |
701
- | \\\`src/pages/boot.js\\\` | Boot metadata for the home page |
702
- | \\\`src/pages/@/\\\` | Special pages (Home, 404) |
703
- | \\\`src/pages/guide/\\\` | Guide pages (Markdown files) |
704
- | \\\`src/i18n/languages/\\\` | Translation files (HJSON format) |
705
- | \\\`src/css/app.sass\\\` | Custom styles |
706
- | \\\`public/images/\\\` | Static assets (logo, flags, icons) |
698
+ | \`docsector.config.js\` | Branding, links, languages, and GitHub config |
699
+ | \`quasar.config.js\` | Quasar/Vite build configuration (via factory) |
700
+ | \`src/pages/index.js\` | Page registry — defines all documentation pages |
701
+ | \`src/pages/boot.js\` | Boot metadata for the home page |
702
+ | \`src/pages/@/\` | Special pages (Home, 404) |
703
+ | \`src/pages/guide/\` | Guide pages (Markdown files) |
704
+ | \`src/i18n/languages/\` | Translation files (HJSON format) |
705
+ | \`src/css/app.sass\` | Custom styles |
706
+ | \`public/images/\` | Static assets (logo, flags, icons) |
707
707
 
708
708
  ## Adding a Page
709
709
 
710
- 1. Register the page in \\\`src/pages/index.js\\\`
711
- 2. Create the Markdown file at \\\`src/pages/{type}/{path}.overview.{lang}.md\\\`
710
+ 1. Register the page in \`src/pages/index.js\`
711
+ 2. Create the Markdown file at \`src/pages/{type}/{path}.overview.{lang}.md\`
712
712
  3. The page will automatically appear in the sidebar navigation
713
713
 
714
714
  ## Customization
715
715
 
716
- Edit \\\`docsector.config.js\\\` to change:
716
+ Edit \`docsector.config.js\` to change:
717
717
 
718
718
  - **Branding** — logo, name, version
719
719
  - **Links** — GitHub, changelog, sponsor
@@ -722,11 +722,11 @@ Edit \\\`docsector.config.js\\\` to change:
722
722
 
723
723
  ## Building for Production
724
724
 
725
- \\\`\\\`\\\`bash
725
+ \`\`\`bash
726
726
  npm run build
727
- \\\`\\\`\\\`
727
+ \`\`\`
728
728
 
729
- The optimized SPA output will be in \\\`dist/spa/\\\`.
729
+ The optimized SPA output will be in \`dist/spa/\`.
730
730
  `
731
731
 
732
732
  // =============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsector/docsector-reader",
3
- "version": "0.3.1",
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",
@@ -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
- if (te(path)) {
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, te } = useI18n()
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
- if (te(path)) {
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
- if (te(path)) {
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) => {
@@ -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'