@cnbcool/cnb-cli 1.0.0 → 1.0.1

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.
Files changed (33) hide show
  1. package/README.md +2 -37
  2. package/package.json +26 -6
  3. package/.cnb.yml +0 -37
  4. package/DEVELOPMENT.md +0 -345
  5. package/cag.config.js +0 -57
  6. package/downloads/1773729361207-dsfgely.png +0 -0
  7. package/skills/artifact-migrate/README.md +0 -79
  8. package/skills/artifact-migrate/SKILL.md +0 -674
  9. package/skills/auto-code/SKILL.md +0 -71
  10. package/skills/auto-code/hooks/hooks.json +0 -15
  11. package/skills/cnb-code-import/LICENSE +0 -20
  12. package/skills/cnb-code-import/README.md +0 -311
  13. package/skills/cnb-code-import/SKILL.md +0 -368
  14. package/skills/cnb-code-import/scripts/migrate.sh +0 -371
  15. package/skills/cnb-skill/SKILL.md +0 -100
  16. package/skills/code-review/README.md +0 -3
  17. package/skills/code-review/SKILL.md +0 -131
  18. package/skills/code-review/hooks/hooks.json +0 -15
  19. package/skills/diagnose-pr-pipeline/README.md +0 -3
  20. package/skills/diagnose-pr-pipeline/SKILL.md +0 -88
  21. package/skills/dialog-ci-log/README.md +0 -16
  22. package/skills/dialog-ci-log/SKILL.md +0 -41
  23. package/skills/dialog-ci-log/scrips/get-failed-stage-logs.js +0 -124
  24. package/skills/pr-diff/README.md +0 -3
  25. package/skills/pr-diff/SKILL.md +0 -97
  26. package/skills/pr-summary/README.md +0 -3
  27. package/skills/pr-summary/SKILL.md +0 -70
  28. package/skills/tapd-resource-fetcher/README.md +0 -3
  29. package/skills/tapd-resource-fetcher/SKILL.md +0 -97
  30. package/skills/text-path-converter/README.md +0 -3
  31. package/skills/text-path-converter/SKILL.md +0 -30
  32. package/skills/text-path-converter/scripts/convertLink.js +0 -148
  33. package/test.js +0 -1
@@ -1,148 +0,0 @@
1
- /**
2
- * 把文本里的相对路径转换为绝对路径
3
- * 与 src/helpers/convertLink.ts 逻辑一致
4
- *
5
- * @param {String} text 待转换的文本
6
- * @param {String} repoSlug 仓库路径
7
- * @param {String} branchOrSha 可选,分支或SHA
8
- * @returns {String}
9
- */
10
- function convertLink(text, repoSlug, branchOrSha) {
11
- // 查询所有代码块的位置
12
- let codeBlockPositions = [];
13
- let index = 0;
14
- while (index !== -1) {
15
- const nextIndex = text.indexOf('```', index);
16
- if (nextIndex === -1) break;
17
- codeBlockPositions.push(nextIndex);
18
- index = nextIndex + 3; // 跳过已匹配的三个反引号
19
- }
20
- if (codeBlockPositions.length % 2 !== 0) {
21
- codeBlockPositions = codeBlockPositions.slice(0, codeBlockPositions.length - 1);
22
- }
23
-
24
- // 查询所有行内代码块的位置
25
- let inlineCodeBlockPositions = [];
26
- index = 0;
27
- while (index < text.length) {
28
- const nextIndex = text.indexOf('`', index);
29
- if (nextIndex === -1) break;
30
- // 检查是否是单独的反引号(不是代码块的一部分)
31
- if (
32
- (nextIndex === 0 || text.charAt(nextIndex - 1) !== '`') &&
33
- (nextIndex === text.length - 1 || text.charAt(nextIndex + 1) !== '`')
34
- ) {
35
- inlineCodeBlockPositions.push(nextIndex);
36
- }
37
- index = nextIndex + 1;
38
- }
39
- if (inlineCodeBlockPositions.length % 2 !== 0) {
40
- inlineCodeBlockPositions = inlineCodeBlockPositions.slice(0, inlineCodeBlockPositions.length - 1);
41
- }
42
-
43
- // 整理起始和结束位置
44
- const excludedRanges = [...codeBlockPositions, ...inlineCodeBlockPositions].reduce((result, item, index) => {
45
- if (index % 2 === 0) {
46
- return result.concat([[item]]);
47
- } else {
48
- result[result.length - 1].push(item);
49
- return result;
50
- }
51
- }, []);
52
-
53
- // Helper function to check if an index is within excluded ranges
54
- const isInExcludedRange = (index) => {
55
- return excludedRanges.some(([start, end]) => index >= start && index < end);
56
- };
57
-
58
- let match;
59
-
60
- // Collect all replacements with their positions
61
- const replacements = [];
62
-
63
- // Match markdown links and images: [alt](url), [](url), ![alt](url) and ![](url)
64
- const markdownLinkRegex = /!?\[([^\]]*)\]\(([^)]+)\)/g;
65
- while ((match = markdownLinkRegex.exec(text)) !== null) {
66
- if (!isInExcludedRange(match.index)) {
67
- // Calculate URL position: match.index + length of "![" + match[1] + "]("
68
- const prefixLength = (match[0].startsWith('!') ? 1 : 0) + 1 + match[1].length + 2;
69
- const urlStart = match.index + prefixLength;
70
- const urlEnd = urlStart + match[2].length;
71
- const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
72
- if (newUrl !== match[2]) {
73
- replacements.push({ start: urlStart, end: urlEnd, newUrl });
74
- }
75
- }
76
- }
77
-
78
- // Match HTML tags: <img src="..."> and <a href="...">
79
- const htmlTagRegex = /\s(src|href)=["']([^"']+)["']/gi;
80
- while ((match = htmlTagRegex.exec(text)) !== null) {
81
- if (!isInExcludedRange(match.index)) {
82
- const urlStart = match.index + match[0].indexOf(match[2]);
83
- const urlEnd = urlStart + match[2].length;
84
- const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
85
- if (newUrl !== match[2]) {
86
- replacements.push({ start: urlStart, end: urlEnd, newUrl });
87
- }
88
- }
89
- }
90
-
91
- // Sort replacements by start position in descending order
92
- replacements.sort((a, b) => b.start - a.start);
93
-
94
- // Apply replacements from end to start to maintain correct indices
95
- let result = text;
96
- for (const { start, end, newUrl } of replacements) {
97
- result = result.substring(0, start) + newUrl + result.substring(end);
98
- }
99
-
100
- return result;
101
- }
102
-
103
- /**
104
- * 相对路径转换为绝对路径
105
- * 与 src/helpers/convertLink.ts 逻辑一致
106
- *
107
- * @param {String} link 待转换的链接
108
- * @param {String} repoSlug 仓库路径
109
- * @param {String} branchOrSha 分支或SHA,默认为 HEAD
110
- * @returns {String}
111
- */
112
- function normaliseLink(link, repoSlug, branchOrSha = 'HEAD') {
113
- const { CNB_WEB_ENDPOINT } = process.env;
114
- const baseURL = `${CNB_WEB_ENDPOINT}/${repoSlug}`;
115
-
116
- if (link.startsWith('/-/')) {
117
- return `${baseURL}${link}`;
118
- }
119
-
120
- if (
121
- link.indexOf('/-/') === -1 &&
122
- (
123
- link.startsWith('../') ||
124
- link.startsWith('./') ||
125
- (link.startsWith('/') && !link.startsWith('//'))
126
- )
127
- ) {
128
- let chunks = link.split('/');
129
- // 过滤掉空字符串和 . .. 这些无效路径
130
- chunks = chunks.filter((chunk) => !!chunk && chunk !== '.' && chunk !== '..');
131
- if (chunks.length === 0) {
132
- return link;
133
- }
134
- chunks.unshift(branchOrSha);
135
- return `${baseURL}/-/git/raw/${chunks.join('/')}`;
136
- }
137
-
138
- return link;
139
- }
140
-
141
- // =======
142
- // 开始执行
143
- // =======
144
-
145
- const args = process.argv.slice(2);
146
- const text = args[0] ?? '';
147
- const content = convertLink(args[0], process.env.CNB_REPO_SLUG, process.env.CNB_BRANCH);
148
- console.log(content);
package/test.js DELETED
@@ -1 +0,0 @@
1
- console.log(123)