Skip to content

Commit 2dd8f81

Browse files
committed
Improve bundler
1 parent f4d8fd8 commit 2dd8f81

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

nodejs-wrapper-source/bundler.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@ const inputDirectoryPath = pathDirName(fileURLToPath(import.meta.url));
77
const packageFileName = "package.json"
88
const scriptFileName = "main.js";
99
const outputDirectoryPath = pathJoin(inputDirectoryPath, "../hugoalh.GitHubActionsToolkit/module/nodejs-wrapper");
10-
async function getDirectoryItem(directoryPath) {
10+
async function getDirectoryItem(directoryPath, relativeBasePath) {
11+
if (typeof relativeBasePath === "undefined") {
12+
relativeBasePath = directoryPath;
13+
}
1114
try {
12-
return await fsReadDir(directoryPath, { withFileTypes: true });
13-
} catch {
15+
let result = [];
16+
for (let item of await fsReadDir(directoryPath, { withFileTypes: true })) {
17+
if (item.isDirectory()) {
18+
result.push(...await getDirectoryItem(pathJoin(directoryPath, item.name), relativeBasePath));
19+
} else {
20+
result.push(pathJoin(directoryPath, item.name).slice(relativeBasePath.length + 1).replace(/\\/gu, "/"));
21+
}
22+
}
23+
return result;
24+
} catch (error) {
1425
return [];
1526
}
1627
}
1728

1829
/* Clean up or initialize output directory (need to await in order to prevent race conditions). */
1930
if (fsExistsSync(outputDirectoryPath)) {
20-
for (const outputFile of await getDirectoryItem(outputDirectoryPath)) {
21-
await fsRemove(pathJoin(outputDirectoryPath, outputFile.name), { recursive: true });
31+
for (let fileName of await getDirectoryItem(outputDirectoryPath)) {
32+
await fsRemove(pathJoin(outputDirectoryPath, fileName), { recursive: true });
2233
}
2334
} else {
2435
await fsMKDir(outputDirectoryPath, { recursive: true });

0 commit comments

Comments
 (0)