@alauda/doom 0.16.3 → 0.17.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/lib/cli/helpers.d.ts +1 -0
- package/lib/cli/helpers.js +16 -0
- package/lib/cli/load-config.js +2 -0
- package/lib/cli/translate.js +39 -19
- package/package.json +8 -8
package/lib/cli/helpers.d.ts
CHANGED
package/lib/cli/helpers.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { glob } from 'tinyglobby';
|
|
3
|
+
import { isDoc } from '../shared/index.js';
|
|
1
4
|
export const parseBoolean = (value) => !!value && !['0', 'false'].includes(value);
|
|
5
|
+
export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async (it) => {
|
|
6
|
+
const stat = await fs.stat(it);
|
|
7
|
+
if (stat.isDirectory()) {
|
|
8
|
+
return glob('**/*.md{,x}', {
|
|
9
|
+
absolute: true,
|
|
10
|
+
cwd: it,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (stat.isFile() && isDoc(it)) {
|
|
14
|
+
return it;
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}));
|
package/lib/cli/load-config.js
CHANGED
package/lib/cli/translate.js
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { setTimeout } from 'node:timers/promises';
|
|
5
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
6
|
import { removeLeadingSlash } from '@rspress/shared';
|
|
6
7
|
import { logger } from '@rspress/shared/logger';
|
|
7
8
|
import { Command } from 'commander';
|
|
@@ -11,11 +12,10 @@ import matter from 'gray-matter';
|
|
|
11
12
|
import { AzureOpenAI, RateLimitError } from 'openai';
|
|
12
13
|
import { pRateLimit } from 'p-ratelimit';
|
|
13
14
|
import { glob } from 'tinyglobby';
|
|
14
|
-
import { cyan } from 'yoctocolors';
|
|
15
|
+
import { cyan, red } from 'yoctocolors';
|
|
15
16
|
import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
|
|
16
|
-
import { isDoc } from '../shared/index.js';
|
|
17
17
|
import { pathExists } from '../utils/index.js';
|
|
18
|
-
import { parseBoolean } from './helpers.js';
|
|
18
|
+
import { getMatchedDocFilePaths, parseBoolean } from './helpers.js';
|
|
19
19
|
import { loadConfig } from './load-config.js';
|
|
20
20
|
const LANGUAGE_CODES = {
|
|
21
21
|
zh: '中文',
|
|
@@ -104,8 +104,8 @@ const limit = pRateLimit({
|
|
|
104
104
|
export const translateCommand = new Command('translate')
|
|
105
105
|
.description('Translate the documentation')
|
|
106
106
|
.argument('[root]', 'Root directory of the documentation')
|
|
107
|
-
.option('-s, --source <language>', 'Document source language', '
|
|
108
|
-
.option('-t, --target <language>', 'Document target language', '
|
|
107
|
+
.option('-s, --source <language>', 'Document source language', 'en')
|
|
108
|
+
.option('-t, --target <language>', 'Document target language', 'zh')
|
|
109
109
|
.requiredOption('-g, --glob <path...>', 'Glob patterns for source dirs/files')
|
|
110
110
|
.option('-C, --copy [boolean]', 'Wether to copy relative assets to the target directory instead of following links', parseBoolean, false)
|
|
111
111
|
.action(async function (root) {
|
|
@@ -126,30 +126,50 @@ export const translateCommand = new Command('translate')
|
|
|
126
126
|
process.exitCode = 1;
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
const
|
|
129
|
+
const sourceMatched = await glob(globs.map(removeLeadingSlash), {
|
|
130
130
|
absolute: true,
|
|
131
131
|
cwd: sourceDir,
|
|
132
132
|
onlyFiles: false,
|
|
133
133
|
});
|
|
134
|
-
|
|
134
|
+
const sourceFilePaths = await getMatchedDocFilePaths(sourceMatched);
|
|
135
|
+
const allSourceFilePaths = new Set(sourceFilePaths.flat());
|
|
136
|
+
const internalFilePaths = await glob(config.internalRoutes || [], {
|
|
137
|
+
absolute: true,
|
|
138
|
+
cwd: docsDir,
|
|
139
|
+
});
|
|
140
|
+
for (const internalFilePath of internalFilePaths) {
|
|
141
|
+
allSourceFilePaths.delete(internalFilePath);
|
|
142
|
+
}
|
|
143
|
+
if (allSourceFilePaths.size === 0) {
|
|
135
144
|
logger.error(`No files matched by the glob patterns: ${globs.map((g) => `\`${cyan(g)}\``).join(', ')}`);
|
|
136
145
|
process.exitCode = 1;
|
|
137
146
|
return;
|
|
138
147
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
if (isDeepStrictEqual(globs, ['*'])) {
|
|
149
|
+
logger.warn(`You're running in a special mode, all files except \`${cyan('internalRoutes')}\` will be translated, and all ${red('unmatched')} target files will be ${red('removed')}.`);
|
|
150
|
+
const targetMatched = await glob(globs.map(removeLeadingSlash), {
|
|
151
|
+
absolute: true,
|
|
152
|
+
cwd: targetDir,
|
|
153
|
+
onlyFiles: false,
|
|
154
|
+
});
|
|
155
|
+
const targetFilePaths = await getMatchedDocFilePaths(targetMatched);
|
|
156
|
+
const allTargetFilePaths = new Set(targetFilePaths.flat());
|
|
157
|
+
for (const internalFilePath of internalFilePaths) {
|
|
158
|
+
allTargetFilePaths.delete(internalFilePath);
|
|
146
159
|
}
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
const toRemoveTargetFilePaths = [];
|
|
161
|
+
for (const targetFilePath of allTargetFilePaths) {
|
|
162
|
+
const targetRelativePath = path.relative(targetDir, targetFilePath);
|
|
163
|
+
const sourceFilePath = path.resolve(sourceDir, targetRelativePath);
|
|
164
|
+
if (!allSourceFilePaths.has(sourceFilePath)) {
|
|
165
|
+
toRemoveTargetFilePaths.push(targetFilePath);
|
|
166
|
+
}
|
|
149
167
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
168
|
+
if (toRemoveTargetFilePaths.length > 0) {
|
|
169
|
+
logger.warn('Found unmatched target files will be removed:\n', ...toRemoveTargetFilePaths.map((file) => `- ${red(file)}`));
|
|
170
|
+
await Promise.all(toRemoveTargetFilePaths.map((file) => fs.rm(file)));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
153
173
|
const executor = async () => await Promise.all([...allSourceFilePaths].map(async (sourceFilePath) => {
|
|
154
174
|
const sourceContent = await fs.readFile(sourceFilePath, 'utf-8');
|
|
155
175
|
const sourceFrontmatter = matter(sourceContent)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"prepublishOnly": "yarn build",
|
|
38
38
|
"serve": "yarn doom serve",
|
|
39
39
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register",
|
|
40
|
-
"translate": "yarn doom translate fixture-docs
|
|
40
|
+
"translate": "yarn doom translate fixture-docs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@inquirer/prompts": "^7.4.0",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"clsx": "^2.1.1",
|
|
52
52
|
"commander": "^13.1.0",
|
|
53
53
|
"ejs": "^3.1.10",
|
|
54
|
-
"es-toolkit": "^1.
|
|
54
|
+
"es-toolkit": "^1.34.1",
|
|
55
55
|
"html-tag-names": "^2.1.0",
|
|
56
|
-
"mermaid": "^11.
|
|
56
|
+
"mermaid": "^11.6.0",
|
|
57
57
|
"openai": "^5.0.0-beta.0",
|
|
58
58
|
"openapi-types": "^12.1.3",
|
|
59
59
|
"p-ratelimit": "^1.0.1",
|
|
@@ -80,22 +80,22 @@
|
|
|
80
80
|
"@swc/core": "1.11.13",
|
|
81
81
|
"@types/cli-progress": "^3.11.6",
|
|
82
82
|
"@types/ejs": "^3.1.5",
|
|
83
|
-
"@types/node": "^18.19.
|
|
83
|
+
"@types/node": "^18.19.84",
|
|
84
84
|
"@types/picomatch": "^3.0.2",
|
|
85
85
|
"@types/react": "^18.3.20",
|
|
86
86
|
"@types/react-dom": "^18.3.5",
|
|
87
87
|
"@types/swagger2openapi": "^7.0.4",
|
|
88
88
|
"@unts/patch-package": "^8.1.1",
|
|
89
89
|
"eslint": "^9.23.0",
|
|
90
|
-
"eslint-import-resolver-typescript": "^4.2.
|
|
91
|
-
"eslint-plugin-import-x": "^4.9.
|
|
90
|
+
"eslint-import-resolver-typescript": "^4.2.5",
|
|
91
|
+
"eslint-plugin-import-x": "^4.9.3",
|
|
92
92
|
"lint-staged": "^15.5.0",
|
|
93
93
|
"npm-run-all2": "^7.0.2",
|
|
94
94
|
"prettier": "^3.5.3",
|
|
95
95
|
"prettier-plugin-pkg": "^0.18.1",
|
|
96
96
|
"simple-git-hooks": "^2.12.1",
|
|
97
97
|
"typescript": "^5.8.2",
|
|
98
|
-
"typescript-eslint": "^8.
|
|
98
|
+
"typescript-eslint": "^8.28.0",
|
|
99
99
|
"yarn-berry-deduplicate": "^6.1.1"
|
|
100
100
|
},
|
|
101
101
|
"publishConfig": {
|