Skip to content

Commit 19459df

Browse files
committed
something
1 parent a1a011e commit 19459df

File tree

179 files changed

+30898
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+30898
-301
lines changed

.gitmodules

Whitespace-only changes.

package-lock.json

Lines changed: 171 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const TARGET_DIR = './src/protos';
5+
6+
// This regex finds lines with relative imports.
7+
// It captures three groups:
8+
// 1. The part before the path (e.g., `from '`)
9+
// 2. The relative path itself (e.g., `./some/file`)
10+
// 3. The closing quote (e.g., `'`)
11+
const IMPORT_REGEX = /(from\s+['"])(\.\.?\/[^'"]+)(['"])/g;
12+
13+
/**
14+
* Recursively walks a directory and applies a file processing function.
15+
* @param {string} directory The directory to walk.
16+
* @param {(filePath: string) => void} processFile The function to apply to each file.
17+
*/
18+
function walkDirectory(directory, processFile) {
19+
const items = fs.readdirSync(directory);
20+
for (const item of items) {
21+
const fullPath = path.join(directory, item);
22+
const stat = fs.statSync(fullPath);
23+
if (stat.isDirectory()) {
24+
walkDirectory(fullPath, processFile);
25+
} else if (fullPath.endsWith('.ts')) {
26+
processFile(fullPath);
27+
}
28+
}
29+
}
30+
31+
/**
32+
* Reads a TypeScript file, adds '.js' extensions to relative imports,
33+
* and writes the changes back to the file.
34+
* @param {string} filePath The path to the TypeScript file.
35+
*/
36+
function addJsExtensions(filePath) {
37+
let content = fs.readFileSync(filePath, 'utf8');
38+
let changesMade = false;
39+
40+
const newContent = content.replace(IMPORT_REGEX, (match, pre, importPath, post) => {
41+
// Check if the path already has an extension.
42+
// path.extname() returns the extension (e.g., '.js') or an empty string.
43+
if (path.extname(importPath)) {
44+
return match; // No change needed
45+
}
46+
47+
changesMade = true;
48+
const newImportPath = `${importPath}.js`;
49+
return `${pre}${newImportPath}${post}`;
50+
});
51+
52+
if (changesMade) {
53+
fs.writeFileSync(filePath, newContent, 'utf8');
54+
}
55+
}
56+
57+
try {
58+
walkDirectory(TARGET_DIR, addJsExtensions);
59+
} catch (error) {
60+
console.error(`Error processing files: ${error.message}`);
61+
process.exit(1);
62+
}

0 commit comments

Comments
 (0)