Skip to content

Commit

Permalink
Change to NPM scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
elmuerte committed Feb 13, 2024
1 parent 0874dd1 commit bd7dd2a
Show file tree
Hide file tree
Showing 12 changed files with 3,323 additions and 51 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.{yaml,yml}]
indent_style = space
indent_size = 2
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate JSON
run: bin/validate-json.sh lba1/*.json lba2/*.json
- name: Merge JSON
run: bin/merge.sh lba1 lba2
- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "npm"
- run: npm ci
- run: npm run validate
- run: npm run build
8 changes: 6 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate JSON
run: bin/validate-json.sh lba1/*.json lba2/*.json
- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "npm"
- run: npm ci
- run: npm run verify
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
lba1.json
lba2.json
dist/
node_modules/

2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist

15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ The text is stored in separate JSON files.

# Development

The `jq` utility is used for a lot of parts in the development process.
Development makes use of NodeJS.

## Building

The quotes are stored in separate JSON files for each game, based on the TEXT
resource file entry.
Various NPM scripts are defined:

These sperate files can be bundled into a single JSON file with the
`bin/merge.sh` shell script.
- clean -- remove generated content
- validate -- validate input files
- build -- build the result
- test -- test the results

```
bin/merge.sh lba1 lba2
```
The start command will execute: validate, build, test
18 changes: 18 additions & 0 deletions bin/merge-json.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import path from "node:path";
import fs from "node:fs/promises";
import glob from "glob-promise";
import jq from "node-jq";

async function merge_json(filePattern, destination) {
await fs.mkdir(path.dirname(destination), { recursive: true });
let files = await glob(filePattern);
let merged = await jq.run("[ .[] | .[] ]", files, {
output: "string",
slurp: true,
});
await fs.writeFile(destination, merged);
console.log(`Merged ${filePattern} into ${destination}`);
}

await merge_json("lba1/*.json", "dist/lba1.json");
await merge_json("lba2/*.json", "dist/lba2.json");
16 changes: 0 additions & 16 deletions bin/merge.sh

This file was deleted.

28 changes: 28 additions & 0 deletions bin/validate-json.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import glob from "glob-promise";
import jq from "node-jq";

async function validate_json(filePattern) {
let files = await glob(filePattern);
let allValid = true;
for (let file of files) {
try {
await jq.run(".", file);
} catch (e) {
console.error('Invalid JSON file "%s": %s', file, e.message);
allValid = false;
}
}
return allValid;
}

let allValid = true;
for (let i = 0; i < process.argv.length; i++) {
allValid &= await validate_json(process.argv[i]);
}

if (!allValid) {
console.info("❌ JSON validation FAILED");
process.exit(1);
} else {
console.info("✅ JSON validation passed");
}
19 changes: 0 additions & 19 deletions bin/validate-json.sh

This file was deleted.

Loading

0 comments on commit bd7dd2a

Please sign in to comment.