Added merge script
This commit is contained in:
parent
2e3eca72eb
commit
1ef77b3447
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Launch Program",
|
|
||||||
"skipFiles": [
|
|
||||||
"<node_internals>/**"
|
|
||||||
],
|
|
||||||
"program": "${file}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"json.schemas": [
|
"json.schemas": [
|
||||||
{
|
{
|
||||||
"fileMatch": [
|
"fileMatch": [
|
||||||
"*.json"
|
"homebrew/*.json"
|
||||||
],
|
],
|
||||||
"url": "https://raw.githubusercontent.com/TheGiddyLimit/5etools-utils/master/schema/brew-fast/homebrew.json"
|
"url": "https://raw.githubusercontent.com/TheGiddyLimit/5etools-utils/master/schema/brew-fast/homebrew.json"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,99 @@
|
||||||
{
|
{
|
||||||
|
"_meta": {
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"json": "SCGtD",
|
||||||
|
"abbreviation": "SCGtD",
|
||||||
|
"full": "Sebastian Crowe's Guide to Drakkenheim",
|
||||||
|
"version": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dateAdded": 0,
|
||||||
|
"dateLastModified": 0
|
||||||
|
},
|
||||||
|
"class": [
|
||||||
|
{
|
||||||
|
"name": "Apothecary",
|
||||||
|
"source": "SCGtD",
|
||||||
|
"classFeatures": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"hd": {
|
||||||
|
"number": 0,
|
||||||
|
"faces": 0
|
||||||
|
},
|
||||||
|
"proficiency": [
|
||||||
|
"str",
|
||||||
|
"str"
|
||||||
|
],
|
||||||
|
"startingProficiencies": {
|
||||||
|
"armor": [
|
||||||
|
"light"
|
||||||
|
],
|
||||||
|
"weapons": [
|
||||||
|
"simple and martial are rendered as x weapons, but you can write any string that you want."
|
||||||
|
],
|
||||||
|
"tools": [
|
||||||
|
"Name of any tool or artisan tools"
|
||||||
|
],
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"skillName": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"startingEquipment": {
|
||||||
|
"default": [
|
||||||
|
"Each string will appear as a list entry"
|
||||||
|
],
|
||||||
|
"additionalFromBackground": true,
|
||||||
|
"goldAlternative": "{@dice xdy}"
|
||||||
|
},
|
||||||
|
"multiclassing": {
|
||||||
|
"requirements": {
|
||||||
|
"str": 0
|
||||||
|
},
|
||||||
|
"proficienciesGained": {
|
||||||
|
"armor": [
|
||||||
|
"light"
|
||||||
|
],
|
||||||
|
"weapons": [
|
||||||
|
"simple"
|
||||||
|
],
|
||||||
|
"tools": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"acrobatics": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"casterProgression": "full",
|
||||||
|
"spellcastingAbility": "str",
|
||||||
|
"classSpells": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"fluff": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"subclass": [{
|
||||||
|
"name": "Apothecary",
|
||||||
|
"source": "SCGtD",
|
||||||
|
"page": 0,
|
||||||
|
"className": "Apothecary",
|
||||||
|
"classSource": "SCGtD",
|
||||||
|
"shortName": "Apo",
|
||||||
|
"subclassFeatures": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"casterProgression": "full",
|
||||||
|
"spellcastingAbility": "str",
|
||||||
|
"subclassSpells": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
|
|
@ -5,18 +5,11 @@
|
||||||
"json": "SCGtD",
|
"json": "SCGtD",
|
||||||
"abbreviation": "SCGtD",
|
"abbreviation": "SCGtD",
|
||||||
"full": "Sebastian Crowe's Guide to Drakkenheim",
|
"full": "Sebastian Crowe's Guide to Drakkenheim",
|
||||||
"authors": [
|
"version": "0"
|
||||||
"Dungeon Dudes"
|
|
||||||
],
|
|
||||||
"convertedBy": [
|
|
||||||
"Werring"
|
|
||||||
],
|
|
||||||
"version": "1.0",
|
|
||||||
"targetSchema": "1.0.0"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dateAdded": 1700993345,
|
"dateAdded": 0,
|
||||||
"dateLastModified": 1700993345
|
"dateLastModified": 0
|
||||||
},
|
},
|
||||||
"spell": [
|
"spell": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,24 @@
|
||||||
{
|
{
|
||||||
|
"_meta": {
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"json": "SCGtD",
|
||||||
|
"abbreviation": "SCGtD",
|
||||||
|
"full": "Sebastian Crowe's Guide to Drakkenheim",
|
||||||
|
"version": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dateAdded": 0,
|
||||||
|
"dateLastModified": 0
|
||||||
|
},
|
||||||
"subclass": [
|
"subclass": [
|
||||||
{
|
{
|
||||||
"name": "",
|
"name": "Barb",
|
||||||
"source": "",
|
"source": "SCGtD",
|
||||||
"page": 0,
|
"page": 0,
|
||||||
"className": "",
|
"className": "Barbarian",
|
||||||
"classSource": "",
|
"classSource": "PHB",
|
||||||
"shortName": "",
|
"shortName": "Barb",
|
||||||
"subclassFeatures": [
|
"subclassFeatures": [
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"validate": "test-json-brew",
|
"validate": "test-json-brew",
|
||||||
|
"merge": "node scripts/combine.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import { selectProject } from "./lib/select-project.js";
|
||||||
|
import { importSourceFactory } from "./lib/import-source.js";
|
||||||
|
|
||||||
|
|
||||||
|
const PROJECT_DIR = process.env.npm_config_local_prefix;
|
||||||
|
const HOMEBREW_DIR = path.join(PROJECT_DIR, "homebrew");
|
||||||
|
|
||||||
|
const projects = fs.readdirSync(HOMEBREW_DIR, {
|
||||||
|
withFileTypes: true,
|
||||||
|
})
|
||||||
|
.filter((dir) => dir.isDirectory())
|
||||||
|
.map((dir) => dir.name);
|
||||||
|
|
||||||
|
if (projects.length === 0) {
|
||||||
|
console.error("No homebrew projects");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const project = selectProject(projects);
|
||||||
|
const SOURCE_DIR = path.join(HOMEBREW_DIR, project);
|
||||||
|
const importSource = importSourceFactory(SOURCE_DIR);
|
||||||
|
|
||||||
|
const meta = importSource("meta.json");
|
||||||
|
meta._meta.dateLastModified = parseInt(Date.now()/1000);
|
||||||
|
|
||||||
|
const sources = fs.readdirSync(SOURCE_DIR, {
|
||||||
|
withFileTypes: true,
|
||||||
|
})
|
||||||
|
.filter((source) => source.isFile() && source.name.endsWith(".json") && source.name !== "meta.json")
|
||||||
|
.map((source) => source.name);
|
||||||
|
|
||||||
|
|
||||||
|
const homebrew = sources.reduce((result, source) => {
|
||||||
|
const sourceData = importSource(source);
|
||||||
|
delete sourceData._meta;
|
||||||
|
|
||||||
|
Object.entries(sourceData).forEach(([sourceKey, sourceValue]) => {
|
||||||
|
if (!(sourceKey in result)) {
|
||||||
|
|
||||||
|
result[sourceKey] = sourceValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Array.isArray(result[sourceKey])) {
|
||||||
|
result[sourceKey] = result[sourceKey].concat(sourceValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Error(`Could not merge non-array key ${sourceKey}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}, meta);
|
||||||
|
|
||||||
|
|
||||||
|
console.log(homebrew.subclass);
|
||||||
|
|
||||||
|
const outFile = path.join(HOMEBREW_DIR, `${project}.json`);
|
||||||
|
if (fs.existsSync(outFile)) {
|
||||||
|
fs.unlinkSync(outFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(outFile, JSON.stringify(homebrew, null, 4), { encoding: "utf-8"});
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} sourceDir
|
||||||
|
* @returns ({string} filePath ) => Record<string, any>
|
||||||
|
*/
|
||||||
|
export function importSourceFactory(sourceDir) {
|
||||||
|
return (filePath) => JSON.parse(fs.readFileSync(path.join(sourceDir, filePath)).toString("utf-8"));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
/**
|
||||||
|
* @param {string[]} projects
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
export function selectProject(projects) {
|
||||||
|
return projects[0];
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue