Skip to content

Commit

Permalink
feat: From now on each release of PF2e Workbench will include the lat…
Browse files Browse the repository at this point in the history
…est versions of all V9-compatible macros from https://gitlab.com/symonsch/my-foundryvtt-macros/-/tree/main/PF2e

They can be found in the asymonous-benefactor-macros pack, with the express permission of said asymonous^H^H^H^H^H^H^H^H^Hanonymous (and colorless) benefactor.
Attribution for the macros can normally be found inside each macro, and the source url for each macro is added at the end of the file.
  • Loading branch information
xdy committed Jan 26, 2022
1 parent 27be86b commit 8c735fe
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 11,876 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
needs: [ test ]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0
with:
submodules: 'true'

Expand All @@ -63,6 +63,9 @@ jobs:
- name: Install
run: npm install

- name: Build packs
run: npm run build:packs

- name: Build
run: npm run build

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/my-foundryvtt-macros"]
path = submodules/my-foundryvtt-macros
url = https://gitlab.com/symonsch/my-foundryvtt-macros.git
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ Asset licenses:
are provided under
the [Creative Commons Attribution 3.0 Unported (CC BY 3.0) license](https://creativecommons.org/licenses/by/3.0/) and
were made by numerous authors. The full list of those can be found at: https://game-icons.net/about.html#authors

build-packs license:

* The build-packs.ts script has been dreadfully hacked from https://github.com/CarlosFdez/pf2e-persistent-damage/blob/master/build-packs.ts and is, like the original, provided under the [ISC license](https://www.isc.org/licenses/)

asymonous-benefactor-macros:

* The macros found in the asymonous-benefactor-macros pack are, with the express permission of said asymonous^H^H^H^H^H^H^H^H^Hanonymous benefactor, collected from https://gitlab.com/symonsch/my-foundryvtt-macros/-/tree/main/PF2e at build time. Attribution for the macros can normally be found inside each macro, and the source url for each macro is added at the end of the file.
11 changes: 10 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@
"scripts": [],
"esmodules": ["xdy-pf2e-workbench.bundle.js"],
"styles": ["styles/xdy-pf2e-workbench.css"],
"packs": [],
"packs": [
{
"name": "asymonous-benefactor-macros",
"label": "asymonous-benefactor-macros",
"system": "pf2e",
"path": "packs/asymonous-benefactor-macros.db",
"module": "xdy-pf2e-workbench",
"entity": "Macro"
}
],
"dependencies": [],
"languages": [
{
Expand Down
12,022 changes: 151 additions & 11,871 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"build:dev": "npm run && webpack",
"lint": "eslint ./src --ext .ts",
"lint:fix": "eslint ./src --ext .ts --fix",
"docs": "typedoc"
"docs": "typedoc",
"build:packs": "ts-node -r tsconfig-paths/register src/build-packs.ts"
},
"devDependencies": {
"@league-of-foundry-developers/foundry-vtt-types": "^9.242.0",
Expand Down
81 changes: 81 additions & 0 deletions src/build-packs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//This script has been dreadfully hacked from the original at https://github.com/CarlosFdez/pf2e-persistent-damage/blob/master/build-packs.ts and is, like the original, provided under the [ISC license](https://www.isc.org/licenses/)

import fs from "fs-extra";
import path from "path";

const asymonousSource = [
"./submodules/my-foundryvtt-macros/PF2e",
"./submodules/my-foundryvtt-macros/PF2e/Contributions by others",
];
const packsSource = "packs";
const workSource = "packs";

const pf2eSystemPath = (() => {
const configPath = path.resolve(process.cwd(), "foundryconfig.json");
const configData = fs.existsSync(configPath) ? fs.readJSONSync(configPath) : undefined;
return configData !== undefined ? path.join(configData.dataPath, "Data", "modules", configData.moduleName) : null;
})();
const outDir = pf2eSystemPath ?? path.join(".");

fs.mkdirsSync(path.resolve(outDir, "packs"));

function randomID() {
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
return Array.from(Array(16).keys())
.map(() => letters[Math.floor(Math.random() * letters.length)])
.join("");
}

function copyFolder(source: string, target: string) {
fs.readdirSync(source)
.filter((file) => file.endsWith(".js"))
.forEach((file) => {
const sourcePath = decodeURIComponent(path.join(source, file));
const targetPath = decodeURIComponent(path.join(target, file));
fs.copyFileSync(sourcePath, targetPath);
//Log last part of path
console.log(`Copied ${path.basename(targetPath)}`);
// eslint-disable-next-line
fs.appendFileSync(targetPath, `\n//# source https://gitlab.com/symonsch/my-foundryvtt-macros/-/tree/main/${path.basename(path.dirname(sourcePath))}/${file}`);
});
}

fs.mkdirsSync(outDir + "/" + workSource + "/" + "asymonous-benefactor-macros");
copyFolder(path.resolve(".", asymonousSource[0]), path.resolve(outDir, packsSource + "/asymonous-benefactor-macros"));
copyFolder(path.resolve(".", asymonousSource[1]), path.resolve(outDir, packsSource + "/asymonous-benefactor-macros"));

function getFolders(dir: string) {
const results = [];
const folders = fs.readdirSync(workSource);
for (const folder of folders) {
if (fs.statSync(path.join(dir, folder)).isDirectory()) {
results.push(folder);
}
}

return results;
}

const folders = getFolders(packsSource);
const lines: string[] = [];
for (const folder of folders) {
const folderPath = path.join(packsSource, folder);
const files = fs.readdirSync(folderPath);
for (const file of files) {
const filePath = path.join(folderPath, file);
if (!filePath.endsWith(".js")) {
continue;
}
try {
const contents = fs.readFileSync(filePath, { encoding: "utf8" });
// eslint-disable-next-line
const json = `{"_id": "${randomID()}", "actorIds": [], "author": "${randomID()}", "command": ${JSON.stringify(contents)},"flags": {},"img":"icons/svg/dice-target.svg","name": "${path.parse(file).name}","permission": {"default": 1},"scope": "global","type": "script"}`;
lines.push(json);
} catch (err) {
console.error(`Failed to read JSON file ${filePath}`, err);
}
}
const result = lines.join("\n");
const file1 = path.resolve(outDir, "packs", folder + ".db");
fs.writeFileSync(file1, result, "utf8");
}
1 change: 1 addition & 0 deletions submodules/my-foundryvtt-macros
Submodule my-foundryvtt-macros added at ad45a4
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"target": "ES2021",
"lib": ["DOM", "ES2021"],
"types": ["@league-of-foundry-developers/foundry-vtt-types", "src/types", "handlebars"],
"esModuleInterop": true,
"moduleResolution": "node",
Expand Down
1 change: 1 addition & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const config: Configuration = {
new copyWebpackPlugin({
patterns: [
{ from: "module.json" },
{ from: "packs/*" },
{
from: "static/",
transform(content: Buffer, absoluteFrom: string) {
Expand Down

0 comments on commit 8c735fe

Please sign in to comment.