Skip to content

Commit 2b61c91

Browse files
committed
fix: do not run wrangler command in directories
Signed-off-by: Diogenes Fernandes <[email protected]>
1 parent e9c38e6 commit 2b61c91

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

search/worker/scripts/feed-data-r2.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ fs.readdir(directoryPath, { recursive: true }, (err, files) => {
1717
const realFilePath = path.join(directoryPath, fileName);
1818
const r2Name = realFilePath.replace(directoryPath, "");
1919

20-
const cmd = `npx wrangler r2 object put registry-ui-api${r2Name} --file ${realFilePath} --local`
21-
console.log(cmd)
22-
exec(cmd, function (err, stdout, stderr) {
23-
console.log(stdout);
24-
console.error(stderr);
25-
});
20+
fs.lstat(realFilePath, (err, stats) => {
21+
22+
if(err)
23+
return console.log(err); //Handle error
24+
if(stats.isDirectory()) {
25+
return console.log(`directories are not supported by wrangler api: ${realFilePath}`)
26+
}
2627

28+
runCmd(r2Name, realFilePath)
29+
});
2730
});
2831
});
32+
33+
const runCmd = (bucketFileName, path) => {
34+
const cmd = `npx wrangler r2 object put registry-ui-api${bucketFileName} --file ${path} --local`
35+
exec(cmd, function (err, stdout, stderr) {
36+
console.log(stdout);
37+
console.error(stderr);
38+
});
39+
}

0 commit comments

Comments
 (0)