@do11y/docs 0.0.0

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/bin/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ import '../dist/cli.js';
package/dist/cli.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createServer, build, preview } from 'vite';
2
+ import { getViteConfig } from './vite-config.js';
3
+ const [_, __, command = 'dev'] = process.argv;
4
+ if (command !== 'dev' && command !== 'build' && command !== 'preview') {
5
+ throw new Error();
6
+ }
7
+ const viteConfig = await getViteConfig(command);
8
+ if (command === 'dev') {
9
+ const server = await createServer(viteConfig);
10
+ await server.listen();
11
+ server.printUrls();
12
+ server.bindCLIShortcuts({ print: true });
13
+ }
14
+ else {
15
+ await build(viteConfig);
16
+ if (command === 'preview') {
17
+ const previewServer = await preview(viteConfig);
18
+ previewServer.printUrls();
19
+ previewServer.bindCLIShortcuts({ print: true });
20
+ }
21
+ }
package/dist/files.js ADDED
@@ -0,0 +1,8 @@
1
+ import { join, dirname } from 'node:path';
2
+ import { createRequire } from 'node:module';
3
+ import { searchForWorkspaceRoot } from 'vite';
4
+ const require = createRequire(import.meta.url);
5
+ export const ui = join(dirname(require.resolve('@do11y/ui/package.json')));
6
+ export const root = join(searchForWorkspaceRoot(process.cwd()), 'example');
7
+ export const docs = join(root, 'docs');
8
+ export const plugins = join(docs, 'site', 'plugins.ts');
@@ -0,0 +1,32 @@
1
+ import { join } from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { docs } from '../files.js';
5
+ export const html = (folder, key) => {
6
+ const template = readFileSync(join(import.meta.dirname, 'template.html'), 'utf-8');
7
+ const bundle = join(folder, 'dist', key === 'index' ? 'bundle-docs.js' : 'bundle-sandbox.js');
8
+ const sandboxBundle = join(folder, 'dist', 'bundle-sandbox.js');
9
+ return {
10
+ async writeBundle() {
11
+ const html = template
12
+ .replace('/assets/index.js', `/assets/${key}.js`)
13
+ .replace('/assets/index.css', `/assets/${key}.css`);
14
+ await writeFile(join(docs, 'dist', `${key}.html`), html);
15
+ },
16
+ configureServer(server) {
17
+ server.middlewares.use(async (req, res, next) => {
18
+ if (req.url !== '/' && !req.url?.startsWith('/sandbox')) {
19
+ return next();
20
+ }
21
+ const currentBundle = req.url === '/' ? bundle : sandboxBundle;
22
+ const html = template
23
+ .replace('/assets/index.js', `/@fs/${currentBundle}`)
24
+ .replace('<link rel="preload stylesheet" href="/assets/index.css" as="style" />', '');
25
+ const transformedHtml = await server.transformIndexHtml(req.url, html);
26
+ res.statusCode = 200;
27
+ res.setHeader('content-type', 'text/html; charset=UTF-8');
28
+ res.end(transformedHtml);
29
+ });
30
+ },
31
+ };
32
+ };
@@ -0,0 +1,16 @@
1
+ <!doctype html>
2
+
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+
8
+ <title>Documentation</title>
9
+
10
+ <link rel="icon" href="/favicon.ico" />
11
+ <link rel="preload stylesheet" href="/assets/index.css" as="style" />
12
+ </head>
13
+
14
+ <body id="app"></body>
15
+ <script type="module" src="/assets/index.js"></script>
16
+ </html>
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { plugins } from './files.js';
2
+ /**
3
+ * Access plugin options (`docs/site/plugins.ts`).
4
+ */
5
+ export const pluginOptions = (await import(plugins)).default;
@@ -0,0 +1,65 @@
1
+ import { join } from 'node:path';
2
+ import { componentPlugin } from '@mdit-vue/plugin-component';
3
+ import { sfcPlugin } from '@mdit-vue/plugin-sfc';
4
+ import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter';
5
+ import markPlugin from 'markdown-it-mark';
6
+ import attrsPlugin from 'markdown-it-attrs';
7
+ import anchorPlugin from 'markdown-it-anchor';
8
+ import metaPlugin from 'markdown-it-vue-meta';
9
+ import markdown from 'markdown-it';
10
+ import { root } from '../../files.js';
11
+ /**
12
+ * Processes blocks with the lang set to `md` into HTML,
13
+ * and turns `.md` files into single file vue components
14
+ * - using `markdown-it`.
15
+ */
16
+ export default (options) => {
17
+ const md = markdown({
18
+ html: true,
19
+ highlight(code, lang, attrs) {
20
+ return options?.highlight?.(md, code, lang, attrs) ?? '';
21
+ },
22
+ });
23
+ md.use(frontmatterPlugin);
24
+ md.use(sfcPlugin);
25
+ md.use(componentPlugin);
26
+ if (options?.metaRenderer) {
27
+ const tsconfig = join(root, 'tsconfig.json');
28
+ md.use(metaPlugin, {
29
+ renderer: options?.metaRenderer,
30
+ tsconfig,
31
+ });
32
+ }
33
+ md.use(anchorPlugin, { permalink: anchorPlugin.permalink.headerLink() });
34
+ md.use(markPlugin);
35
+ md.use(attrsPlugin);
36
+ if (options?.setup) {
37
+ md.use(options.setup);
38
+ }
39
+ return {
40
+ name: 'do11y:markdown',
41
+ enforce: 'pre',
42
+ transform(code, id) {
43
+ if (id.endsWith('.md')) {
44
+ const env = {
45
+ path: id.replace(/[?#].*$/, ''),
46
+ };
47
+ const html = md.render(code, env);
48
+ /**
49
+ * If it's a markdown block, return the
50
+ * html directly - otherwise create
51
+ * a single file component.
52
+ */
53
+ if (id.endsWith('lang.md')) {
54
+ return html;
55
+ }
56
+ else {
57
+ const template = env.sfcBlocks?.template?.content ?? '';
58
+ const script = env.sfcBlocks?.scriptSetup?.contentStripped ?? '';
59
+ const styles = env.sfcBlocks?.styles.map((s) => s.content).join('\n\n') ?? '';
60
+ return `${template}\n\n<script setup>${script}</script>\n\n${styles}`;
61
+ }
62
+ }
63
+ },
64
+ };
65
+ };
@@ -0,0 +1,15 @@
1
+ import markdownPlugin from './markdown/markdown.js';
2
+ import customBlockPlugin from 'v-custom-block';
3
+ import sitePlugin from './site/site.js';
4
+ import routesPlugin from './routes/routes.js';
5
+ import uiPlugin from './ui/ui.js';
6
+ import sandboxPlugin from './sandbox/sandbox.js';
7
+ import { pluginOptions } from '../plugin-options.js';
8
+ export const plugins = () => [
9
+ uiPlugin(),
10
+ sandboxPlugin(),
11
+ markdownPlugin(pluginOptions),
12
+ customBlockPlugin('docs'),
13
+ sitePlugin(),
14
+ routesPlugin(),
15
+ ];
@@ -0,0 +1,46 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import fg from 'fast-glob';
3
+ import fm from 'front-matter';
4
+ import { root } from '../../files.js';
5
+ /**
6
+ * Adds the ability to import routes (`*.md` files)
7
+ * through `do11y:routes`.
8
+ */
9
+ export default () => {
10
+ const moduleId = 'do11y:routes';
11
+ const resolvedModuleId = '\0' + moduleId;
12
+ const markdownFiles = fg.globSync(['(docs|src|packages)/**/*.md'], {
13
+ absolute: true,
14
+ cwd: root,
15
+ });
16
+ return {
17
+ name: 'do11y:routes',
18
+ resolveId(id) {
19
+ if (id === moduleId) {
20
+ return resolvedModuleId;
21
+ }
22
+ },
23
+ load(id) {
24
+ if (id === resolvedModuleId) {
25
+ const getFrontMatter = (path) => fm(readFileSync(path, 'utf-8')).attributes;
26
+ const pages = markdownFiles
27
+ .map((path) => ({
28
+ path,
29
+ frontmatter: (getFrontMatter(path) ?? {}),
30
+ }))
31
+ .filter((file) => {
32
+ return (typeof file.frontmatter.title === 'string' &&
33
+ typeof file.frontmatter.slug === 'string');
34
+ });
35
+ const stringifiedRoutes = pages.map((route) => {
36
+ return `{
37
+ path: "${route.frontmatter.slug}",
38
+ meta: ${JSON.stringify(route.frontmatter)},
39
+ component: async () => (await import("${route.path}")).default
40
+ }`;
41
+ });
42
+ return `export default [${stringifiedRoutes.map((route) => route.trim()).join(',\n')}]`;
43
+ }
44
+ },
45
+ };
46
+ };
@@ -0,0 +1,38 @@
1
+ import { kebabCase } from 'change-case';
2
+ import { parse } from 'node:path';
3
+ import fg from 'fast-glob';
4
+ import { root, ui } from '../../files.js';
5
+ import { html } from '../../html/html.js';
6
+ /**
7
+ * Creates a seprate sandbox app, and
8
+ * adds the ability to declare sandbox components
9
+ * which you can access through `do11y:sandbox`.
10
+ */
11
+ export default () => {
12
+ const moduleId = 'do11y:sandbox';
13
+ const resolvedModuleId = '\0' + moduleId;
14
+ const sandboxFiles = fg.globSync(['(docs|src|packages)/**/*.sandbox.vue'], {
15
+ absolute: true,
16
+ cwd: root,
17
+ });
18
+ return {
19
+ name: 'do11y:sandbox',
20
+ ...html(ui, 'sandbox'),
21
+ resolveId(id) {
22
+ if (id === moduleId) {
23
+ return resolvedModuleId;
24
+ }
25
+ },
26
+ async load(id) {
27
+ if (id === resolvedModuleId) {
28
+ const stringifiedStories = sandboxFiles.map((path) => {
29
+ return `{
30
+ url: "${kebabCase(parse(path).name.replace('.sandbox', ''))}",
31
+ component: async () => (await import("${path}")).default
32
+ }`;
33
+ });
34
+ return `export default [${stringifiedStories.map((sandbox) => sandbox.trim()).join(',\n')}]`;
35
+ }
36
+ },
37
+ };
38
+ };
@@ -0,0 +1,14 @@
1
+ import { join } from 'node:path';
2
+ import { docs } from '../../files.js';
3
+ /**
4
+ * Add ability to access the site options (`docs/site/index.ts`)
5
+ * through `do11y:site`.
6
+ */
7
+ export default () => ({
8
+ name: 'do11y:site',
9
+ async resolveId(id, importer) {
10
+ if (id === 'do11y:site') {
11
+ return this.resolve(join(docs, 'site', 'index.js'), importer);
12
+ }
13
+ },
14
+ });
@@ -0,0 +1,9 @@
1
+ import { ui } from '../../files.js';
2
+ import { html } from '../../html/html.js';
3
+ /**
4
+ * The main application.
5
+ */
6
+ export default () => ({
7
+ name: 'do11y:ui',
8
+ ...html(ui, 'index'),
9
+ });
@@ -0,0 +1,43 @@
1
+ import { join } from 'node:path';
2
+ import { loadConfigFromFile, mergeConfig } from 'vite';
3
+ import { root, docs, ui } from './files.js';
4
+ import { plugins } from './plugins/plugins.js';
5
+ export const getUserViteConfig = async (command) => {
6
+ const userConfigFile = await loadConfigFromFile({
7
+ command: command === 'dev' ? 'serve' : 'build',
8
+ mode: command === 'dev' ? 'dev' : 'build',
9
+ });
10
+ return userConfigFile?.config ?? {};
11
+ };
12
+ export const getViteConfig = async (command) => {
13
+ const userConfig = await getUserViteConfig(command);
14
+ const config = mergeConfig(userConfig, {
15
+ root: docs,
16
+ server: {
17
+ port: 1998,
18
+ fs: {
19
+ allow: [root, ui, import.meta.dirname],
20
+ },
21
+ },
22
+ preview: {
23
+ port: 1996,
24
+ },
25
+ build: {
26
+ manifest: true,
27
+ outDir: join(docs, 'dist'),
28
+ rollupOptions: {
29
+ input: {
30
+ index: join(ui, 'dist', 'bundle-docs.js'),
31
+ sandbox: join(ui, 'dist', 'bundle-sandbox.js'),
32
+ },
33
+ output: {
34
+ entryFileNames: () => 'assets/[name].js',
35
+ assetFileNames: () => 'assets/[name][extname]',
36
+ },
37
+ },
38
+ },
39
+ });
40
+ return mergeConfig(config, {
41
+ plugins: plugins(),
42
+ });
43
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@do11y/docs",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/sq11y/do11y"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist",
12
+ "routes.d.ts"
13
+ ],
14
+ "bin": {
15
+ "do11y": "./bin/bin.js"
16
+ },
17
+ "exports": {
18
+ ".": "./dist/index.js",
19
+ "./types": "./routes.d.ts"
20
+ },
21
+ "peerDependencies": {
22
+ "@vitejs/plugin-vue": "^6.0.2",
23
+ "vue": "3.5.25"
24
+ },
25
+ "dependencies": {
26
+ "@mdit-vue/plugin-component": "^3.0.2",
27
+ "@mdit-vue/plugin-frontmatter": "^3.0.2",
28
+ "@mdit-vue/plugin-sfc": "^3.0.2",
29
+ "change-case": "^5.4.4",
30
+ "fast-glob": "^3.3.3",
31
+ "front-matter": "^4.0.2",
32
+ "markdown-it": "^14.1.0",
33
+ "markdown-it-anchor": "^9.2.0",
34
+ "markdown-it-attrs": "^4.3.1",
35
+ "markdown-it-mark": "^4.0.0",
36
+ "markdown-it-vue-meta": "^0.0.2",
37
+ "v-custom-block": "^1.0.67",
38
+ "@do11y/ui": "0.0.1"
39
+ },
40
+ "devDependencies": {
41
+ "@tsconfig/node24": "^24.0.3",
42
+ "@types/markdown-it": "^14.1.2",
43
+ "@types/markdown-it-attrs": "^4.1.3",
44
+ "@types/node": "^24.10.1",
45
+ "typescript": "5.9.3",
46
+ "vite": "^7.2.6",
47
+ "vue-router": "^4.6.3"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc && copyfiles -f src/html/template.html dist/html"
51
+ }
52
+ }
package/routes.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare module 'do11y:routes' {
2
+ import type { RouteRecordRaw } from 'vue-router';
3
+ const routes: (Omit<RouteRecordRaw, 'meta'> & { meta: { title: string; slug: string } })[];
4
+ export default routes;
5
+ }