File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 1
1
const core = require ( '@actions/core' ) ;
2
2
const github = require ( '@actions/github' ) ;
3
3
const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
4
5
5
6
const inFile = core . getInput ( 'in-file' ) ;
6
7
const inDirectory = core . getInput ( 'in-directory' ) ;
14
15
15
16
let outputJson = JSON . constructor ( ) ;
16
17
18
+ // Multi-object file
17
19
if ( typeof inFile === "string" && inFile !== '' )
18
20
{
19
21
if ( fs . existsSync ( inFile ) )
25
27
core . error ( "inDirectory " + inDirectory + " does not exist" ) ;
26
28
}
27
29
30
+ // Directory of single-object files
28
31
if ( typeof inDirectory === "string" && inDirectory !== '' )
29
32
{
30
33
if ( fs . existsSync ( inDirectory ) )
47
50
core . error ( "inDirectory " + inDirectory + " does not exist" ) ;
48
51
}
49
52
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 )
51
56
{
57
+ fs . mkdirSync ( path . dirname ( outputJson ) , { recursive : true } ) ;
58
+
52
59
fs . writeFileSync (
53
60
outFile ,
54
61
JSON . stringify ( outputJson , null , null ) ,
You can’t perform that action at this time.
0 commit comments