@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.
@@ -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 = require(`./utils/${converter}`).default;
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
- if (fs.existsSync(flatOptionsFilePath)) {
9
- const content = fs.readFileSync(flatOptionsFilePath, 'utf8');
10
- data = JSON.parse(content);
11
- }
3
+ try {
4
+ data = require('../flat-options.json');
5
+ } catch {}
12
6
 
13
7
  export const flatOptionsData = data;
@@ -1,13 +1 @@
1
- import fs from 'fs';
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
- if (fs.existsSync(keyMappingFilePath)) {
9
- const content = fs.readFileSync(keyMappingFilePath, 'utf8');
10
- data = JSON.parse(content);
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), ![alt](url) and ![](url)
64
64
  const markdownLinkRegex = /!?\[([^\]]*)\]\(([^)]+)\)/g;
@@ -0,0 +1,10 @@
1
+ import { CONVER_LINK } from './constants';
2
+ import convertLink from './convert-link';
3
+
4
+ const plugins = {
5
+ [CONVER_LINK]: convertLink
6
+ }
7
+
8
+ export function loadPlugin(pluginName: string) {
9
+ return plugins[pluginName];
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.3.1",
3
+ "version": "2.3.4",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",