Skip to content

Commit 40f4c4d

Browse files
nullvariantclaude
andauthored
chore: fix SonarCloud quality issues and bump version to 0.12.0 (#153)
- Refactor generate-root-readme.js: - Replace 6 similar transform functions with data-driven approach - Use node:fs and node:path prefixes - Use replaceAll() instead of replace() with /g flag - Apply Prettier formatting - Bump version from 0.11.3 to 0.12.0 🖥️ IDE: [Cursor](https://cursor.sh) 🔌 Extension: [Claude Code](https://claude.ai/download) Model-Raw: claude-opus-4-5-20251101 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0befe83 commit 40f4c4d

2 files changed

Lines changed: 66 additions & 88 deletions

File tree

extensions/git-id-switcher/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "git-id-switcher",
33
"displayName": "%extension.displayName%",
44
"description": "%extension.description%",
5-
"version": "0.11.3",
5+
"version": "0.12.0",
66
"publisher": "nullvariant",
77
"icon": "images/icon.png",
88
"engines": {

extensions/git-id-switcher/scripts/generate-root-readme.js

Lines changed: 65 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
* Usage: node scripts/generate-root-readme.js
1010
*/
1111

12-
const fs = require('fs');
13-
const path = require('path');
14-
15-
const GITHUB_BASE = 'https://github.com/nullvariant/nullvariant-vscode-extensions/blob/main';
16-
const EXTENSION_PATH = 'extensions/git-id-switcher';
17-
18-
const SOURCE_PATH = path.join(__dirname, '..', 'docs', 'i18n', 'en', 'README.md');
19-
const OUTPUT_PATH = path.join(__dirname, '..', 'README.md');
12+
const fs = require("node:fs");
13+
const path = require("node:path");
14+
15+
const GITHUB_BASE =
16+
"https://github.com/nullvariant/nullvariant-vscode-extensions/blob/main";
17+
const EXTENSION_PATH = "extensions/git-id-switcher";
18+
19+
const SOURCE_PATH = path.join(
20+
__dirname,
21+
"..",
22+
"docs",
23+
"i18n",
24+
"en",
25+
"README.md",
26+
);
27+
const OUTPUT_PATH = path.join(__dirname, "..", "README.md");
2028

2129
const AUTO_GENERATED_HEADER = `<!-- 🚨 AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY 🚨
2230
Source: docs/i18n/en/README.md
@@ -25,100 +33,70 @@ const AUTO_GENERATED_HEADER = `<!-- 🚨 AUTO-GENERATED FILE - DO NOT EDIT DIREC
2533
`;
2634

2735
/**
28-
* Transform relative language links to absolute GitHub URLs
29-
* ../ja/README.md -> https://github.com/.../docs/i18n/ja/README.md
30-
*/
31-
function transformLanguageLinks(content) {
32-
// Match href="../XX/README.md" or href="../XX-YY/README.md"
33-
return content.replace(
34-
/href="\.\.\/([a-zA-Z-]+)\/README\.md"/g,
35-
`href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/i18n/$1/README.md"`
36-
);
37-
}
38-
39-
/**
40-
* Transform LANGUAGES.md link to absolute GitHub URL
41-
* ../../LANGUAGES.md -> https://github.com/.../docs/LANGUAGES.md
42-
*/
43-
function transformLanguagesLink(content) {
44-
return content.replace(
45-
/href="\.\.\/\.\.\/LANGUAGES\.md"/g,
46-
`href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/LANGUAGES.md"`
47-
);
48-
}
49-
50-
/**
51-
* Remove -en suffix from image filenames
52-
* demo-en.png -> demo.png
53-
* quickpick-en.png -> quickpick.png
54-
*/
55-
function removeEnSuffixFromImages(content) {
56-
return content.replace(/-en\.png/g, '.png');
57-
}
58-
59-
/**
60-
* Transform CONTRIBUTING.md link to absolute GitHub URL
61-
* ../../CONTRIBUTING.md -> https://github.com/.../CONTRIBUTING.md
36+
* All link transformations to apply.
37+
* Each transformation has a pattern (regex) and replacement (string or function).
6238
*/
63-
function transformContributingLink(content) {
64-
return content.replace(
65-
/\[CONTRIBUTING\.md\]\([^)]+\)/g,
66-
`[CONTRIBUTING.md](${GITHUB_BASE}/CONTRIBUTING.md)`
67-
);
68-
}
39+
const TRANSFORMATIONS = [
40+
// Transform relative language links: ../ja/README.md -> absolute GitHub URL
41+
{
42+
pattern: /href="\.\.\/([a-zA-Z-]+)\/README\.md"/g,
43+
replacement: `href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/i18n/$1/README.md"`,
44+
},
45+
// Transform LANGUAGES.md link: ../../LANGUAGES.md -> absolute GitHub URL
46+
{
47+
pattern: /href="\.\.\/\.\.\/LANGUAGES\.md"/g,
48+
replacement: `href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/LANGUAGES.md"`,
49+
},
50+
// Remove -en suffix from image filenames: demo-en.png -> demo.png
51+
{
52+
pattern: /-en\.png/g,
53+
replacement: ".png",
54+
},
55+
// Transform CONTRIBUTING.md markdown link to absolute GitHub URL
56+
{
57+
pattern: /\[CONTRIBUTING\.md\]\([^)]+\)/g,
58+
replacement: `[CONTRIBUTING.md](${GITHUB_BASE}/CONTRIBUTING.md)`,
59+
},
60+
// Transform LICENSE markdown link to absolute GitHub URL
61+
{
62+
pattern: /\[LICENSE\]\([^)]+\)/g,
63+
replacement: `[LICENSE](${GITHUB_BASE}/LICENSE)`,
64+
},
65+
// Transform DESIGN_PHILOSOPHY.md markdown-style link to absolute GitHub URL
66+
{
67+
pattern: /\(\.\.\/\.\.\/DESIGN_PHILOSOPHY\.md\)/g,
68+
replacement: `(${GITHUB_BASE}/${EXTENSION_PATH}/docs/DESIGN_PHILOSOPHY.md)`,
69+
},
70+
// Transform DESIGN_PHILOSOPHY.md HTML href to absolute GitHub URL
71+
{
72+
pattern: /href="\.\.\/\.\.\/DESIGN_PHILOSOPHY\.md"/g,
73+
replacement: `href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/DESIGN_PHILOSOPHY.md"`,
74+
},
75+
];
6976

7077
/**
71-
* Transform LICENSE link to absolute GitHub URL
72-
* ../../../../../LICENSE -> https://github.com/.../LICENSE
78+
* Apply all transformations to content
79+
* @param {string} content - The content to transform
80+
* @returns {string} - The transformed content
7381
*/
74-
function transformLicenseLink(content) {
75-
return content.replace(
76-
/\[LICENSE\]\([^)]+\)/g,
77-
`[LICENSE](${GITHUB_BASE}/LICENSE)`
82+
function applyTransformations(content) {
83+
return TRANSFORMATIONS.reduce(
84+
(text, { pattern, replacement }) => text.replaceAll(pattern, replacement),
85+
content,
7886
);
7987
}
8088

81-
/**
82-
* Transform DESIGN_PHILOSOPHY.md link to absolute GitHub URL
83-
* ../../DESIGN_PHILOSOPHY.md -> https://github.com/.../docs/DESIGN_PHILOSOPHY.md
84-
* Handles both markdown links (...) and HTML href="..."
85-
*/
86-
function transformDesignPhilosophyLink(content) {
87-
// Transform markdown-style links to absolute GitHub URL
88-
content = content.replace(
89-
/\(\.\.\/\.\.\/DESIGN_PHILOSOPHY\.md\)/g,
90-
`(${GITHUB_BASE}/${EXTENSION_PATH}/docs/DESIGN_PHILOSOPHY.md)`
91-
);
92-
// Transform HTML href attributes to absolute GitHub URL
93-
content = content.replace(
94-
/href="\.\.\/\.\.\/DESIGN_PHILOSOPHY\.md"/g,
95-
`href="${GITHUB_BASE}/${EXTENSION_PATH}/docs/DESIGN_PHILOSOPHY.md"`
96-
);
97-
return content;
98-
}
99-
10089
function main() {
101-
// Read source file
10290
if (!fs.existsSync(SOURCE_PATH)) {
10391
console.error(`Error: Source file not found: ${SOURCE_PATH}`);
10492
process.exit(1);
10593
}
10694

107-
let content = fs.readFileSync(SOURCE_PATH, 'utf-8');
108-
109-
// Apply transformations
110-
content = transformLanguageLinks(content);
111-
content = transformLanguagesLink(content);
112-
content = removeEnSuffixFromImages(content);
113-
content = transformContributingLink(content);
114-
content = transformLicenseLink(content);
115-
content = transformDesignPhilosophyLink(content);
116-
117-
// Add auto-generated header
95+
let content = fs.readFileSync(SOURCE_PATH, "utf-8");
96+
content = applyTransformations(content);
11897
content = AUTO_GENERATED_HEADER + content;
11998

120-
// Write output file
121-
fs.writeFileSync(OUTPUT_PATH, content, 'utf-8');
99+
fs.writeFileSync(OUTPUT_PATH, content, "utf-8");
122100

123101
console.log(`✅ Generated ${OUTPUT_PATH}`);
124102
console.log(` Source: ${SOURCE_PATH}`);

0 commit comments

Comments
 (0)