Skip to content

Commit dec2d3c

Browse files
committed
Init
0 parents  commit dec2d3c

File tree

593 files changed

+433484
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

593 files changed

+433484
-0
lines changed

.github/workflows/main.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
on: [push]
2+
3+
jobs:
4+
plugin_json:
5+
runs-on: ubuntu-latest
6+
name: Test merging some JSON files
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v4
10+
11+
- name: Test
12+
uses: ./
13+
with:
14+
in-file: test/file.json
15+
in-directory: test/file
16+
out-file: output.json
17+
18+
- name: Print output
19+
shell: bash
20+
run: |
21+
wc -c < output.json
22+
cat output.json
23+
echo
24+
25+
- name: Upload artifact
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: output
29+
path: output.json

action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Voxelite JSON Merger'
2+
description: 'Merge JSON and separate JSONs into a single file, works for blocks, items...'
3+
inputs:
4+
in-file:
5+
description: 'Main file to use as a source'
6+
in-directory:
7+
description: 'Directory from which to process separate JSON files'
8+
out-file:
9+
description: 'Merged JSON file'
10+
required: true
11+
runs:
12+
using: 'node20'
13+
main: 'index.js'

index.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
const fs = require('fs');
4+
5+
const inFile = core.getInput('in-file');
6+
const inDirectory = core.getInput('in-directory');
7+
const outFile = core.getInput('out-file');
8+
9+
try
10+
{
11+
core.info("inFile: " + inFile);
12+
core.info("inDirectory: " + inDirectory);
13+
core.info("outFile: " + outFile);
14+
15+
let outputJson = JSON.constructor();
16+
17+
if(inFile !== undefined)
18+
{
19+
const fileData = fs.readFileSync(inFile, 'utf8');
20+
outputJson = JSON.parse(fileData);
21+
}
22+
23+
if(inDirectory !== undefined)
24+
{
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[filenameWithoutExtension] !== undefined)
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+
});
39+
}
40+
41+
{
42+
fs.writeFileSync(
43+
outFile,
44+
JSON.stringify(outputJson, null, null),
45+
{ encoding: 'utf8', flag: 'w' }
46+
);
47+
}
48+
49+
}
50+
catch(error)
51+
{
52+
core.setFailed(error.message);
53+
}

node_modules/.bin/uuid

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

+244
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/LICENSE.md

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)