adminforth 1.11.5-next.10 → 1.11.5-next.12
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.
- package/commands/utils.js +22 -8
- package/package.json +1 -1
package/commands/utils.js
CHANGED
|
@@ -56,18 +56,20 @@ export const findInstance = (fileContent) => {
|
|
|
56
56
|
return matches[0][2];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
function
|
|
59
|
+
function processJsFilesInDir(directory) {
|
|
60
60
|
const files = fs.readdirSync(directory);
|
|
61
61
|
|
|
62
62
|
files.forEach((file) => {
|
|
63
63
|
const filePath = path.join(directory, file);
|
|
64
64
|
|
|
65
65
|
if (fs.statSync(filePath).isDirectory()) {
|
|
66
|
-
|
|
66
|
+
processJsFilesInDir(filePath);
|
|
67
67
|
} else if (file.endsWith(".js")) {
|
|
68
68
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
let fileContent = fs.readFileSync(filePath, "utf-8");
|
|
70
|
+
|
|
71
|
+
// Add .js to relative imports if missing
|
|
72
|
+
fileContent = fileContent.replace(
|
|
71
73
|
/import (.+?) from ["'](.+?)["'];/g,
|
|
72
74
|
(match, imports, modulePath) => {
|
|
73
75
|
if (
|
|
@@ -79,7 +81,20 @@ function processAllJsFilesInDir(directory) {
|
|
|
79
81
|
return match;
|
|
80
82
|
}
|
|
81
83
|
);
|
|
82
|
-
|
|
84
|
+
|
|
85
|
+
// Remove /index.js from imports only if it's not a relative path
|
|
86
|
+
fileContent = fileContent.replace(
|
|
87
|
+
/import (.+?) from ["'](.+?)\/index\.js["'];/g,
|
|
88
|
+
(match, imports, modulePath) => {
|
|
89
|
+
// Check if the path is not relative (doesn't start with ./ or ../)
|
|
90
|
+
if (!modulePath.startsWith("./") && !modulePath.startsWith("../")) {
|
|
91
|
+
return `import ${imports} from "${modulePath}";`;
|
|
92
|
+
}
|
|
93
|
+
return match;
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
fs.writeFileSync(filePath, fileContent, "utf-8");
|
|
83
98
|
} catch (error) {
|
|
84
99
|
console.error(`Error processing file '${filePath}':`, error);
|
|
85
100
|
}
|
|
@@ -101,11 +116,10 @@ export async function getInstance(file, currentDirectory) {
|
|
|
101
116
|
}
|
|
102
117
|
);
|
|
103
118
|
} catch (error) {
|
|
104
|
-
console.log(`Error: Could not compile TypeScript file '${file}'`);
|
|
119
|
+
//console.log(`Error: Could not compile TypeScript file '${file}'`);
|
|
105
120
|
}
|
|
106
|
-
|
|
107
121
|
const distDir = path.join(currentDirectory, "dist");
|
|
108
|
-
|
|
122
|
+
processJsFilesInDir(distDir);
|
|
109
123
|
|
|
110
124
|
filePath = filePath
|
|
111
125
|
.replace(".ts", ".js")
|