@alauda/doom 0.3.3 → 0.4.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.
Files changed (41) hide show
  1. package/lib/cli/index.js +1 -2
  2. package/lib/cli/load-config.js +18 -19
  3. package/lib/{cli/config.d.ts → config.d.ts} +1 -1
  4. package/lib/runtime/components/Badge.d.ts +1 -0
  5. package/lib/runtime/components/Badge.js +1 -0
  6. package/lib/runtime/components/Card.d.ts +1 -0
  7. package/lib/runtime/components/Card.js +1 -0
  8. package/lib/runtime/components/LinkCard.d.ts +1 -0
  9. package/lib/runtime/components/LinkCard.js +1 -0
  10. package/lib/runtime/components/PackageManagerTabs.d.ts +1 -0
  11. package/lib/runtime/components/PackageManagerTabs.js +1 -0
  12. package/lib/runtime/components/Steps.d.ts +1 -0
  13. package/lib/runtime/components/Steps.js +1 -0
  14. package/lib/runtime/components/Tab.d.ts +1 -0
  15. package/lib/runtime/components/Tab.js +1 -0
  16. package/lib/runtime/components/Tabs.d.ts +1 -0
  17. package/lib/runtime/components/Tabs.js +1 -0
  18. package/lib/runtime/components/Toc.d.ts +1 -0
  19. package/lib/runtime/components/Toc.js +1 -0
  20. package/lib/runtime/components/index.d.ts +9 -1
  21. package/lib/runtime/components/index.js +9 -1
  22. package/package.json +2 -1
  23. package/lib/cli/shiki/index.d.ts +0 -1
  24. package/lib/cli/shiki/index.js +0 -1
  25. package/lib/cli/shiki/transformers/callouts.d.ts +0 -7
  26. package/lib/cli/shiki/transformers/callouts.js +0 -16
  27. package/lib/cli/shiki/transformers/index.d.ts +0 -1
  28. package/lib/cli/shiki/transformers/index.js +0 -1
  29. package/lib/cli/shiki/types.d.ts +0 -14
  30. package/lib/cli/shiki/types.js +0 -1
  31. package/lib/cli/shiki/utils.d.ts +0 -4
  32. package/lib/cli/shiki/utils.js +0 -47
  33. package/lib/plugins/swagger/index.d.ts +0 -2
  34. package/lib/plugins/swagger/index.js +0 -38
  35. package/lib/plugins/swagger/types.d.ts +0 -28
  36. package/lib/plugins/swagger/types.js +0 -1
  37. package/lib/runtime/components/SwaggerModel.d.ts +0 -5
  38. package/lib/runtime/components/SwaggerModel.js +0 -5
  39. package/lib/runtime/components/SwaggerPath.d.ts +0 -5
  40. package/lib/runtime/components/SwaggerPath.js +0 -32
  41. /package/lib/{cli/config.js → config.js} +0 -0
package/lib/cli/index.js CHANGED
@@ -2,14 +2,13 @@
2
2
  /**
3
3
  * Adopted from @see https://github.com/web-infra-dev/rspress/blob/main/packages/cli/src/index.ts
4
4
  */
5
+ import module from 'node:module';
5
6
  import path from 'node:path';
6
7
  import { logger } from '@rsbuild/core';
7
8
  import { build, dev, serve } from '@rspress/core';
8
9
  import { watch } from 'chokidar';
9
- // import type { EventName } from 'chokidar/handler.js'
10
10
  import { program } from 'commander';
11
11
  import { green } from 'yoctocolors';
12
- import module from 'node:module';
13
12
  import { CWD, DEFAULT_CONFIGS, I18N_FILE } from './constants.js';
14
13
  import { loadConfig } from './load-config.js';
15
14
  const META_FILE = '_meta.json';
@@ -12,9 +12,18 @@ import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, globalPlugin,
12
12
  import { pkgResolve } from '../utils/helpers.js';
13
13
  import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
14
14
  const DEFAULT_LOGO = '/logo.svg';
15
+ const zhLocaleConfig = {
16
+ searchPlaceholderText: '搜索文档',
17
+ searchNoResultsText: '未搜索到相关结果',
18
+ searchSuggestedQueryText: '可更换不同的关键字后重试',
19
+ outlineTitle: '本页概览',
20
+ prevPageText: '上一页',
21
+ nextPageText: '下一页',
22
+ };
15
23
  const getCommonConfig = async (config) => {
24
+ const fallbackToZh = 'lang' in config && config.lang == null;
16
25
  return {
17
- lang: 'en',
26
+ lang: fallbackToZh ? 'zh' : config.lang,
18
27
  route: {
19
28
  exclude: [
20
29
  'dist/**/*',
@@ -36,24 +45,14 @@ const getCommonConfig = async (config) => {
36
45
  },
37
46
  themeConfig: {
38
47
  enableScrollToTop: true,
39
- locales: 'lang' in config && config.lang == null
40
- ? undefined
41
- : [
42
- {
43
- lang: 'zh',
44
- label: '简体中文',
45
- searchPlaceholderText: '搜索文档',
46
- searchNoResultsText: '未搜索到相关结果',
47
- searchSuggestedQueryText: '可更换不同的关键字后重试',
48
- outlineTitle: '本页概览',
49
- prevPageText: '上一页',
50
- nextPageText: '下一页',
51
- },
52
- {
53
- lang: 'en',
54
- label: 'English',
55
- },
56
- ],
48
+ ...(fallbackToZh
49
+ ? zhLocaleConfig
50
+ : {
51
+ locales: [
52
+ { lang: 'zh', label: '简体中文', ...zhLocaleConfig },
53
+ { lang: 'en', label: 'English' },
54
+ ],
55
+ }),
57
56
  },
58
57
  plugins: [
59
58
  pluginPreview({
@@ -1,2 +1,2 @@
1
- import { DoomConfig } from '../utils/index.js';
1
+ import { DoomConfig } from './utils/index.js';
2
2
  export declare const defineConfig: (config: DoomConfig) => DoomConfig;
@@ -0,0 +1 @@
1
+ export { Badge, Badge as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Badge, Badge as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Card, Card as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Card, Card as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { LinkCard, LinkCard as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { LinkCard, LinkCard as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { PackageManagerTabs, PackageManagerTabs as default, } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Steps, Steps as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Steps, Steps as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Tab, Tab as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Tab, Tab as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Tabs, Tabs as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Tabs, Tabs as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Toc, Toc as default } from '@rspress/theme-default';
@@ -0,0 +1 @@
1
+ export { Toc, Toc as default } from '@rspress/theme-default';
@@ -1,6 +1,14 @@
1
+ export * from './Badge.js';
1
2
  export * from './Callouts.js';
3
+ export * from './Card.js';
2
4
  export * from './K8sCrd.js';
5
+ export * from './LinkCard.js';
3
6
  export * from './Overview.js';
4
- export * from './QuickNav.js';
7
+ export * from './PackageManagerTabs.js';
5
8
  export * from './OpenAPIRef.js';
6
9
  export * from './OpenAPIPath.js';
10
+ export * from './QuickNav.js';
11
+ export * from './Steps.js';
12
+ export * from './Tab.js';
13
+ export * from './Tabs.js';
14
+ export * from './Toc.js';
@@ -1,6 +1,14 @@
1
+ export * from './Badge.js';
1
2
  export * from './Callouts.js';
3
+ export * from './Card.js';
2
4
  export * from './K8sCrd.js';
5
+ export * from './LinkCard.js';
3
6
  export * from './Overview.js';
4
- export * from './QuickNav.js';
7
+ export * from './PackageManagerTabs.js';
5
8
  export * from './OpenAPIRef.js';
6
9
  export * from './OpenAPIPath.js';
10
+ export * from './QuickNav.js';
11
+ export * from './Steps.js';
12
+ export * from './Tab.js';
13
+ export * from './Tabs.js';
14
+ export * from './Toc.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -14,6 +14,7 @@
14
14
  "bin": "lib/cli/index.js",
15
15
  "exports": {
16
16
  "./package.json": "./package.json",
17
+ "./config": "./lib/config.js",
17
18
  "./runtime": "./lib/runtime/index.js"
18
19
  },
19
20
  "files": [
@@ -1 +0,0 @@
1
- export * from './transformers/index.js';
@@ -1 +0,0 @@
1
- export * from './transformers/index.js';
@@ -1,7 +0,0 @@
1
- import { PluginShikiOptions } from '@rspress/plugin-shiki';
2
- import { IRangeTransformerOptions } from '../types.js';
3
- export interface ITransformerCalloutsOptions extends IRangeTransformerOptions {
4
- classActivePre?: string;
5
- classActiveLine?: string;
6
- }
7
- export declare const createTransformerCallouts: (options?: ITransformerCalloutsOptions) => Exclude<PluginShikiOptions["transformers"], undefined>[0];
@@ -1,16 +0,0 @@
1
- import { addClass, checkClass, createRangeTransformer } from '../utils.js';
2
- export const createTransformerCallouts = (options = {}) => {
3
- const { classActiveLine = 'callout', classActivePre = 'has-callouts' } = options;
4
- return {
5
- name: 'shiki-transformer:callouts',
6
- preTransformer: createRangeTransformer({
7
- callout: classActiveLine,
8
- }, options),
9
- postTransformer({ code }) {
10
- if (!checkClass(code, classActiveLine)) {
11
- return code;
12
- }
13
- return addClass(code, classActivePre, 'pre');
14
- },
15
- };
16
- };
@@ -1 +0,0 @@
1
- export * from './callouts.js';
@@ -1 +0,0 @@
1
- export * from './callouts.js';
@@ -1,14 +0,0 @@
1
- import type { HtmlRendererOptions } from 'shiki';
2
- export type TLineOptions = NonNullable<HtmlRendererOptions['lineOptions']>;
3
- export interface ITransformerResult {
4
- code: string;
5
- lineOptions: TLineOptions;
6
- }
7
- export interface ITransformerOptions {
8
- code: string;
9
- lang: string;
10
- }
11
- export type TPreTransformer = (options: ITransformerOptions) => ITransformerResult;
12
- export interface IRangeTransformerOptions {
13
- tagRegExp?: RegExp;
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import type { IRangeTransformerOptions, TPreTransformer } from './types.js';
2
- export declare function createRangeTransformer(classMap: Record<string, string | string[]>, options?: IRangeTransformerOptions): TPreTransformer;
3
- export declare const checkClass: (code: string, className: string | string[]) => boolean;
4
- export declare function addClass(code: string, classes: string | string[], tag?: string): string;
@@ -1,47 +0,0 @@
1
- export function createRangeTransformer(classMap, options = {}) {
2
- return ({ code }) => {
3
- // https://regex101.com/r/mUxvfx/1
4
- const tagRE = options.tagRegExp ??
5
- /(?:#|\/\/|\/\*{1,2}) *\[!code ([\w+-]+)(?::(\d+))?] *(?:\*{1,2}\/)?/;
6
- const lineOptions = [];
7
- const tags = Object.keys(classMap);
8
- const codeFormat = code
9
- .split('\n')
10
- .map((lineOfCode, lineNumber) => {
11
- const [match, tag, range] = lineOfCode.match(tagRE) ?? [];
12
- if (!match) {
13
- return lineOfCode;
14
- }
15
- if (!tags.includes(tag)) {
16
- return lineOfCode;
17
- }
18
- for (const [rangeOffset] of Array.from({
19
- length: Number(range ?? 1),
20
- }).entries()) {
21
- lineOptions.push({
22
- line: lineNumber + rangeOffset + 1,
23
- classes: typeof classMap[tag] === 'string'
24
- ? [classMap[tag]]
25
- : classMap[tag],
26
- });
27
- }
28
- return lineOfCode.replace(tagRE, '');
29
- })
30
- .join('\n');
31
- return {
32
- code: codeFormat,
33
- lineOptions,
34
- };
35
- };
36
- }
37
- export const checkClass = (code, className) => {
38
- const classes = Array.isArray(className) ? className.join(' ') : className;
39
- return code.search(classes) !== -1;
40
- };
41
- export function addClass(code, classes, tag) {
42
- const classRE = new RegExp(`<${tag ?? 'w+'}[^>]*class="([\\w+-:;\\/* ]*)"`);
43
- classes = Array.isArray(classes) ? classes : [classes];
44
- return code.replace(classRE, (match, previousClasses) => {
45
- return match.replace(previousClasses, `${previousClasses} ${classes.join(' ')}`.trim());
46
- });
47
- }
@@ -1,2 +0,0 @@
1
- import type { RspressPlugin } from '@rspress/core';
2
- export declare const swaggerPlugin: () => RspressPlugin;
@@ -1,38 +0,0 @@
1
- import path from 'node:path';
2
- import { glob } from 'tinyglobby';
3
- import { resolveStaticConfig } from '../../utils/index.js';
4
- const crdMap = {};
5
- const openapiMap = {};
6
- let allModelReferences;
7
- export const swaggerPlugin = () => {
8
- return {
9
- name: 'doom-swagger',
10
- async beforeBuild(config_) {
11
- const config = config_;
12
- if (!config.swagger) {
13
- return;
14
- }
15
- const { crds, openapis, modelReferences } = config.swagger;
16
- if (crds) {
17
- for (const file of await glob(crds, {
18
- cwd: config.root,
19
- })) {
20
- crdMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
21
- }
22
- }
23
- if (openapis) {
24
- for (const file of await glob(openapis, {
25
- cwd: config.root,
26
- })) {
27
- openapiMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
28
- }
29
- }
30
- allModelReferences = modelReferences;
31
- },
32
- extendPageData(pageData) {
33
- pageData.crdMap = crdMap;
34
- pageData.openapiMap = openapiMap;
35
- pageData.modelReferences = allModelReferences;
36
- },
37
- };
38
- };
@@ -1,28 +0,0 @@
1
- import { OpenAPIV3 } from 'openapi-types';
2
- export interface CustomResourceDefinitionVersion {
3
- name: string;
4
- schema: {
5
- openAPIV3Schema: OpenAPIV3.SchemaObject;
6
- };
7
- served: boolean;
8
- storage: boolean;
9
- }
10
- export interface CustomResourceDefinition {
11
- apiVersion: string;
12
- kind: 'CustomResourceDefinition';
13
- metadata: {
14
- annotations: Record<string, string>;
15
- name: string;
16
- };
17
- spec: {
18
- group: string;
19
- names: {
20
- kind: string;
21
- listKind: string;
22
- plural: string;
23
- singular: string;
24
- };
25
- scope: 'Namespaced' | 'Cluster';
26
- versions: CustomResourceDefinitionVersion[];
27
- };
28
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export interface SwaggerModelProps {
2
- model: string;
3
- }
4
- export declare const SwaggerModel: ({ model }: SwaggerModelProps) => import("react/jsx-runtime").JSX.Element;
5
- export default SwaggerModel;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export const SwaggerModel = ({ model }) => {
3
- return _jsx("h2", { children: model });
4
- };
5
- export default SwaggerModel;
@@ -1,5 +0,0 @@
1
- export interface SwaggerPathProps {
2
- path: string;
3
- }
4
- export declare const SwaggerPath: ({ path }: SwaggerPathProps) => import("react/jsx-runtime").JSX.Element | null;
5
- export default SwaggerPath;
@@ -1,32 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { usePageData } from '@rspress/core/runtime';
3
- import { getCustomMDXComponent } from '@rspress/core/theme';
4
- import { OpenAPIV3 } from 'openapi-types';
5
- import { useMemo } from 'react';
6
- import { HeadingTitle } from './_HeadingTitle.js';
7
- export const SwaggerPath = ({ path }) => {
8
- const X = useMemo(getCustomMDXComponent, []);
9
- const { page } = usePageData();
10
- const pathItem = useMemo(() => {
11
- for (const [, openapi] of Object.entries(page.openapiMap || {})) {
12
- const pathItem = openapi.paths?.[path];
13
- if (pathItem) {
14
- return pathItem;
15
- }
16
- }
17
- }, [page.openapiMap]);
18
- if (!pathItem) {
19
- console.error(`No OpenAPI path definition found for ${path}`);
20
- return null;
21
- }
22
- return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { level: 2, children: path }), Object.values(OpenAPIV3.HttpMethods).map((method) => {
23
- if (!pathItem[method]) {
24
- return null;
25
- }
26
- const { parameters, summary } = pathItem[method];
27
- return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { level: 3, children: [_jsx(X.code, { children: method }), summary] }), _jsx(HeadingTitle, { level: 4, children: "Parameters" }), _jsx(X.ul, { children: parameters?.map((parameter, index) => {
28
- return (_jsxs(X.li, { children: [_jsx(X.code, { children: parameter.name }), parameter.description] }, index));
29
- }) })] }));
30
- })] }));
31
- };
32
- export default SwaggerPath;
File without changes