@digo-labs/common 0.1.9 → 0.1.10
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/dist/app-config-helpers.d.ts +7 -0
- package/dist/auth.d.ts +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +168 -136
- package/dist/index.js.map +1 -1
- package/dist/types/websocket-types.d.ts +1 -1
- package/package.json +4 -2
- package/vite-plugin-raw-mdx.ts +63 -0
- package/vite.apps.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digo-labs/common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
"default": "./dist/index.css"
|
|
19
19
|
},
|
|
20
20
|
"./vite.apps": "./vite.apps.ts",
|
|
21
|
+
"./vite-plugin-raw-mdx": "./vite-plugin-raw-mdx.ts",
|
|
21
22
|
"./package.json": "./package.json"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
25
|
-
"vite.apps.ts"
|
|
26
|
+
"vite.apps.ts",
|
|
27
|
+
"vite-plugin-raw-mdx.ts"
|
|
26
28
|
],
|
|
27
29
|
"publishConfig": {
|
|
28
30
|
"access": "public",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { Plugin } from 'vite';
|
|
4
|
+
|
|
5
|
+
type RawMdxConfig = { docsDir: string; };
|
|
6
|
+
|
|
7
|
+
function extractSection(content: string): string {
|
|
8
|
+
const match = content.match(/^section:\s*(.+)$/m);
|
|
9
|
+
return match?.[1].trim().replace(/['"]/g, '') ?? 'Uncategorized';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toSlug(name: string): string {
|
|
13
|
+
return name.toLowerCase().replace(/\s+/g, '-');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function rawMdxPlugin(config: RawMdxConfig): Plugin {
|
|
17
|
+
const { docsDir } = config;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name: 'vite-plugin-raw-mdx',
|
|
21
|
+
|
|
22
|
+
configureServer(server) {
|
|
23
|
+
server.middlewares.use((req, res, next) => {
|
|
24
|
+
const match = req.url?.match(/^\/docs\/([^/]+)\/([^/]+)\.mdx(\?.*)?$/);
|
|
25
|
+
if (!match) return next();
|
|
26
|
+
|
|
27
|
+
const [, sectionSlug, slug] = match;
|
|
28
|
+
const filePath = join(docsDir, `${slug}.mdx`);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const content = readFileSync(filePath, 'utf8');
|
|
32
|
+
const expectedSlug = toSlug(extractSection(content));
|
|
33
|
+
|
|
34
|
+
if (expectedSlug !== sectionSlug) {
|
|
35
|
+
res.statusCode = 404;
|
|
36
|
+
res.end('Not found');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
41
|
+
res.end(content);
|
|
42
|
+
} catch {
|
|
43
|
+
next();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
generateBundle() {
|
|
49
|
+
const files = readdirSync(docsDir).filter(f => f.endsWith('.mdx'));
|
|
50
|
+
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
const content = readFileSync(join(docsDir, file), 'utf8');
|
|
53
|
+
const sectionSlug = toSlug(extractSection(content));
|
|
54
|
+
|
|
55
|
+
this.emitFile({
|
|
56
|
+
type: 'asset',
|
|
57
|
+
fileName: `docs/${sectionSlug}/${file}`,
|
|
58
|
+
source: content,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
package/vite.apps.ts
CHANGED
|
@@ -9,15 +9,18 @@ import remarkGfm from 'remark-gfm';
|
|
|
9
9
|
import remarkFrontmatter from 'remark-frontmatter';
|
|
10
10
|
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
|
|
11
11
|
import rehypeSlug from 'rehype-slug';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { rawMdxPlugin } from './vite-plugin-raw-mdx';
|
|
12
14
|
|
|
13
15
|
export type DigoViteConfigProperties = {
|
|
14
16
|
includeAssetsFrom: string[];
|
|
15
17
|
port: number;
|
|
16
18
|
allowedHosts?: string[];
|
|
19
|
+
docsDir?: string;
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
export function digoViteConfig(properties: DigoViteConfigProperties) {
|
|
20
|
-
const { includeAssetsFrom, port, allowedHosts } = properties;
|
|
23
|
+
const { includeAssetsFrom, port, allowedHosts, docsDir } = properties;
|
|
21
24
|
return defineConfig({
|
|
22
25
|
plugins: [
|
|
23
26
|
react({
|
|
@@ -37,6 +40,7 @@ export function digoViteConfig(properties: DigoViteConfigProperties) {
|
|
|
37
40
|
rehypePlugins: [rehypeSlug],
|
|
38
41
|
|
|
39
42
|
}),
|
|
43
|
+
...docsDir ? [rawMdxPlugin({ docsDir: resolve(process.cwd(), docsDir) })] : [],
|
|
40
44
|
],
|
|
41
45
|
server: {
|
|
42
46
|
port: port,
|