@alauda/doom 0.22.6 → 0.23.1
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/lib/cli/helpers.d.ts +12 -0
- package/lib/cli/helpers.js +9 -0
- package/lib/cli/index.js +2 -0
- package/lib/cli/lint.d.ts +2 -0
- package/lib/cli/lint.js +87 -0
- package/lib/cli/translate.js +2 -5
- package/lib/types.d.ts +5 -0
- package/package.json +14 -5
package/lib/cli/helpers.d.ts
CHANGED
|
@@ -7,3 +7,15 @@ export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(str
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function escapeMarkdownHeadingIds(content: string): string;
|
|
9
9
|
export declare const defaultGitHubUrl: (url: string) => string;
|
|
10
|
+
export declare const parseTerms: () => Promise<{
|
|
11
|
+
en: string;
|
|
12
|
+
zh?: string | undefined;
|
|
13
|
+
ru?: string | undefined;
|
|
14
|
+
description?: string | undefined;
|
|
15
|
+
badCases?: {
|
|
16
|
+
en?: string[];
|
|
17
|
+
zh?: string[];
|
|
18
|
+
ru?: string[];
|
|
19
|
+
} | undefined;
|
|
20
|
+
name?: "company" | "product" | "productShort" | undefined;
|
|
21
|
+
}[]>;
|
package/lib/cli/helpers.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { glob } from 'tinyglobby';
|
|
3
|
+
import { xfetch } from 'x-fetch';
|
|
4
|
+
import { parse } from 'yaml';
|
|
3
5
|
import { FALSY_VALUES } from '../shared/index.js';
|
|
4
6
|
export const parseBoolean = (value) => !!value && !FALSY_VALUES.has(value);
|
|
5
7
|
const DOC_PATTERN = /\.mdx?$/;
|
|
@@ -32,3 +34,10 @@ export function escapeMarkdownHeadingIds(content) {
|
|
|
32
34
|
export const defaultGitHubUrl = (url) => /^https?:\/\//.test(url)
|
|
33
35
|
? url
|
|
34
36
|
: `https://github.com/${url.replace(/^(\/*github.com)?\/+/i, '')}`;
|
|
37
|
+
const parseTerms_ = async () => {
|
|
38
|
+
const terms = await xfetch(process.env.RAW_TERMS_URL ||
|
|
39
|
+
'https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
|
|
40
|
+
return parse(terms);
|
|
41
|
+
};
|
|
42
|
+
let parsedTermsCache;
|
|
43
|
+
export const parseTerms = () => (parsedTermsCache ??= parseTerms_());
|
package/lib/cli/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { setNodeEnv } from '../utils/index.js';
|
|
|
14
14
|
import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
|
|
15
15
|
import { exportCommand } from './export.js';
|
|
16
16
|
import { parseBoolean } from './helpers.js';
|
|
17
|
+
import { lintCommand } from './lint.js';
|
|
17
18
|
import { loadConfig } from './load-config.js';
|
|
18
19
|
import { newCommand } from './new.js';
|
|
19
20
|
import { translateCommand } from './translate.js';
|
|
@@ -148,6 +149,7 @@ program
|
|
|
148
149
|
program.addCommand(newCommand);
|
|
149
150
|
program.addCommand(translateCommand);
|
|
150
151
|
program.addCommand(exportCommand);
|
|
152
|
+
program.addCommand(lintCommand);
|
|
151
153
|
program.parseAsync().catch((err) => {
|
|
152
154
|
if (err instanceof Error && err.name === 'ExitPromptError') {
|
|
153
155
|
return;
|
package/lib/cli/lint.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import cspellRecommended from '@cspell/eslint-plugin/recommended';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import react from '@eslint-react/eslint-plugin';
|
|
4
|
+
import { logger } from '@rspress/shared/logger';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import { merge } from 'es-toolkit/compat';
|
|
7
|
+
import { ESLint } from 'eslint';
|
|
8
|
+
import * as mdx from 'eslint-plugin-mdx';
|
|
9
|
+
import tseslint from 'typescript-eslint';
|
|
10
|
+
import { parseTerms } from './helpers.js';
|
|
11
|
+
import { loadConfig } from './load-config.js';
|
|
12
|
+
export const lintCommand = new Command('lint')
|
|
13
|
+
.description('Lint the documentation')
|
|
14
|
+
.argument('[root]', 'Root directory of the documentation')
|
|
15
|
+
.action(async function (root) {
|
|
16
|
+
const globalOptions = this.optsWithGlobals();
|
|
17
|
+
const { config } = await loadConfig(root, globalOptions);
|
|
18
|
+
const docsDir = config.root;
|
|
19
|
+
const parsedTerms = await parseTerms();
|
|
20
|
+
const eslint = new ESLint({
|
|
21
|
+
cwd: docsDir,
|
|
22
|
+
overrideConfigFile: true,
|
|
23
|
+
// @ts-expect-error -- stronger types
|
|
24
|
+
overrideConfig: tseslint.config([
|
|
25
|
+
{
|
|
26
|
+
extends: [
|
|
27
|
+
js.configs.recommended,
|
|
28
|
+
react.configs.recommended,
|
|
29
|
+
mdx.configs.flat,
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
files: ['**/en/**/*.{js,jsx,md,mdx,ts,tsx}'],
|
|
34
|
+
extends: [cspellRecommended],
|
|
35
|
+
rules: {
|
|
36
|
+
'@cspell/spellchecker': [
|
|
37
|
+
'error',
|
|
38
|
+
merge({
|
|
39
|
+
autoFix: true,
|
|
40
|
+
cspell: {
|
|
41
|
+
words: parsedTerms.map((it) => it.en),
|
|
42
|
+
flagWords: parsedTerms.flatMap(({ badCases }) => badCases?.en ?? []),
|
|
43
|
+
},
|
|
44
|
+
}, config.lint?.cspellOptions),
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
files: ['**/*.{ts,tsx}'],
|
|
50
|
+
extends: [
|
|
51
|
+
tseslint.configs.recommendedTypeChecked,
|
|
52
|
+
react.configs['recommended-typescript'],
|
|
53
|
+
],
|
|
54
|
+
rules: {
|
|
55
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
56
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
57
|
+
'@typescript-eslint/restrict-template-expressions': [
|
|
58
|
+
'error',
|
|
59
|
+
{ allowNumber: true },
|
|
60
|
+
],
|
|
61
|
+
'prefer-const': ['error', { destructuring: 'all' }],
|
|
62
|
+
},
|
|
63
|
+
languageOptions: {
|
|
64
|
+
parser: tseslint.parser,
|
|
65
|
+
parserOptions: {
|
|
66
|
+
projectService: true,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
]),
|
|
71
|
+
});
|
|
72
|
+
logger.start('Linting...');
|
|
73
|
+
const results = await eslint.lintFiles('**/*.{js,jsx,ts,tsx,md,mdx}');
|
|
74
|
+
const { error, warning } = results.reduce((count, result) => ({
|
|
75
|
+
error: count.error + result.errorCount,
|
|
76
|
+
warning: count.warning + result.warningCount,
|
|
77
|
+
}), { error: 0, warning: 0 });
|
|
78
|
+
logger.info(`Linting completed with ${error} errors and ${warning} warnings`);
|
|
79
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
80
|
+
const formatted = await formatter.format(results);
|
|
81
|
+
if (formatted) {
|
|
82
|
+
console.log(formatted);
|
|
83
|
+
}
|
|
84
|
+
if (error) {
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
}
|
|
87
|
+
});
|
package/lib/cli/translate.js
CHANGED
|
@@ -12,13 +12,11 @@ import matter from 'gray-matter';
|
|
|
12
12
|
import { AzureOpenAI, RateLimitError } from 'openai';
|
|
13
13
|
import { pRateLimit } from 'p-ratelimit';
|
|
14
14
|
import { glob } from 'tinyglobby';
|
|
15
|
-
import { xfetch } from 'x-fetch';
|
|
16
|
-
import { parse } from 'yaml';
|
|
17
15
|
import { cyan, red } from 'yoctocolors';
|
|
18
16
|
import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
|
|
19
17
|
import { Language, SUPPORTED_LANGUAGES } from '../shared/index.js';
|
|
20
18
|
import { pathExists } from '../utils/index.js';
|
|
21
|
-
import { escapeMarkdownHeadingIds, getMatchedDocFilePaths, parseBoolean, } from './helpers.js';
|
|
19
|
+
import { escapeMarkdownHeadingIds, getMatchedDocFilePaths, parseBoolean, parseTerms, } from './helpers.js';
|
|
22
20
|
import { loadConfig } from './load-config.js';
|
|
23
21
|
export const TERMS_SUPPORTED_LANGUAGES = ['en', 'zh'];
|
|
24
22
|
const DEFAULT_SYSTEM_PROMPT = `
|
|
@@ -62,8 +60,7 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
62
60
|
`.trim();
|
|
63
61
|
let openai;
|
|
64
62
|
const resolveTerms_ = async () => {
|
|
65
|
-
const
|
|
66
|
-
const parsedTerms = parse(terms);
|
|
63
|
+
const parsedTerms = await parseTerms();
|
|
67
64
|
return ('- 以下是常见的相关术语词汇对应表(English <-> 中文)\n' +
|
|
68
65
|
parsedTerms.map(({ en, zh = en }) => ` * ${en} <-> ${zh}`).join('\n'));
|
|
69
66
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Options } from '@cspell/eslint-plugin';
|
|
1
2
|
import type { serve } from '@rspress/core';
|
|
2
3
|
import type { ApiPluginOptions, AutoSidebarPluginOptions, PermissionPluginOptions, PluginShikiOptions, ReferenceItem, ReleaseNotesOptions } from './plugins/index.js';
|
|
3
4
|
import type { DoomSite } from './shared/index.js';
|
|
@@ -24,6 +25,9 @@ export interface TranslateOptions {
|
|
|
24
25
|
systemPrompt?: string;
|
|
25
26
|
userPrompt?: string;
|
|
26
27
|
}
|
|
28
|
+
export interface LintOptions {
|
|
29
|
+
cspellOptions?: Partial<Options>;
|
|
30
|
+
}
|
|
27
31
|
declare module '@rspress/shared' {
|
|
28
32
|
interface UserConfig {
|
|
29
33
|
prefix?: string;
|
|
@@ -38,6 +42,7 @@ declare module '@rspress/shared' {
|
|
|
38
42
|
translate?: TranslateOptions;
|
|
39
43
|
shiki?: PluginShikiOptions;
|
|
40
44
|
editRepoBaseUrl?: string;
|
|
45
|
+
lint?: LintOptions;
|
|
41
46
|
}
|
|
42
47
|
interface SiteData {
|
|
43
48
|
originalTitle?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "git+https://github.com/alauda/doom.git",
|
|
@@ -34,19 +34,25 @@
|
|
|
34
34
|
"rspress-plugins"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@cspell/eslint-plugin": "^9.0.1",
|
|
38
|
+
"@eslint-react/eslint-plugin": "^1.49.0",
|
|
37
39
|
"@inquirer/prompts": "^7.5.1",
|
|
38
40
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
39
41
|
"@playwright/browser-chromium": "^1.52.0",
|
|
40
42
|
"@rsbuild/plugin-yaml": "^1.0.2",
|
|
41
|
-
"@rspress/core": "1.
|
|
42
|
-
"@shikijs/transformers": "^3.4.
|
|
43
|
+
"@rspress/core": "1.44.0",
|
|
44
|
+
"@shikijs/transformers": "^3.4.2",
|
|
43
45
|
"chokidar": "^4.0.3",
|
|
44
46
|
"cli-progress": "^3.12.0",
|
|
45
47
|
"clsx": "^2.1.1",
|
|
46
48
|
"commander": "^13.1.0",
|
|
47
49
|
"ejs": "^3.1.10",
|
|
48
50
|
"es-toolkit": "^1.37.2",
|
|
51
|
+
"eslint": "^9.26.0",
|
|
52
|
+
"eslint-plugin-mdx": "^3.4.2",
|
|
49
53
|
"html-tag-names": "^2.1.0",
|
|
54
|
+
"mdast-util-mdx": "^2.0.1",
|
|
55
|
+
"mdast-util-mdx-jsx": "^2.1.4",
|
|
50
56
|
"mermaid": "^11.6.0",
|
|
51
57
|
"openai": "^5.0.0-beta.0",
|
|
52
58
|
"openapi-types": "^12.1.3",
|
|
@@ -60,13 +66,16 @@
|
|
|
60
66
|
"remark-directive": "^2.0.1",
|
|
61
67
|
"remark-frontmatter": "^4.0.1",
|
|
62
68
|
"remark-gfm": "^3.0.1",
|
|
63
|
-
"
|
|
69
|
+
"remark-mdx": "^2.3.0",
|
|
70
|
+
"remark-stringify": "^10.0.3",
|
|
71
|
+
"shiki": "^3.4.2",
|
|
64
72
|
"simple-git": "^3.27.0",
|
|
65
73
|
"swagger2openapi": "^7.0.8",
|
|
66
74
|
"tinyglobby": "^0.2.13",
|
|
67
75
|
"type-fest": "^4.41.0",
|
|
76
|
+
"typescript-eslint": "^8.32.1",
|
|
68
77
|
"x-fetch": "^0.2.6",
|
|
69
|
-
"yaml": "^2.
|
|
78
|
+
"yaml": "^2.8.0",
|
|
70
79
|
"yoctocolors": "^2.1.1"
|
|
71
80
|
},
|
|
72
81
|
"publishConfig": {
|