-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd-js-extensions.js
57 lines (48 loc) · 1.52 KB
/
add-js-extensions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fs from "fs";
import path from "path";
const directories = [
"src/clients/generated/core",
"src/clients/generated/models",
"src/clients/generated/services",
"src/clients/generated",
];
directories.forEach((directory) => {
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
fs.readdir(directory, (err, files) => {
if (err) {
return console.log("Unable to scan directory: " + err);
}
files.forEach((file) => {
const filePath = path.join(directory, file);
if (fs.lstatSync(filePath).isFile() && filePath.endsWith(".ts")) {
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
return console.log("Unable to read file: " + err);
}
const result = data.replace(
/(import .* from '.*)(?<!\.js)';/g,
"$1.js';",
);
fs.writeFile(filePath, result, "utf8", (err) => {
if (err) return console.log("Unable to write file: " + err);
});
});
}
});
});
});
// Explicitly process the generated/index.ts file
const indexPath = "src/clients/generated/index.ts";
if (fs.existsSync(indexPath)) {
fs.readFile(indexPath, "utf8", (err, data) => {
if (err) {
return console.log("Unable to read file: " + err);
}
const result = data.replace(/(import .* from '.*)(?<!\.js)';/g, "$1.js';");
fs.writeFile(indexPath, result, "utf8", (err) => {
if (err) return console.log("Unable to write file: " + err);
});
});
}