@coreui/astro-docs-api-generator 0.1.0-beta.0 → 0.1.0-beta.1
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 +2 -1
- package/src/config.mjs +52 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/astro-docs-api-generator",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "API documentation JSON generator for @coreui/astro-docs (React + Vue), emitting a consistent ApiData shape.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"exports": {
|
|
31
31
|
".": "./src/cli.mjs",
|
|
32
|
+
"./config": "./src/config.mjs",
|
|
32
33
|
"./react": "./src/react.mjs",
|
|
33
34
|
"./vue": "./src/vue.mjs"
|
|
34
35
|
},
|
package/src/config.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Helper for a docs project's `api.config.mjs`. Each framework's config used to repeat
|
|
2
|
+
// the same source scan (`isComponent` + recursive `scan`) and only differed in the file
|
|
3
|
+
// pattern and the component roots — this centralizes that. The consumer passes its own
|
|
4
|
+
// `configUrl` (`import.meta.url`) so roots and the emitted component paths resolve
|
|
5
|
+
// relative to the config file, exactly as the CLI's `run()` expects (it resolves each
|
|
6
|
+
// `rel` against the config's directory).
|
|
7
|
+
import { readdirSync } from 'node:fs'
|
|
8
|
+
import { join, dirname, basename, relative } from 'node:path'
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
10
|
+
|
|
11
|
+
// Per-framework: file extension + which filenames count as a documentable component.
|
|
12
|
+
// React mirrors the source convention (`C*.tsx`, minus declarations/specs/tests); Vue
|
|
13
|
+
// mirrors the VuePress docgen glob (`[A-Z]*.ts`, minus declarations/specs/ComponentProps).
|
|
14
|
+
const FRAMEWORKS = {
|
|
15
|
+
react: {
|
|
16
|
+
ext: '.tsx',
|
|
17
|
+
isComponent: (name) => /^C[A-Z].*\.tsx$/.test(name) && !/\.(d|spec|test)\.tsx$/.test(name),
|
|
18
|
+
},
|
|
19
|
+
vue: {
|
|
20
|
+
ext: '.ts',
|
|
21
|
+
isComponent: (name) =>
|
|
22
|
+
/^[A-Z].*\.ts$/.test(name) && !/\.(d|spec)\.ts$/.test(name) && name !== 'ComponentProps.ts',
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createApiConfig({ framework, configUrl, roots, importPackage, outDir = 'src/api', importSrcBase }) {
|
|
27
|
+
const fw = FRAMEWORKS[framework]
|
|
28
|
+
if (!fw) throw new Error(`createApiConfig: unknown framework '${framework}' (expected 'react' or 'vue')`)
|
|
29
|
+
|
|
30
|
+
const here = dirname(fileURLToPath(configUrl))
|
|
31
|
+
|
|
32
|
+
const scan = (dir, out) => {
|
|
33
|
+
let entries
|
|
34
|
+
try {
|
|
35
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
36
|
+
} catch {
|
|
37
|
+
return out
|
|
38
|
+
}
|
|
39
|
+
for (const e of entries) {
|
|
40
|
+
if (e.name === '__tests__' || e.name.startsWith('.')) continue
|
|
41
|
+
const p = join(dir, e.name)
|
|
42
|
+
if (e.isDirectory()) scan(p, out)
|
|
43
|
+
else if (fw.isComponent(e.name)) out[basename(e.name, fw.ext)] = `./${relative(here, p)}`
|
|
44
|
+
}
|
|
45
|
+
return out
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const components = {}
|
|
49
|
+
for (const root of roots) scan(join(here, root), components)
|
|
50
|
+
|
|
51
|
+
return { framework, outDir, importPackage, importSrcBase, components }
|
|
52
|
+
}
|