Skip to content

Commit 339ce6f

Browse files
committedJun 18, 2024
Check inFile/inDirectory for existence
1 parent 4bb5337 commit 339ce6f

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed
 

‎index.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,35 @@ try
1616

1717
if(typeof inFile === "string" && inFile !== '')
1818
{
19-
const fileData = fs.readFileSync(inFile, 'utf8');
20-
outputJson = JSON.parse(fileData);
19+
if(fs.existsSync(inFile))
20+
{
21+
const fileData = fs.readFileSync(inFile, 'utf8');
22+
outputJson = JSON.parse(fileData);
23+
}
24+
else
25+
core.error("inDirectory " + inDirectory + " does not exist");
2126
}
2227

2328
if(typeof inDirectory === "string" && inDirectory !== '')
2429
{
25-
fs.readdirSync(inDirectory).forEach(filename => {
26-
if(!filename.endsWith(".json"))
27-
return;
28-
29-
const filenameWithoutExtension = filename.substring(0, filename.length - ".json".length);
30-
if(!outputJson.hasOwnProperty(filenameWithoutExtension))
31-
{
32-
core.error(filenameWithoutExtension + " is already defined (in " + inFile + ")");
33-
return;
34-
}
35-
36-
const fileData = fs.readFileSync(inDirectory + '/' + filename, { encoding: 'utf8', flag: 'r' });
37-
outputJson[filenameWithoutExtension] = JSON.parse(fileData);
38-
});
30+
if(fs.existsSync(inDirectory))
31+
{
32+
fs.readdirSync(inDirectory).forEach(filename => {
33+
if (!filename.endsWith(".json"))
34+
return;
35+
36+
const filenameWithoutExtension = filename.substring(0, filename.length - ".json".length);
37+
if (!outputJson.hasOwnProperty(filenameWithoutExtension)) {
38+
core.error(filenameWithoutExtension + " is already defined (in " + inFile + ")");
39+
return;
40+
}
41+
42+
const fileData = fs.readFileSync(inDirectory + '/' + filename, {encoding: 'utf8', flag: 'r'});
43+
outputJson[filenameWithoutExtension] = JSON.parse(fileData);
44+
});
45+
}
46+
else
47+
core.error("inDirectory " + inDirectory + " does not exist");
3948
}
4049

4150
if(Object.keys(outputJson).length !== 0)

0 commit comments

Comments
 (0)