Skip to content

Commit 3f6594e

Browse files
committed
Move to vue-doc-gen + vitepress instead of styleguide
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
1 parent adb40d1 commit 3f6594e

10 files changed

Lines changed: 152 additions & 210 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ yarn-error.log*
2020
# Unit test / coverage reports
2121
coverage
2222

23+
# vitepress stuff
24+
styleguide/package-lock.json
25+
26+
# genereated file
27+
docs/components
28+
2329
# Docs compiled build
2430
styleguide/build/
2531
styleguide/index.html

docgen.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { defineConfig } = require('vue-docgen-cli')
2+
const fs = require('fs')
3+
4+
const generatePages = () => {
5+
const path = 'src/components'
6+
return fs.readdirSync(path)
7+
.filter(file => fs.statSync(`${path}/${file}`).isDirectory())
8+
.map(file => {
9+
return {
10+
components: `${file}/*.vue`,
11+
outFile: `${file}.md`,
12+
}
13+
})
14+
}
15+
16+
module.exports = defineConfig({
17+
componentsRoot: 'src/components',
18+
docsRepo: 'nextcloud/nextcloud-vue',
19+
docsBranch: 'master',
20+
editLinkLabel: 'Fork me on GitHub',
21+
outDir: 'docs/components',
22+
23+
pages: generatePages(),
24+
})

docs/components.md

Whitespace-only changes.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"dev": "vite build --mode development",
1818
"watch": "vite build --watch --mode development",
1919
"l10n:extract": "node build/extract-l10n.js",
20-
"lint": "eslint --ext .js,.vue src",
20+
"lint": "eslint --ext .mjs,.js,.vue src styleguide",
2121
"lint:fix": "eslint --ext .js,.vue src --fix",
2222
"test": "vitest run",
2323
"test:coverage": "vitest run --coverage",
2424
"stylelint": "stylelint src/**/*.vue src/**/*.scss src/**/*.css",
2525
"stylelint:fix": "stylelint src/**/*.vue src/**/*.scss src/**/*.css --fix",
26-
"styleguide": "vue-styleguidist server",
27-
"styleguide:build": "vue-styleguidist build",
28-
"cypress": "cypress run-ct",
29-
"cypress:gui": "cypress open-ct",
30-
"cypress:update-snapshots": "cypress run-ct --env type=base --config screenshotsFolder=cypress/snapshots/base"
26+
"styleguide": "concurrently \"vue-docgen --watch\" \"cd styleguide && npx vitepress dev\"",
27+
"styleguide:build": "vue-docgen && cd styleguide && npx vitepress build",
28+
"cypress": "cypress run --component",
29+
"cypress:gui": "cypress open --component",
30+
"cypress:update-snapshots": "cypress run --component --env type=base --config screenshotsFolder=cypress/snapshots/base"
3131
},
3232
"main": "dist/index.cjs",
3333
"module": "dist/index.mjs",
@@ -94,7 +94,7 @@
9494
"@vue/compiler-sfc": "^2.7.14",
9595
"@vue/test-utils": "^1.3.3",
9696
"browserslist-to-esbuild": "^1.2.0",
97-
"css-loader": "~6.7.1",
97+
"concurrently": "^7.6.0",
9898
"cypress": "^9.7.0",
9999
"cypress-visual-regression": "^1.5.0",
100100
"eslint-plugin-cypress": "^2.11.1",
@@ -107,6 +107,7 @@
107107
"sass": "^1.56.1",
108108
"vite": "^3.2.4",
109109
"vitest": "^0.25.3",
110+
"vue-docgen-cli": "^4.51.0",
110111
"vue-eslint-parser": "^9.1.0"
111112
},
112113
"browserslist": [

src/components/NcActions/NcActions.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-action
2828
<docs>
2929
### Single action
3030

31-
```
31+
```vue
3232
<template>
3333
<NcActions>
3434
<NcActionButton @click="actionDelete">
@@ -57,7 +57,7 @@ export default {
5757

5858
### Multiple actions
5959

60-
```
60+
```vue
6161
<template>
6262
<NcActions>
6363
<NcActionButton @click="showMessage('Edit')">

styleguide.config.js

Lines changed: 0 additions & 201 deletions
This file was deleted.

styleguide/.vitepress/config.mjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import * as path from "path";
2+
import * as fs from 'fs'
3+
import { fileURLToPath } from "url";
4+
import { defineConfig } from "vitepress";
5+
import { SearchPlugin } from 'vitepress-plugin-search'
6+
import PackageJSON from '../../package.json'
7+
8+
const __filename = fileURLToPath(import.meta.url)
9+
const __dirname = path.dirname(__filename)
10+
11+
const version = PackageJSON.version
12+
const docsPath = path.resolve(__dirname, '../docs')
13+
14+
/**
15+
* Generate list of all components grouped by functionality for sidebar menu
16+
*
17+
* @returns {import('vitepress').DefaultTheme.SidebarItem[]}
18+
*/
19+
function getComponents() {
20+
const sections = {}
21+
22+
fs.readdirSync(path.resolve(docsPath, 'components'))
23+
.forEach(file => {
24+
const name = file.replace('.md', '')
25+
const words = name.split(/(?=[A-Z])/)
26+
const section = words
27+
.slice(0, (words[1] === 'App' && words.length >= 3 ? 3 : 2))
28+
.join('')
29+
.replace(/s$/, '') // fix NcActions
30+
if (!(section in sections)) sections[section] = []
31+
sections[section].push(name)
32+
})
33+
34+
return Object.keys(sections)
35+
.sort()
36+
.map(section => {
37+
// Get base component as first entry, sort is not enogh because of `NcActions` vs `NcActionX`
38+
const first = sections[section].sort((p,q) => p.length - q.length)[0]
39+
const other = sections[section].filter(p => p !== first).sort()
40+
return {
41+
text: section,
42+
items: [
43+
first,
44+
...other
45+
].map(file => ({text: file, link: `/components/${file}`}))
46+
}
47+
})
48+
}
49+
50+
export default defineConfig({
51+
title: '@nextcloud/vue',
52+
description: 'Vue.js components for Nextcloud app development',
53+
54+
ignoreDeadLinks: true,
55+
56+
themeConfig: {
57+
logo: 'https://nextcloud.com/wp-content/uploads/2022/10/nextcloud-logo-blue-transparent.svg',
58+
nav: [
59+
{ text: `${version}`, items: [
60+
{ text: 'Changelog', link: `https://github.com/nextcloud/nextcloud-vue/blob/v${version}/CHANGELOG.md` },
61+
]},
62+
],
63+
sidebar: [
64+
{
65+
text: 'Components',
66+
collapsible: true,
67+
collapsed: true,
68+
items: getComponents(),
69+
},
70+
{
71+
items: [{
72+
text: 'Directives',
73+
link: '/directives'
74+
}]
75+
},
76+
],
77+
socialLinks: [
78+
{
79+
icon: 'github',
80+
link: 'https://github.com/nextcloud/nextcloud-vue'
81+
}
82+
],
83+
},
84+
85+
srcDir: '../docs',
86+
87+
markdown: {
88+
highlight: (str, language, attr) => hljs.highlight(str, { language: language === 'vue' ? 'xml' : language}).value
89+
},
90+
91+
vite: {
92+
root: docsPath,
93+
plugins: [ SearchPlugin() ],
94+
95+
}
96+
})

0 commit comments

Comments
 (0)