@cnbcool/cnb-api-generate 2.3.1 → 2.3.4
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/client/fetch-response-handler.ts +3 -1
- package/client/lib/flat-options-data.ts +3 -9
- package/client/lib/help-data.ts +1 -13
- package/client/lib/key-mapping-data.ts +3 -9
- package/client/plugins/constants.ts +1 -0
- package/client/{utils → plugins}/convert-link.ts +3 -3
- package/client/plugins/index.ts +10 -0
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { loadPlugin } from "./plugins";
|
|
2
|
+
|
|
1
3
|
export async function fetchResponseHandler(fetchOriginParams: Record<string, any>, response: {
|
|
2
4
|
status: number,
|
|
3
5
|
trace?: string,
|
|
@@ -27,7 +29,7 @@ export async function fetchResponseHandler(fetchOriginParams: Record<string, any
|
|
|
27
29
|
if (convertConfig) {
|
|
28
30
|
const {converter, handler} = convertConfig;
|
|
29
31
|
try {
|
|
30
|
-
const converterExample =
|
|
32
|
+
const converterExample = loadPlugin(converter);
|
|
31
33
|
if (converterExample && typeof converterExample === 'function') {
|
|
32
34
|
return handler(converterExample, fetchOriginParams, response.data);
|
|
33
35
|
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const flatOptionsFilePath = path.join(__dirname, '../flat-options.json');
|
|
5
|
-
|
|
6
1
|
let data: Record<string, Record<string, Record<string, any>>> = {};
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
3
|
+
try {
|
|
4
|
+
data = require('../flat-options.json');
|
|
5
|
+
} catch {}
|
|
12
6
|
|
|
13
7
|
export const flatOptionsData = data;
|
package/client/lib/help-data.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const helpFileContent = fs.readFileSync(
|
|
5
|
-
path.join(__dirname, '../help.json'),
|
|
6
|
-
'utf8',
|
|
7
|
-
);
|
|
8
|
-
if (!helpFileContent) {
|
|
9
|
-
console.error('help.json not found');
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const helpData = JSON.parse(helpFileContent);
|
|
1
|
+
export const helpData = require('../help.json');
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const keyMappingFilePath = path.join(__dirname, '../key-mapping.json');
|
|
5
|
-
|
|
6
1
|
let data: Record<string, Record<string, Record<string, string>>> = {};
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
3
|
+
try {
|
|
4
|
+
data = require('../key-mapping.json');
|
|
5
|
+
} catch {}
|
|
12
6
|
|
|
13
7
|
export const keyMappingData = data;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CONVER_LINK = 'convert-link'
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export default function convertLink(text: string, repoSlug: string | undefined, branchOrSha: string | undefined) {
|
|
11
11
|
// 查询所有代码块的位置
|
|
12
|
-
let codeBlockPositions = [];
|
|
12
|
+
let codeBlockPositions: number[] = [];
|
|
13
13
|
let index = 0;
|
|
14
14
|
while (index !== -1) {
|
|
15
15
|
const nextIndex = text.indexOf('```', index);
|
|
@@ -22,7 +22,7 @@ export default function convertLink(text: string, repoSlug: string | undefined,
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// 查询所有行内代码块的位置
|
|
25
|
-
let inlineCodeBlockPositions = [];
|
|
25
|
+
let inlineCodeBlockPositions: number[] = [];
|
|
26
26
|
index = 0;
|
|
27
27
|
while (index < text.length) {
|
|
28
28
|
const nextIndex = text.indexOf('`', index);
|
|
@@ -58,7 +58,7 @@ export default function convertLink(text: string, repoSlug: string | undefined,
|
|
|
58
58
|
let match;
|
|
59
59
|
|
|
60
60
|
// Collect all replacements with their positions
|
|
61
|
-
const replacements = [];
|
|
61
|
+
const replacements: { start: number; end: number; newUrl: string }[] = [];
|
|
62
62
|
|
|
63
63
|
// Match markdown links and images: [alt](url), [](url),  and 
|
|
64
64
|
const markdownLinkRegex = /!?\[([^\]]*)\]\(([^)]+)\)/g;
|