Skip to content

Commit 1e81a01

Browse files
committed
Add comments and QoL to JS code
1 parent 7fa428b commit 1e81a01

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const core = require('@actions/core');
22
const github = require('@actions/github');
33
const fs = require('fs');
4+
const path = require('path');
45

56
const inFile = core.getInput('in-file');
67
const inDirectory = core.getInput('in-directory');
@@ -14,6 +15,7 @@ try
1415

1516
let outputJson = JSON.constructor();
1617

18+
// Multi-object file
1719
if(typeof inFile === "string" && inFile !== '')
1820
{
1921
if(fs.existsSync(inFile))
@@ -25,6 +27,7 @@ try
2527
core.error("inDirectory " + inDirectory + " does not exist");
2628
}
2729

30+
// Directory of single-object files
2831
if(typeof inDirectory === "string" && inDirectory !== '')
2932
{
3033
if(fs.existsSync(inDirectory))
@@ -47,8 +50,12 @@ try
4750
core.error("inDirectory " + inDirectory + " does not exist");
4851
}
4952

50-
if(Object.keys(outputJson).length !== 0)
53+
// Output file
54+
// Override existing file, create new only if we have data to write
55+
if(!fs.existsSync(outputJson) || Object.keys(outputJson).length !== 0)
5156
{
57+
fs.mkdirSync(path.dirname(outputJson), { recursive: true });
58+
5259
fs.writeFileSync(
5360
outFile,
5461
JSON.stringify(outputJson, null, null),

0 commit comments

Comments
 (0)