adminforth 1.5.8-next.3 → 1.5.8-next.5
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 +35 -17
- package/package.json +1 -1
package/commands/utils.js
CHANGED
|
@@ -56,6 +56,37 @@ export const findInstance = (fileContent) => {
|
|
|
56
56
|
return matches[0][2];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
function processAllJsFilesInDir(directory) {
|
|
60
|
+
const files = fs.readdirSync(directory);
|
|
61
|
+
|
|
62
|
+
files.forEach((file) => {
|
|
63
|
+
const filePath = path.join(directory, file);
|
|
64
|
+
|
|
65
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
66
|
+
processAllJsFilesInDir(filePath);
|
|
67
|
+
} else if (file.endsWith(".js")) {
|
|
68
|
+
try {
|
|
69
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
70
|
+
const updatedContent = fileContent.replace(
|
|
71
|
+
/import (.+?) from ["'](.+?)["'];/g,
|
|
72
|
+
(match, imports, modulePath) => {
|
|
73
|
+
if (
|
|
74
|
+
!modulePath.endsWith(".js") &&
|
|
75
|
+
(modulePath.startsWith("./") || modulePath.startsWith("../"))
|
|
76
|
+
) {
|
|
77
|
+
return `import ${imports} from "${modulePath}.js";`;
|
|
78
|
+
}
|
|
79
|
+
return match;
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
fs.writeFileSync(filePath, updatedContent, "utf-8");
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`Error processing file '${filePath}':`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
59
90
|
export async function getInstance(file, currentDirectory) {
|
|
60
91
|
const initialFilePath = path.join(currentDirectory, file);
|
|
61
92
|
let filePath = initialFilePath;
|
|
@@ -73,25 +104,12 @@ export async function getInstance(file, currentDirectory) {
|
|
|
73
104
|
console.log(`Error: Could not compile TypeScript file '${file}'`);
|
|
74
105
|
}
|
|
75
106
|
|
|
107
|
+
const distDir = path.join(currentDirectory, "dist");
|
|
108
|
+
processAllJsFilesInDir(distDir);
|
|
109
|
+
|
|
76
110
|
filePath = filePath
|
|
77
111
|
.replace(".ts", ".js")
|
|
78
|
-
.replace(currentDirectory,
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const compiledContent = fs.readFileSync(filePath, "utf-8");
|
|
82
|
-
const updatedContent = compiledContent.replace(
|
|
83
|
-
/import (.+?) from ["'](.+?)["'];/g,
|
|
84
|
-
(match, imports, modulePath) => {
|
|
85
|
-
if (!modulePath.endsWith(".js") && (modulePath.startsWith("./") || modulePath.startsWith("../"))) {
|
|
86
|
-
return `import ${imports} from "${modulePath}.js";`; // Append .js to local imports
|
|
87
|
-
}
|
|
88
|
-
return match;
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
fs.writeFileSync(filePath, updatedContent, "utf-8");
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error("Error during post-processing:", error);
|
|
94
|
-
}
|
|
112
|
+
.replace(currentDirectory, distDir);
|
|
95
113
|
}
|
|
96
114
|
|
|
97
115
|
const fileContent = fs.readFileSync(initialFilePath, "utf-8");
|