@alauda/doom 0.22.0 → 0.22.2

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/index.js CHANGED
@@ -28,7 +28,7 @@ program
28
28
  showGlobalOptions: true,
29
29
  })
30
30
  .option('-c, --config <config>', 'Specify the path to the config file')
31
- .option('-v <version>', `Specify the version of the documentation, can also be 'unversioned' or 'unversioned-x.y'`)
31
+ .option('-v <version>', 'Specify the version of the documentation, can also be `unversioned` or `unversioned-x.y`')
32
32
  .option('-b, --base <base>', 'Override the base of the documentation')
33
33
  .option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
34
34
  .option('-f, --force [boolean]', `Force to
@@ -40,6 +40,7 @@ program
40
40
  .option('-I, --include <language...>', 'Include **only** the specific language(s), `en ru` for example')
41
41
  .option('-E, --exclude <language...>', 'Include all languages except the specific language(s), `ru` for example')
42
42
  .option('-o, --out-dir <path>', 'Override the `outDir` defined in the config file or the default `dist/{base}/{version}`, the resulting path will be `dist/{outDir}/{version}`')
43
+ .option('-r, --redirect <enum>', 'Whether to redirect to the locale closest to `navigator.language` when the user visits the site, could be `auto` or `never`', 'auto')
43
44
  .option('-n, --no-open [boolean]', 'Do not open the browser after starting the server')
44
45
  .command('dev', { isDefault: true })
45
46
  .description('Start the development server')
@@ -1,6 +1,6 @@
1
1
  import { type UserConfig } from '@rspress/core';
2
2
  import type { GlobalCliOptions } from '../types.js';
3
- export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, }?: GlobalCliOptions): Promise<{
3
+ export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
5
  filepath?: string;
6
6
  }>;
@@ -36,7 +36,7 @@ const KNOWN_LOCALE_CONFIGS = {
36
36
  nextPageText: 'Следующая страница',
37
37
  },
38
38
  };
39
- const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, }) => {
39
+ const getCommonConfig = async ({ config, root, configFilePath, base, version, download, export: export_, ignore, force, open, lazy, include, exclude, redirect, }) => {
40
40
  const fallbackToZh = 'lang' in config && !config.lang;
41
41
  root = resolveDocRoot(CWD, root, config.root);
42
42
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
@@ -102,6 +102,7 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
102
102
  enableScrollToTop: true,
103
103
  // https://github.com/web-infra-dev/rspress/issues/2011
104
104
  outline: true,
105
+ localeRedirect: redirect,
105
106
  ...(fallbackToZh ? KNOWN_LOCALE_CONFIGS.zh : { locales }),
106
107
  },
107
108
  plugins: [
@@ -178,7 +179,7 @@ const findConfig = async (basePath) => {
178
179
  }
179
180
  }
180
181
  };
181
- export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, } = {}) {
182
+ export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, export: export_, ignore, force, open, lazy, include, exclude, outDir, redirect, } = {}) {
182
183
  let configFilePath;
183
184
  if (configFile) {
184
185
  configFilePath = path.resolve(configFile);
@@ -242,6 +243,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
242
243
  lazy,
243
244
  include,
244
245
  exclude,
246
+ redirect,
245
247
  });
246
248
  base = commonConfig.base;
247
249
  const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
@@ -12,7 +12,7 @@ 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 { fetchApi } from 'x-fetch';
15
+ import { xfetch } from 'x-fetch';
16
16
  import { parse } from 'yaml';
17
17
  import { cyan, red } from 'yoctocolors';
18
18
  import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
@@ -62,7 +62,7 @@ const DEFAULT_SYSTEM_PROMPT = `
62
62
  `.trim();
63
63
  let openai;
64
64
  const resolveTerms_ = async () => {
65
- const terms = await fetchApi('https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
65
+ const terms = await xfetch('https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
66
66
  const parsedTerms = parse(terms);
67
67
  return ('- 以下是常见的相关术语词汇对应表(English <-> 中文)\n' +
68
68
  parsedTerms.map(({ en, zh = en }) => ` * ${en} <-> ${zh}`).join('\n'));
@@ -1,5 +1,6 @@
1
1
  import { logger } from '@rspress/shared/logger';
2
2
  import { render } from 'ejs';
3
+ import { ResponseError, xfetch } from 'x-fetch';
3
4
  import { cyan, red } from 'yoctocolors';
4
5
  import { isCI } from './utils.js';
5
6
  const releaseCache = new Map();
@@ -7,41 +8,38 @@ const FIELD_MAPPER = {
7
8
  zh: 'customfield_13800',
8
9
  en: 'customfield_13801',
9
10
  };
11
+ const issuesToListItems = (issues, lang) => issues
12
+ .map((issue) => {
13
+ const description = ((FIELD_MAPPER[lang] && issue.fields[FIELD_MAPPER[lang]]) ||
14
+ issue.fields[FIELD_MAPPER.en])?.trim();
15
+ if (!description) {
16
+ return;
17
+ }
18
+ return {
19
+ type: 'listItem',
20
+ children: [
21
+ {
22
+ type: 'paragraph',
23
+ children: description
24
+ .split('\n')
25
+ .map((line) => ({ type: 'text', value: line }))
26
+ .reduce((acc, curr, index) => {
27
+ if (index === 0) {
28
+ return [curr];
29
+ }
30
+ return acc.concat({ type: 'html', value: '<br>' }, curr);
31
+ }, []),
32
+ },
33
+ ],
34
+ };
35
+ })
36
+ .filter(Boolean);
10
37
  const { JIRA_USERNAME, JIRA_PASSWORD } = process.env;
11
- const issuesToMdast = (issues, lang) => {
12
- return issues
13
- .map((issue) => {
14
- const description = ((lang !== 'en' && issue.fields[FIELD_MAPPER[lang]]) ||
15
- issue.fields[FIELD_MAPPER.en])?.trim();
16
- if (!description) {
17
- return;
18
- }
19
- return {
20
- type: 'listItem',
21
- children: [
22
- {
23
- type: 'paragraph',
24
- children: description
25
- .split('\n')
26
- .map((line) => {
27
- return {
28
- type: 'text',
29
- value: line,
30
- };
31
- })
32
- .reduce((acc, curr, index) => {
33
- if (index === 0) {
34
- return [curr];
35
- }
36
- return acc.concat({ type: 'html', value: '<br>' }, curr);
37
- }, []),
38
- },
39
- ],
40
- };
41
- })
42
- .filter((_) => !!_);
43
- };
44
38
  let warned = false;
39
+ const NO_ISSUE_MAPPER = {
40
+ zh: '此次发版无相关问题。',
41
+ en: 'No issues in this release.',
42
+ };
45
43
  const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
46
44
  const query = new URLSearchParams(releaseQuery);
47
45
  const templateName = query.get('template');
@@ -62,10 +60,8 @@ const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
62
60
  if (warned) {
63
61
  return;
64
62
  }
65
- else {
66
- warned = true;
67
- }
68
- const message = `${cyan('`JIRA_USERNAME`')} and ${cyan('`JIRA_PASSWORD`')} environments must be set for fetching Jira issues`;
63
+ warned = true;
64
+ const message = `\`${cyan('JIRA_USERNAME')}\` and \`${cyan('JIRA_PASSWORD')}\` environments must be set for fetching Jira issues`;
69
65
  if (isCI) {
70
66
  throw new Error(message);
71
67
  }
@@ -81,14 +77,32 @@ const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
81
77
  }
82
78
  const jql = await render(template, data, { async: true });
83
79
  logger.info(`Fetching release notes for query \`${cyan(releaseQuery)}\``);
84
- const res = await fetch(`https://jira.alauda.cn/rest/api/2/search?${new URLSearchParams({ jql })}`, { headers: { Authorization } });
85
- if (!res.ok) {
86
- logger.error(`Failed to fetch release notes for query \`${red(releaseQuery)}\` with status \`${res.status}\``);
80
+ let issues;
81
+ try {
82
+ ;
83
+ ({ issues } = await xfetch(`https://jira.alauda.cn/rest/api/2/search?${new URLSearchParams({ jql })}`, { headers: { Authorization } }));
84
+ }
85
+ catch (err) {
86
+ if (err instanceof ResponseError) {
87
+ logger.error(`Failed to fetch release notes for query \`${red(releaseQuery)}\` with status \`${err.response.status}\` and ${err.data ? `data ${JSON.stringify(data, null, 2)}` : `message \`${err.message}\``}`);
88
+ }
87
89
  return;
88
90
  }
89
- const { issues } = (await res.json());
90
- return ['en', 'zh'].reduce((acc, curr) => Object.assign(acc, {
91
- [curr]: { type: 'list', children: issuesToMdast(issues, curr) },
91
+ return ['en', 'zh'].reduce((acc, lang) => Object.assign(acc, {
92
+ [lang]: issues.length
93
+ ? {
94
+ type: 'list',
95
+ children: issuesToListItems(issues, lang),
96
+ }
97
+ : {
98
+ type: 'paragraph',
99
+ children: [
100
+ {
101
+ type: 'text',
102
+ value: NO_ISSUE_MAPPER[lang] || NO_ISSUE_MAPPER.en,
103
+ },
104
+ ],
105
+ },
92
106
  }), {});
93
107
  };
94
108
  export const resolveRelease = async (releaseTemplates, releaseQuery, lang) => {
@@ -30,3 +30,4 @@ export interface JiraIssue {
30
30
  key: string;
31
31
  fields: Partial<Record<string, string>>;
32
32
  }
33
+ export type JiraLanguage = 'zh' | 'en';
package/lib/types.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface GlobalCliOptions {
17
17
  include?: string[];
18
18
  exclude?: string[];
19
19
  outDir?: string;
20
+ redirect?: 'auto' | 'never';
20
21
  }
21
22
  export interface TranslateOptions {
22
23
  systemPrompt?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",