@alauda/doom 0.14.5 → 0.14.6

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.
@@ -6,8 +6,10 @@ import { Command } from 'commander';
6
6
  import matter from 'gray-matter';
7
7
  import { AzureOpenAI } from 'openai';
8
8
  import { pRateLimit } from 'p-ratelimit';
9
+ import { glob } from 'tinyglobby';
9
10
  import { cyan } from 'yoctocolors';
10
11
  import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
12
+ import { isDoc } from '../shared/index.js';
11
13
  import { pathExists } from '../utils/index.js';
12
14
  import { loadConfig } from './load-config.js';
13
15
  const LANGUAGE_CODES = {
@@ -88,8 +90,9 @@ export const translateCommand = new Command('translate')
88
90
  .argument('[root]', 'Root directory of the documentation')
89
91
  .option('-s, --source <language>', 'Document source language', 'zh')
90
92
  .option('-t, --target <language>', 'Document target language', 'en')
93
+ .option('-g, --glob <path...>', 'Glob pattern for source files')
91
94
  .action(async function (root) {
92
- const { source, target, ...globalOptions } = this.optsWithGlobals();
95
+ const { source, target, glob: globs, ...globalOptions } = this.optsWithGlobals();
93
96
  if (!Object.hasOwn(LANGUAGE_CODES, source) ||
94
97
  !Object.hasOwn(LANGUAGE_CODES, target) ||
95
98
  source === target) {
@@ -106,17 +109,32 @@ export const translateCommand = new Command('translate')
106
109
  process.exitCode = 1;
107
110
  return;
108
111
  }
109
- const dirents = await fs.readdir(sourceDir, {
110
- recursive: true,
111
- withFileTypes: true,
112
- });
113
- await Promise.all(dirents.map(async (d) => {
114
- if (!d.isFile() || !/\.mdx?$/.test(d.name)) {
112
+ let sourceFilePaths;
113
+ if (globs?.length) {
114
+ sourceFilePaths = await glob(globs.map((g) => g.split('/').at(-1).includes('.') ? g : `${g}.md{,x}`), {
115
+ absolute: true,
116
+ cwd: sourceDir,
117
+ });
118
+ }
119
+ else {
120
+ const dirents = await fs.readdir(sourceDir, {
121
+ recursive: true,
122
+ withFileTypes: true,
123
+ });
124
+ sourceFilePaths = dirents.reduce((acc, d) => {
125
+ if (!d.isFile() || !isDoc(d.name)) {
126
+ return acc;
127
+ }
128
+ acc.push(path.resolve(d.parentPath ||
129
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
130
+ d.path, d.name));
131
+ return acc;
132
+ }, []);
133
+ }
134
+ await Promise.all(sourceFilePaths.map(async (sourceFilePath) => {
135
+ if (!isDoc(sourceFilePath)) {
115
136
  return;
116
137
  }
117
- const sourceFilePath = path.resolve(d.parentPath ||
118
- // eslint-disable-next-line @typescript-eslint/no-deprecated
119
- d.path, d.name);
120
138
  const sourceContent = await fs.readFile(sourceFilePath, 'utf-8');
121
139
  const sourceFrontmatter = matter(sourceContent).data;
122
140
  if (sourceFrontmatter.i18n?.disableAutoTranslation) {
@@ -1,3 +1,5 @@
1
1
  export declare const normalizeVersion: (version?: string) => string;
2
2
  export declare const removeBothEndsSlashes: (str?: string) => string;
3
3
  export declare const getPdfName: (lang: string, userBase?: string, title?: string) => string;
4
+ export declare const DOC_PATTERN: RegExp;
5
+ export declare const isDoc: (filename: string) => boolean;
@@ -2,3 +2,5 @@ const PLAIN_VERSION_PATTERN = /^(\d+\.)*\d+$/;
2
2
  export const normalizeVersion = (version = '') => PLAIN_VERSION_PATTERN.test(version) ? `v${version}` : version;
3
3
  export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
4
4
  export const getPdfName = (lang, userBase, title) => `${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
5
+ export const DOC_PATTERN = /\.mdx?$/;
6
+ export const isDoc = (filename) => DOC_PATTERN.test(filename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -73,14 +73,14 @@
73
73
  "simple-git": "^3.27.0",
74
74
  "swagger2openapi": "^7.0.8",
75
75
  "tinyglobby": "^0.2.12",
76
- "type-fest": "^4.36.0",
76
+ "type-fest": "^4.37.0",
77
77
  "yaml": "^2.7.0",
78
78
  "yoctocolors": "^2.1.1"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@eslint/js": "^9.21.0",
82
82
  "@swc-node/register": "^1.10.9",
83
- "@swc/core": "1.11.5",
83
+ "@swc/core": "1.11.7",
84
84
  "@types/cli-progress": "^3.11.6",
85
85
  "@types/ejs": "^3.1.5",
86
86
  "@types/fs-extra": "^11.0.4",