packages/*/LICENSE
explorations
docs-api
+packages/docs/api
[build]
-command = "yarn run docs:build && yarn run docs:api"
+command = "yarn run docs:api && yarn run docs:build"
ignore = "./scripts/docs-check.sh"
publish = "packages/docs/.vitepress/dist"
"test:jest": "jest --coverage",
"test:types": "tsc --build ./tsconfig.json",
"test:dts": "lerna run test:dts",
- "docs:api": "typedoc"
+ "docs:api": "lerna run docs:api --scope @pinia/docs"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.5",
"rollup-plugin-typescript2": "^0.30.0",
"semver": "^7.3.5",
"typedoc": "^0.21.6",
+ "typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.3.5",
"yorkie": "^2.0.0"
},
nav: [
{ text: 'Guide', link: '/introduction.html' },
- { text: 'API', link: 'https://pinia.esm.dev/api/' },
+ { text: 'API', link: '/api/' },
// { text: 'Config', link: '/config/' },
// { text: 'Plugins', link: '/plugins/' },
{
"private": true,
"scripts": {
"docs": "vitepress dev .",
+ "docs:api": "node run-typedoc.js",
"docs:build": "vitepress build ."
},
"dependencies": {
--- /dev/null
+const { createTypeDocApp } = require('./typedoc-markdown')
+const path = require('path')
+
+createTypeDocApp({
+ name: 'Pinia',
+ entryPoints: [
+ path.resolve(__dirname, '../pinia/src/index.ts'),
+ path.resolve(__dirname, '../testing/src/index.ts'),
+ path.resolve(__dirname, '../nuxt/src/index.ts'),
+ ],
+}).build()
--- /dev/null
+const _fs = require('fs')
+const path = require('path')
+const TypeDoc = require('typedoc')
+const { PageEvent } = require('typedoc/dist/lib/output/events')
+const {
+ prependYAML,
+} = require('typedoc-plugin-markdown/dist/utils/front-matter')
+
+const fs = _fs.promises
+
+const DEFAULT_OPTIONS = {
+ disableOutputCheck: true,
+ readme: 'none',
+ out: path.resolve(__dirname, './api'),
+ entryDocument: 'index.md',
+ hideBreadcrumbs: false,
+ hideInPageTOC: true,
+}
+
+/**
+ *
+ * @param {Partial<import('typedoc').TypeDocOptions>} config
+ */
+exports.createTypeDocApp = function createTypeDocApp(config = {}) {
+ const options = {
+ ...DEFAULT_OPTIONS,
+ ...config,
+ }
+
+ const app = new TypeDoc.Application()
+
+ // If you want TypeDoc to load tsconfig.json / typedoc.json files
+ app.options.addReader(new TypeDoc.TSConfigReader())
+ // app.options.addReader(new TypeDoc.TypeDocReader())
+
+ /** @type {'build' | 'serve'} */
+ let targetMode = 'build'
+
+ app.renderer.on(
+ PageEvent.END,
+ /**
+ *
+ * @param {import('typedoc/dist/lib/output/events').PageEvent} page
+ */
+ (page) => {
+ if (page.url !== 'index.md' && page.contents) {
+ page.contents = prependYAML(page.contents, {
+ sidebar: 'auto',
+ sidebarDepth: 3,
+ })
+ }
+ }
+ )
+
+ async function serve() {
+ app.bootstrap(options)
+ app.convertAndWatch(handleProject)
+ }
+
+ async function build() {
+ if ((await fs.stat(options.out)).isDirectory()) {
+ await fs.rm(options.out, { recursive: true })
+ }
+ app.bootstrap(options)
+ const project = app.convert()
+ return handleProject(project)
+ }
+
+ /**
+ *
+ * @param {import('typedoc').ProjectReflection} project
+ */
+ async function handleProject(project) {
+ if (project) {
+ // Rendered docs
+ try {
+ await app.generateDocs(project, options.out)
+ app.logger.info(`generated at ${options.out}.`)
+ } catch (error) {
+ app.logger.error(error)
+ }
+ } else {
+ app.logger.error('No project')
+ }
+ }
+
+ return {
+ build,
+ serve,
+ /**
+ *
+ * @param {'build' | 'serve'} command
+ */
+ setTargetMode(command) {
+ targetMode = command
+ },
+ }
+}
--- /dev/null
+import { Plugin } from 'vite'
+import _fs from 'fs'
+import { TypeDocOptions } from 'typedoc'
+import { createTypeDocApp } from './typedoc-markdown'
+
+export default function TypeDocPlugin(
+ config: Partial<TypeDocOptions> = {}
+): Plugin {
+ const { serve, setTargetMode } = createTypeDocApp(config)
+ setTargetMode('serve')
+
+ return {
+ name: 'typedoc',
+ apply: 'serve',
+ buildStart() {
+ return serve()
+ },
+ }
+}
import { defineConfig, Plugin } from 'vite'
import _fs from 'fs'
import path from 'path'
+// import TypeDocPlugin from './vite-typedoc-plugin'
const fs = _fs.promises
export default defineConfig({
- plugins: process.env.NETLIFY ? [] : [copyPiniaPlugin()],
+ clearScreen: false,
+ plugins: [
+ ...(process.env.NETLIFY ? [] : [copyPiniaPlugin()]),
+ // FIXME: fix vitepress bug of running plugins twice
+ // TypeDocPlugin({
+ // name: 'Pinia',
+ // entryPoints: [
+ // path.resolve(__dirname, '../pinia/src/index.ts'),
+ // path.resolve(__dirname, '../testing/src/index.ts'),
+ // path.resolve(__dirname, '../nuxt/src/index.ts'),
+ // ],
+ // }),
+ ],
define: {
__DEV__: 'true',
__BROWSER__: 'true',
id: Id
/**
- * Function to create a fresh state.
+ * Function to create a fresh state. **Must be an arrow function** to ensure
+ * correct typings!
*/
state?: () => S
+++ /dev/null
-// @ts-check
-
-/** @type {Partial<import('typedoc').TypeDocOptions>} */
-const config = {
- name: 'Pinia',
- readme: 'none',
- excludeInternal: true,
- out: 'packages/docs/.vitepress/dist/api',
- entryPoints: [
- 'packages/pinia/src/index.ts',
- 'packages/testing/src/index.ts',
- 'packages/nuxt/src/index.ts',
- ],
-}
-
-module.exports = config
resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.12.10.tgz#614c4222fe642657f37693ea62cad4dafeddf843"
integrity sha512-fIS001cAYHkyQPidWXmHuhs8usjP5XVJjWB8oZGqkTowZaz3v7g3KDZeeqE82FBrmkAnIBOY3jgy7lnPnqATbA==
+typedoc-plugin-markdown@^3.10.4:
+ version "3.10.4"
+ resolved "https://registry.yarnpkg.com/typedoc-plugin-markdown/-/typedoc-plugin-markdown-3.10.4.tgz#4e0e9c584a1e421beafa4c3666896615f069da6b"
+ integrity sha512-if9w7S9fXLg73AYi/EoRSEhTOZlg3I8mIP8YEmvzSE33VrNXC9/hA0nVcLEwFVJeQY7ay6z67I6kW0KIv7LjeA==
+ dependencies:
+ handlebars "^4.7.7"
+
typedoc@^0.21.6:
version "0.21.6"
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.21.6.tgz#854bfa2d6b3ac818ac70aa4734a4d1ba93695595"