@ramathibodi/nuxt-commons 0.1.72 → 0.1.74

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 (90) hide show
  1. package/README.md +74 -55
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1 -0
  4. package/dist/runtime/components/Alert.vue +4 -0
  5. package/dist/runtime/components/BarcodeReader.vue +8 -0
  6. package/dist/runtime/components/ExportCSV.vue +13 -5
  7. package/dist/runtime/components/FileBtn.vue +17 -5
  8. package/dist/runtime/components/ImportCSV.vue +14 -2
  9. package/dist/runtime/components/MrzReader.vue +168 -0
  10. package/dist/runtime/components/SplitterPanel.vue +9 -1
  11. package/dist/runtime/components/TabsGroup.vue +9 -1
  12. package/dist/runtime/components/TextBarcode.vue +13 -1
  13. package/dist/runtime/components/device/IdCardButton.vue +15 -3
  14. package/dist/runtime/components/device/IdCardWebSocket.vue +18 -6
  15. package/dist/runtime/components/device/Scanner.vue +18 -6
  16. package/dist/runtime/components/dialog/Confirm.vue +20 -8
  17. package/dist/runtime/components/dialog/Host.vue +4 -0
  18. package/dist/runtime/components/dialog/Index.vue +17 -5
  19. package/dist/runtime/components/dialog/Loading.vue +14 -2
  20. package/dist/runtime/components/dialog/default/Confirm.vue +20 -8
  21. package/dist/runtime/components/dialog/default/Loading.vue +14 -2
  22. package/dist/runtime/components/dialog/default/Notify.vue +18 -6
  23. package/dist/runtime/components/dialog/default/Printing.vue +14 -2
  24. package/dist/runtime/components/dialog/default/VerifyUser.vue +20 -8
  25. package/dist/runtime/components/document/Form.vue +10 -2
  26. package/dist/runtime/components/document/TemplateBuilder.vue +14 -2
  27. package/dist/runtime/components/form/ActionPad.vue +19 -7
  28. package/dist/runtime/components/form/Birthdate.vue +15 -3
  29. package/dist/runtime/components/form/CheckboxGroup.vue +17 -5
  30. package/dist/runtime/components/form/CodeEditor.vue +11 -3
  31. package/dist/runtime/components/form/Date.vue +23 -11
  32. package/dist/runtime/components/form/DateTime.vue +29 -17
  33. package/dist/runtime/components/form/Dialog.vue +21 -9
  34. package/dist/runtime/components/form/EditPad.vue +20 -8
  35. package/dist/runtime/components/form/File.vue +18 -6
  36. package/dist/runtime/components/form/Hidden.vue +15 -3
  37. package/dist/runtime/components/form/Iterator.vue +43 -31
  38. package/dist/runtime/components/form/Login.vue +18 -6
  39. package/dist/runtime/components/form/Pad.vue +24 -12
  40. package/dist/runtime/components/form/SignPad.vue +13 -5
  41. package/dist/runtime/components/form/System.vue +10 -2
  42. package/dist/runtime/components/form/Table.vue +31 -19
  43. package/dist/runtime/components/form/TableData.vue +21 -9
  44. package/dist/runtime/components/form/Time.vue +16 -4
  45. package/dist/runtime/components/form/images/Capture.vue +17 -9
  46. package/dist/runtime/components/form/images/Edit.vue +16 -4
  47. package/dist/runtime/components/form/images/Field.vue +21 -10
  48. package/dist/runtime/components/form/images/Pad.vue +12 -0
  49. package/dist/runtime/components/label/Date.vue +12 -4
  50. package/dist/runtime/components/label/DateAgo.vue +13 -5
  51. package/dist/runtime/components/label/DateCount.vue +13 -5
  52. package/dist/runtime/components/label/Field.vue +14 -6
  53. package/dist/runtime/components/label/FormatMoney.vue +11 -3
  54. package/dist/runtime/components/label/Mask.vue +11 -3
  55. package/dist/runtime/components/label/Object.vue +11 -3
  56. package/dist/runtime/components/master/Autocomplete.vue +25 -7
  57. package/dist/runtime/components/master/Combobox.vue +26 -8
  58. package/dist/runtime/components/master/RadioGroup.vue +17 -5
  59. package/dist/runtime/components/master/Select.vue +24 -7
  60. package/dist/runtime/components/master/label.vue +14 -6
  61. package/dist/runtime/components/model/Autocomplete.vue +31 -12
  62. package/dist/runtime/components/model/Combobox.vue +30 -12
  63. package/dist/runtime/components/model/Pad.vue +15 -3
  64. package/dist/runtime/components/model/Select.vue +27 -7
  65. package/dist/runtime/components/model/Table.vue +30 -18
  66. package/dist/runtime/components/model/iterator.vue +36 -28
  67. package/dist/runtime/components/model/label.vue +16 -8
  68. package/dist/runtime/components/pdf/Print.vue +17 -5
  69. package/dist/runtime/components/pdf/View.vue +18 -6
  70. package/dist/runtime/composables/alert.d.ts +4 -0
  71. package/dist/runtime/composables/api.d.ts +4 -0
  72. package/dist/runtime/composables/document/templateFormHidden.d.ts +4 -0
  73. package/dist/runtime/composables/localStorageModel.d.ts +4 -0
  74. package/dist/runtime/composables/lookupList.d.ts +16 -5
  75. package/dist/runtime/composables/lookupList.js +71 -21
  76. package/dist/runtime/composables/lookupListMaster.d.ts +4 -0
  77. package/dist/runtime/composables/lookupListMaster.js +9 -4
  78. package/dist/runtime/composables/menu.d.ts +4 -0
  79. package/dist/runtime/composables/useMrzReader.d.ts +48 -0
  80. package/dist/runtime/composables/useMrzReader.js +423 -0
  81. package/dist/runtime/composables/useTesseract.d.ts +16 -0
  82. package/dist/runtime/composables/useTesseract.js +45 -0
  83. package/dist/runtime/utils/asset.d.ts +2 -0
  84. package/dist/runtime/utils/asset.js +49 -0
  85. package/package.json +12 -3
  86. package/scripts/enrich-vue-docs-from-ai.mjs +197 -0
  87. package/scripts/generate-ai-summary.mjs +321 -0
  88. package/scripts/generate-composables-md.mjs +129 -0
  89. package/templates/public/tesseract/mrz.traineddata.gz +0 -0
  90. package/templates/public/tesseract/ocrb.traineddata.gz +0 -0
@@ -0,0 +1,197 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ const rootDir = process.cwd()
5
+ const aiPath = path.join(rootDir, 'docs/ai-summary.json')
6
+ const docsDir = path.join(rootDir, 'docs/components')
7
+
8
+ if (!fs.existsSync(aiPath) || !fs.existsSync(docsDir)) {
9
+ console.log('Skip enrich: required docs/ai-summary.json or docs/components missing.')
10
+ process.exit(0)
11
+ }
12
+
13
+ const ai = JSON.parse(fs.readFileSync(aiPath, 'utf8'))
14
+ const componentMap = new Map(ai.components.map((c) => [c.path, c]))
15
+
16
+ function toPosix(p) {
17
+ return p.split(path.sep).join('/')
18
+ }
19
+
20
+ function guessSourcePathFromDoc(docFile) {
21
+ const rel = toPosix(path.relative(docsDir, docFile))
22
+ const noExt = rel.replace(/\.md$/, '')
23
+ return `src/runtime/components/${noExt}.vue`
24
+ }
25
+
26
+ function mdEscape(str) {
27
+ return String(str ?? '').replace(/\|/g, '\\|')
28
+ }
29
+
30
+ const propHints = {
31
+ modelName: { type: 'string', description: 'GraphQL model name used to resolve query/mutation operations.' },
32
+ modelBy: { type: 'Record<string, any>', description: 'Base filter object applied to read/search/create flows.' },
33
+ modelKey: { type: 'string', description: 'Unique key field used to identify and update existing rows/items.' },
34
+ fields: { type: 'Array<string | object>', description: 'Requested GraphQL fields used when loading records.' },
35
+ headers: { type: 'any[]', description: 'Column definitions used by table/iterator rendering.' },
36
+ itemTitle: { type: 'string', description: 'Item field used as display label.' },
37
+ itemValue: { type: 'string', description: 'Item field used as stored value.' },
38
+ filterKeys: { type: 'string | string[]', description: 'Keys used for client-side filtering/searching.' },
39
+ multiple: { type: 'boolean', description: 'Enables multi-select mode.' },
40
+ placeholder: { type: 'string', description: 'Placeholder text shown when input has no value.' },
41
+ noDataText: { type: 'string', description: 'Text shown when no matching data is available.' },
42
+ }
43
+
44
+ function inferTypeFromDocDefault(defaultCell) {
45
+ const v = (defaultCell || '').trim().replace(/^`|`$/g, '')
46
+ if (!v || v === '-' || v === 'undefined') return undefined
47
+ if (v === 'true' || v === 'false') return 'boolean'
48
+ if (/^-?\d+(\.\d+)?$/.test(v)) return 'number'
49
+ if ((v.startsWith("'") && v.endsWith("'")) || (v.startsWith('"') && v.endsWith('"'))) return 'string'
50
+ if (v.includes('=> []') || v === '[]') return 'any[]'
51
+ if (v.includes('=> ({') || v === '{}' || v === 'null') return 'Record<string, any>'
52
+ return undefined
53
+ }
54
+
55
+ function inferEventDescription(eventName, payload) {
56
+ if (eventName === 'update:modelValue') return 'Emitted when the bound model value changes.'
57
+ if (eventName === 'open:dialog') return 'Emitted when the component opens its dialog/form editor.'
58
+ if (eventName === 'close:dialog') return 'Emitted when the component closes its dialog/form editor.'
59
+ if (eventName === 'create') return 'Emitted after a create action completes.'
60
+ if (eventName === 'update') return 'Emitted after an update action completes.'
61
+ if (eventName === 'delete') return 'Emitted after a delete action completes.'
62
+ if (eventName === 'import') return 'Emitted after import data is parsed and ready.'
63
+ if (eventName === 'error') return 'Emitted when an operation fails.'
64
+ if (payload) return `Emits payload: \`${payload}\`.`
65
+ return 'Custom event emitted by this component.'
66
+ }
67
+
68
+ function splitRow(line) {
69
+ const cols = line.split('|').slice(1, -1).map((c) => c.trim())
70
+ return cols
71
+ }
72
+
73
+ function joinRow(cols) {
74
+ return `| ${cols.join(' | ')} |`
75
+ }
76
+
77
+ function updatePropsTable(lines, sectionStartIdx, component) {
78
+ // table starts after "## Props", header and separator rows
79
+ let i = sectionStartIdx + 1
80
+ while (i < lines.length && !lines[i].startsWith('|')) i++
81
+ if (i + 1 >= lines.length) return 0
82
+
83
+ const propsByName = new Map((component.props || []).map((p) => [p.name, p]))
84
+ let changed = 0
85
+
86
+ // skip header + separator
87
+ for (let r = i + 2; r < lines.length; r++) {
88
+ const line = lines[r]
89
+ if (!line.startsWith('|')) break
90
+ const cols = splitRow(line)
91
+ if (cols.length < 5) continue
92
+
93
+ const propName = cols[0].replace(/`/g, '').trim()
94
+ const meta = propsByName.get(propName)
95
+ const hint = propHints[propName]
96
+
97
+ const desc = cols[1]
98
+ const type = cols[2]
99
+ const def = cols[4]
100
+
101
+ if ((!desc || desc === '-') && meta?.description) cols[1] = mdEscape(meta.description)
102
+ else if ((!desc || desc === '-') && hint?.description) cols[1] = mdEscape(hint.description)
103
+
104
+ if ((type === '-' || !type) && meta?.type) cols[2] = `\`${mdEscape(meta.type)}\``
105
+ else if ((type === '-' || !type) && hint?.type) cols[2] = `\`${mdEscape(hint.type)}\``
106
+ else if ((type === '-' || !type)) {
107
+ const inferred = inferTypeFromDocDefault(def)
108
+ if (inferred) cols[2] = `\`${mdEscape(inferred)}\``
109
+ }
110
+
111
+ if ((!def || def === '-') && meta?.default !== undefined) cols[4] = `\`${mdEscape(meta.default)}\``
112
+
113
+ const next = joinRow(cols)
114
+ if (next !== line) {
115
+ lines[r] = next
116
+ changed++
117
+ }
118
+ }
119
+
120
+ return changed
121
+ }
122
+
123
+ function updateEventsTable(lines, sectionStartIdx, component) {
124
+ let i = sectionStartIdx + 1
125
+ while (i < lines.length && !lines[i].startsWith('|')) i++
126
+ if (i + 1 >= lines.length) return 0
127
+
128
+ const emitsByName = new Map((component.emits || []).map((e) => [e.event, e]))
129
+ let changed = 0
130
+
131
+ // skip header + separator
132
+ for (let r = i + 2; r < lines.length; r++) {
133
+ const line = lines[r]
134
+ if (!line.startsWith('|')) break
135
+ const cols = splitRow(line)
136
+ while (cols.length < 3) cols.push('')
137
+
138
+ const eventName = cols[0].replace(/`/g, '').trim()
139
+ const meta = emitsByName.get(eventName)
140
+ if (!meta) continue
141
+
142
+ const propsCol = cols[1]
143
+ const descCol = cols[2]
144
+
145
+ if ((!propsCol || propsCol === '-') && meta.payload) cols[1] = `\`${mdEscape(meta.payload)}\``
146
+ if (!descCol || descCol === '-') cols[2] = mdEscape(inferEventDescription(eventName, meta.payload))
147
+
148
+ const next = joinRow(cols)
149
+ if (next !== line) {
150
+ lines[r] = next
151
+ changed++
152
+ }
153
+ }
154
+
155
+ return changed
156
+ }
157
+
158
+ function processDocFile(docFile) {
159
+ const sourcePath = guessSourcePathFromDoc(docFile)
160
+ const component = componentMap.get(sourcePath)
161
+ if (!component) return 0
162
+
163
+ const content = fs.readFileSync(docFile, 'utf8')
164
+ const lines = content.split('\n')
165
+ let changed = 0
166
+
167
+ for (let i = 0; i < lines.length; i++) {
168
+ if (lines[i].trim() === '## Props') changed += updatePropsTable(lines, i, component)
169
+ if (lines[i].trim() === '## Events') changed += updateEventsTable(lines, i, component)
170
+ }
171
+
172
+ if (changed > 0) fs.writeFileSync(docFile, lines.join('\n'))
173
+ return changed
174
+ }
175
+
176
+ function walkMd(dir) {
177
+ const out = []
178
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
179
+ const full = path.join(dir, entry.name)
180
+ if (entry.isDirectory()) out.push(...walkMd(full))
181
+ else if (entry.name.endsWith('.md')) out.push(full)
182
+ }
183
+ return out
184
+ }
185
+
186
+ const mdFiles = walkMd(docsDir)
187
+ let changedFiles = 0
188
+ let changedRows = 0
189
+ for (const file of mdFiles) {
190
+ const changed = processDocFile(file)
191
+ if (changed > 0) {
192
+ changedFiles++
193
+ changedRows += changed
194
+ }
195
+ }
196
+
197
+ console.log(`Enriched ${changedRows} table rows across ${changedFiles} files.`)
@@ -0,0 +1,321 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ const rootDir = process.cwd()
5
+ const componentsDir = path.join(rootDir, 'src/runtime/components')
6
+ const composablesDir = path.join(rootDir, 'src/runtime/composables')
7
+ const outMdFile = path.join(rootDir, 'docs/ai-summary.md')
8
+ const outJsonFile = path.join(rootDir, 'docs/ai-summary.json')
9
+ const outTypeIndexFile = path.join(rootDir, 'docs/type-index.json')
10
+
11
+ function walkFiles(dir, exts = new Set(['.vue', '.ts'])) {
12
+ const result = []
13
+ if (!fs.existsSync(dir)) return result
14
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
15
+ const full = path.join(dir, entry.name)
16
+ if (entry.isDirectory()) {
17
+ result.push(...walkFiles(full, exts))
18
+ } else if (exts.has(path.extname(entry.name))) {
19
+ result.push(full)
20
+ }
21
+ }
22
+ return result.sort((a, b) => a.localeCompare(b))
23
+ }
24
+
25
+ function toPosix(p) {
26
+ return p.split(path.sep).join('/')
27
+ }
28
+
29
+ function extractTopDescription(content) {
30
+ const m = content.match(/\/\*\*([\s\S]*?)\*\//)
31
+ if (!m) return 'No top-level description found.'
32
+ const lines = m[1]
33
+ .split('\n')
34
+ .map((l) => l.replace(/^\s*\*\s?/, '').trim())
35
+ .filter(Boolean)
36
+ .filter((l) => !l.toLowerCase().includes('vue-docgen'))
37
+ return lines[0] || 'No top-level description found.'
38
+ }
39
+
40
+ function compact(str) {
41
+ return str.replace(/\s+/g, ' ').trim()
42
+ }
43
+
44
+ function findInterfaceBody(content, interfaceName) {
45
+ const needle = `interface ${interfaceName}`
46
+ const start = content.indexOf(needle)
47
+ if (start === -1) return null
48
+
49
+ const braceStart = content.indexOf('{', start)
50
+ if (braceStart === -1) return null
51
+
52
+ let depth = 0
53
+ for (let i = braceStart; i < content.length; i++) {
54
+ const ch = content[i]
55
+ if (ch === '{') depth++
56
+ if (ch === '}') depth--
57
+ if (depth === 0) {
58
+ return content.slice(braceStart + 1, i)
59
+ }
60
+ }
61
+ return null
62
+ }
63
+
64
+ function extractWithDefaults(content) {
65
+ const defaults = {}
66
+ const m = content.match(/withDefaults\s*\(\s*defineProps[\s\S]*?,\s*\{([\s\S]*?)\}\s*\)/)
67
+ if (!m) return defaults
68
+
69
+ const lines = m[1].split('\n')
70
+ for (const line of lines) {
71
+ const clean = line.trim()
72
+ if (!clean || clean.startsWith('//')) continue
73
+ const kv = clean.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(.+?)(?:,\s*)?(?:\/\/\s*(.*))?$/)
74
+ if (!kv) continue
75
+ const key = kv[1]
76
+ const rawValue = kv[2].trim()
77
+ const description = (kv[3] || '').trim()
78
+ defaults[key] = { value: rawValue, description }
79
+ }
80
+
81
+ return defaults
82
+ }
83
+
84
+ function inferTypeFromDefault(rawValue) {
85
+ if (rawValue === 'true' || rawValue === 'false') return 'boolean'
86
+ if (rawValue === 'null') return 'null'
87
+ if (/^['"].*['"]$/.test(rawValue)) return 'string'
88
+ if (/^-?\d+(\.\d+)?$/.test(rawValue)) return 'number'
89
+ if (/^\(\)\s*=>\s*\[\s*\]$/.test(rawValue)) return 'any[]'
90
+ if (/^\(\)\s*=>\s*\(\s*\{\s*\}\s*\)$/.test(rawValue)) return 'Record<string, any>'
91
+ if (/^\(\)\s*=>\s*\[/.test(rawValue)) return 'any[]'
92
+ if (/^\(\)\s*=>\s*\(\s*\{/.test(rawValue)) return 'Record<string, any>'
93
+ return 'unknown'
94
+ }
95
+
96
+ function extractProps(content) {
97
+ const props = []
98
+ const ifaceBody = findInterfaceBody(content, 'Props')
99
+ const defaults = extractWithDefaults(content)
100
+
101
+ if (ifaceBody) {
102
+ const lines = ifaceBody.split('\n')
103
+ for (const line of lines) {
104
+ const m = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)(\?)?\s*:\s*([^/;]+(?:\|[^/;]+)*)[;]?\s*(?:\/\/\s*(.+))?\s*$/)
105
+ if (m) {
106
+ const name = m[1]
107
+ const optional = !!m[2]
108
+ const type = compact(m[3].trim())
109
+ const description = (m[4] || '').trim()
110
+ props.push({
111
+ name,
112
+ type,
113
+ required: !optional,
114
+ default: Object.prototype.hasOwnProperty.call(defaults, name) ? defaults[name].value : undefined,
115
+ description: description || (defaults[name]?.description || ''),
116
+ })
117
+ }
118
+ }
119
+ }
120
+
121
+ // Fallback for components where Props is empty and typed props come from imported intersections.
122
+ if (!props.length && Object.keys(defaults).length) {
123
+ for (const [name, meta] of Object.entries(defaults)) {
124
+ props.push({
125
+ name,
126
+ type: inferTypeFromDefault(meta.value),
127
+ required: false,
128
+ default: meta.value,
129
+ description: meta.description || 'Inferred from withDefaults()',
130
+ })
131
+ }
132
+ }
133
+
134
+ return props
135
+ }
136
+
137
+ function extractEmits(content) {
138
+ const emits = []
139
+
140
+ const typed = content.match(/defineEmits<\{([\s\S]*?)\}>\(\)/)
141
+ if (typed) {
142
+ const overloads = typed[1].matchAll(/\(\s*e\s*:\s*'([^']+)'\s*(?:,\s*([^)]*))?\)\s*:\s*void/g)
143
+ for (const m of overloads) {
144
+ emits.push({
145
+ event: m[1],
146
+ payload: m[2] ? compact(m[2]) : undefined,
147
+ })
148
+ }
149
+ }
150
+
151
+ const arr = content.match(/defineEmits\s*\(\s*\[([\s\S]*?)\]\s*\)/)
152
+ if (arr) {
153
+ const names = arr[1].matchAll(/'([^']+)'|"([^"]+)"/g)
154
+ for (const m of names) {
155
+ emits.push({ event: m[1] || m[2] })
156
+ }
157
+ }
158
+
159
+ return emits
160
+ }
161
+
162
+ function extractExports(content) {
163
+ const functions = []
164
+ const constants = []
165
+ const interfaces = []
166
+ const types = []
167
+ const enums = []
168
+
169
+ const fnMatches = content.matchAll(/export\s+function\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*?)\)\s*(?::\s*([^({;\n]+(?:<[\s\S]*?>)?))?\s*\{/g)
170
+ for (const m of fnMatches) {
171
+ functions.push({
172
+ name: m[1],
173
+ params: compact(m[2]),
174
+ returns: m[3] ? compact(m[3]) : undefined,
175
+ signature: compact(`function ${m[1]}(${m[2]})${m[3] ? `: ${m[3]}` : ''}`),
176
+ })
177
+ }
178
+
179
+ const constMatches = content.matchAll(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?::\s*([^=;\n]+))?\s*=/g)
180
+ for (const m of constMatches) {
181
+ constants.push({
182
+ name: m[1],
183
+ type: m[2] ? compact(m[2]) : undefined,
184
+ })
185
+ }
186
+
187
+ const interfaceMatches = content.matchAll(/export\s+interface\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\n\}/g)
188
+ for (const m of interfaceMatches) {
189
+ interfaces.push({
190
+ name: m[1],
191
+ shape: compact(m[2]),
192
+ })
193
+ }
194
+
195
+ const typeMatches = content.matchAll(/export\s+type\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([^;\n]+(?:\n[^;\n]+)*)/g)
196
+ for (const m of typeMatches) {
197
+ types.push({
198
+ name: m[1],
199
+ definition: compact(m[2].replace(/\n/g, ' ')),
200
+ })
201
+ }
202
+
203
+ const enumMatches = content.matchAll(/export\s+enum\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}/g)
204
+ for (const m of enumMatches) {
205
+ const members = m[2]
206
+ .split('\n')
207
+ .map((line) => line.trim())
208
+ .filter(Boolean)
209
+ .map((line) => line.replace(/,$/, ''))
210
+ enums.push({
211
+ name: m[1],
212
+ members,
213
+ })
214
+ }
215
+
216
+ return { functions, constants, interfaces, types, enums }
217
+ }
218
+
219
+ const componentFiles = walkFiles(componentsDir, new Set(['.vue']))
220
+ const composableFiles = walkFiles(composablesDir, new Set(['.ts']))
221
+
222
+ const generatedAt = new Date().toISOString()
223
+ const docModel = {
224
+ generatedAt,
225
+ scope: {
226
+ componentCount: componentFiles.length,
227
+ composableCount: composableFiles.length,
228
+ },
229
+ components: [],
230
+ composables: [],
231
+ }
232
+
233
+ const lines = []
234
+ lines.push('# AI Summary')
235
+ lines.push('')
236
+ lines.push('AI-first summary generated from source files with explicit type metadata.')
237
+ lines.push('')
238
+ lines.push(`Generated at: ${generatedAt}`)
239
+ lines.push('')
240
+ lines.push('## Scope')
241
+ lines.push('')
242
+ lines.push(`- Components: ${componentFiles.length}`)
243
+ lines.push(`- Composables: ${composableFiles.length}`)
244
+ lines.push('')
245
+ lines.push('## Components')
246
+ lines.push('')
247
+
248
+ for (const file of componentFiles) {
249
+ const rel = toPosix(path.relative(rootDir, file))
250
+ const content = fs.readFileSync(file, 'utf8')
251
+ const summary = extractTopDescription(content)
252
+ const props = extractProps(content)
253
+ const emits = extractEmits(content)
254
+ const componentEntry = {
255
+ path: rel,
256
+ summary,
257
+ props,
258
+ emits,
259
+ }
260
+ docModel.components.push(componentEntry)
261
+
262
+ lines.push(`### \`${rel}\``)
263
+ lines.push(`- Summary: ${summary}`)
264
+ if (props.length) {
265
+ lines.push(`- Props (${props.length}):`)
266
+ for (const prop of props) {
267
+ const chunks = [
268
+ `type=${prop.type}`,
269
+ prop.required ? 'required=true' : 'required=false',
270
+ ]
271
+ if (prop.default !== undefined) chunks.push(`default=${prop.default}`)
272
+ if (prop.description) chunks.push(`desc=${prop.description}`)
273
+ lines.push(` - \`${prop.name}\` { ${chunks.join(' | ')} }`)
274
+ }
275
+ } else {
276
+ lines.push('- Props: None declared in a local `Props` interface.')
277
+ }
278
+ if (emits.length) {
279
+ lines.push(`- Emits (${emits.length}):`)
280
+ for (const e of emits) {
281
+ lines.push(` - \`${e.event}\`${e.payload ? ` payload: ${e.payload}` : ''}`)
282
+ }
283
+ } else {
284
+ lines.push('- Emits: None detected.')
285
+ }
286
+ lines.push('')
287
+ }
288
+
289
+ lines.push('## Composables')
290
+ lines.push('')
291
+
292
+ for (const file of composableFiles) {
293
+ const rel = toPosix(path.relative(rootDir, file))
294
+ const content = fs.readFileSync(file, 'utf8')
295
+ const summary = extractTopDescription(content)
296
+ const exports = extractExports(content)
297
+ const composableEntry = {
298
+ path: rel,
299
+ summary,
300
+ exports,
301
+ }
302
+ docModel.composables.push(composableEntry)
303
+
304
+ lines.push(`### \`${rel}\``)
305
+ lines.push(`- Summary: ${summary}`)
306
+ lines.push(`- Export functions (${exports.functions.length}): ${exports.functions.map((f) => `\`${f.signature}\``).join(', ') || 'none'}`)
307
+ lines.push(`- Export interfaces (${exports.interfaces.length}): ${exports.interfaces.map((i) => `\`${i.name}\``).join(', ') || 'none'}`)
308
+ lines.push(`- Export types (${exports.types.length}): ${exports.types.map((t) => `\`${t.name}\``).join(', ') || 'none'}`)
309
+ lines.push(`- Export consts (${exports.constants.length}): ${exports.constants.map((c) => `\`${c.name}\``).join(', ') || 'none'}`)
310
+ lines.push(`- Export enums (${exports.enums.length}): ${exports.enums.map((e) => `\`${e.name}\``).join(', ') || 'none'}`)
311
+ lines.push('')
312
+ }
313
+
314
+ fs.mkdirSync(path.dirname(outMdFile), { recursive: true })
315
+ fs.writeFileSync(outMdFile, lines.join('\n'))
316
+ fs.writeFileSync(outJsonFile, JSON.stringify(docModel, null, 2))
317
+ fs.writeFileSync(outTypeIndexFile, JSON.stringify(docModel, null, 2))
318
+
319
+ console.log(`Generated ${toPosix(path.relative(rootDir, outMdFile))}`)
320
+ console.log(`Generated ${toPosix(path.relative(rootDir, outJsonFile))}`)
321
+ console.log(`Generated ${toPosix(path.relative(rootDir, outTypeIndexFile))}`)
@@ -0,0 +1,129 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ const rootDir = process.cwd()
5
+ const aiSummaryPath = path.join(rootDir, 'docs/ai-summary.json')
6
+ const outDir = path.join(rootDir, 'docs/composables-md')
7
+
8
+ if (!fs.existsSync(aiSummaryPath)) {
9
+ console.error('docs/ai-summary.json not found. Run: npm run docs:ai:summary')
10
+ process.exit(1)
11
+ }
12
+
13
+ const ai = JSON.parse(fs.readFileSync(aiSummaryPath, 'utf8'))
14
+ const composables = ai.composables || []
15
+
16
+ function safeName(filePath) {
17
+ return filePath
18
+ .replace(/^src\/runtime\/composables\//, '')
19
+ .replace(/\//g, '__')
20
+ .replace(/\.ts$/, '')
21
+ }
22
+
23
+ function mdEscape(str) {
24
+ return String(str ?? '').replace(/\|/g, '\\|')
25
+ }
26
+
27
+ fs.mkdirSync(outDir, { recursive: true })
28
+
29
+ const index = []
30
+ index.push('# Composables (Markdown)')
31
+ index.push('')
32
+ index.push(`Generated at: ${ai.generatedAt}`)
33
+ index.push('')
34
+ index.push('| Composable | Source |')
35
+ index.push('| ---------- | ------ |')
36
+
37
+ for (const c of composables) {
38
+ const fileBase = safeName(c.path)
39
+ const outFile = path.join(outDir, `${fileBase}.md`)
40
+ const content = []
41
+
42
+ content.push(`# ${fileBase}`)
43
+ content.push('')
44
+ content.push(`- Source: \`${c.path}\``)
45
+ content.push(`- Summary: ${c.summary || ''}`)
46
+ content.push('')
47
+
48
+ const exp = c.exports || {}
49
+ const functions = exp.functions || []
50
+ const interfaces = exp.interfaces || []
51
+ const types = exp.types || []
52
+ const consts = exp.constants || []
53
+ const enums = exp.enums || []
54
+
55
+ content.push('## Exported Functions')
56
+ content.push('')
57
+ if (functions.length) {
58
+ content.push('| Name | Signature | Returns |')
59
+ content.push('| ---- | --------- | ------- |')
60
+ for (const fn of functions) {
61
+ content.push(`| \`${mdEscape(fn.name)}\` | \`${mdEscape(fn.signature || '')}\` | \`${mdEscape(fn.returns || '')}\` |`)
62
+ }
63
+ } else {
64
+ content.push('No exported functions.')
65
+ }
66
+ content.push('')
67
+
68
+ content.push('## Exported Interfaces')
69
+ content.push('')
70
+ if (interfaces.length) {
71
+ for (const i of interfaces) {
72
+ content.push(`### \`${i.name}\``)
73
+ content.push('')
74
+ content.push('```ts')
75
+ content.push(i.shape || '')
76
+ content.push('```')
77
+ content.push('')
78
+ }
79
+ } else {
80
+ content.push('No exported interfaces.')
81
+ content.push('')
82
+ }
83
+
84
+ content.push('## Exported Types')
85
+ content.push('')
86
+ if (types.length) {
87
+ content.push('| Name | Definition |')
88
+ content.push('| ---- | ---------- |')
89
+ for (const t of types) {
90
+ content.push(`| \`${mdEscape(t.name)}\` | \`${mdEscape(t.definition || '')}\` |`)
91
+ }
92
+ } else {
93
+ content.push('No exported types.')
94
+ }
95
+ content.push('')
96
+
97
+ content.push('## Exported Constants')
98
+ content.push('')
99
+ if (consts.length) {
100
+ content.push('| Name | Type |')
101
+ content.push('| ---- | ---- |')
102
+ for (const k of consts) {
103
+ content.push(`| \`${mdEscape(k.name)}\` | \`${mdEscape(k.type || '')}\` |`)
104
+ }
105
+ } else {
106
+ content.push('No exported constants.')
107
+ }
108
+ content.push('')
109
+
110
+ content.push('## Exported Enums')
111
+ content.push('')
112
+ if (enums.length) {
113
+ for (const e of enums) {
114
+ content.push(`### \`${e.name}\``)
115
+ content.push('')
116
+ for (const m of e.members || []) content.push(`- \`${m}\``)
117
+ content.push('')
118
+ }
119
+ } else {
120
+ content.push('No exported enums.')
121
+ content.push('')
122
+ }
123
+
124
+ fs.writeFileSync(outFile, content.join('\n'))
125
+ index.push(`| [\`${fileBase}\`](${fileBase}.md) | \`${c.path}\` |`)
126
+ }
127
+
128
+ fs.writeFileSync(path.join(outDir, 'README.md'), index.join('\n'))
129
+ console.log(`Generated markdown docs for ${composables.length} composables at docs/composables-md`)