2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-07 07:12:23 +03:00

docs: create plugin to generate documentation object server side for client side consumption

This commit is contained in:
Jeff
2019-11-17 10:51:59 -08:00
parent 22bf8f9475
commit 66a2cb8ff9
5 changed files with 332 additions and 17 deletions
+13
View File
@@ -0,0 +1,13 @@
<template>
$END$
</template>
<script>
export default {
name: "ApiDocs"
}
</script>
<style scoped>
</style>
+10 -11
View File
@@ -63,19 +63,18 @@ module.exports = {
title: 'Vue Select',
description: meta.description,
head,
plugins: {
'@vuepress/google-analytics': {
ga: isDeployPreview ? '' : 'UA-12818324-8',
},
'@vuepress/pwa': {
plugins: [
require('./generateApiDocs'),
['@vuepress/google-analytics',{ga: isDeployPreview ? '' : 'UA-12818324-8',}],
['@vuepress/pwa', {
serviceWorker: false,
updatePopup: true,
},
'@vuepress/plugin-register-components': {},
'@vuepress/plugin-active-header-links': {},
'@vuepress/plugin-search': {},
'@vuepress/plugin-nprogress': {},
},
}],
'@vuepress/plugin-register-components',
'@vuepress/plugin-active-header-links',
'@vuepress/plugin-search',
'@vuepress/plugin-nprogress',
],
themeConfig: {
repo: 'sagalbot/vue-select',
editLinks: true,
+40
View File
@@ -0,0 +1,40 @@
const docs = require('vue-docgen-api');
const path = require('path');
const fs = require('fs');
/**
* Get all of the component mixin paths.
* @param directory
* @return {string[]}
*/
function getMixins (directory) {
return fs.readdirSync(directory)
.filter(file => file !== 'index.js')
.map(file => path.resolve(directory, file));
}
/**
* Dynamically generates all API documentation with vue-docgen-api.
* Resulting object can be imported and used client-side:
*
* import documentation from '@dynamic/api'
*
* @see https://vuepress.vuejs.org/plugin/option-api.html#clientdynamicmodules
* @param options
* @param sourceDir
* @return {{clientDynamicModules(): Promise<{name: string, content: string}>}}
*/
module.exports = (options, {sourceDir}) => ({
/**
* Generate documentation for Select.vue
* @return {Promise<{name: string, content: string}>}
*/
async clientDynamicModules () {
const file = path.resolve(sourceDir, '../src/components/Select.vue');
return {
name: 'api.js',
content: `export default ${JSON.stringify(await docs.parse(file))}`,
};
},
});