Skip to content

Commit

Permalink
test of pack-on-release
Browse files Browse the repository at this point in the history
  • Loading branch information
esheyw committed Feb 2, 2024
1 parent 34e13c6 commit 68fa136
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 57 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ jobs:
steps:
# Checkout
- uses: actions/checkout@v2
# build sass
# install deps
- run: npm ci
# build sass
- run: npm run sass
# pack packs
- run: npm run pack

# Substitute the Manifest and Download URLs in the module.json
- name: Substitute Manifest and Download Links For Versioned Ones
Expand All @@ -27,7 +30,7 @@ jobs:
download: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.zip

# Create a zip file with all files required by the module to add to the release
- run: zip -r ./module.zip module.json LICENSE styles/*.css styles/*.map scripts/ templates/ lang/
- run: zip -r ./module.zip module.json LICENSE styles/*.css styles/*.map scripts/ templates/ lang/ packs/

# Create a release for this specific version
- name: Update Release with Files
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ styles/*.map
.vscode/
foundry.js
commons.js
packs/
packs/**
node_modules
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
- brushup the group initiative skills dialog macro
- double check CSS on various themes/no-dorako
- npm package setup, run link dev
- or just a standalone script
- or just a standalone script
- move validator wavy underline from inline style to sass
14 changes: 14 additions & 0 deletions build/pack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { compilePack } from "@foundryvtt/foundryvtt-cli";
import { promises as fs } from "fs";

const MODULE_ID = process.cwd();

const packs = await fs.readdir("./unpacks");
for (const pack of packs) {
if (pack === ".gitattributes") continue;
console.log("Packing " + pack);
await compilePack(
`${MODULE_ID}/unpacks/${pack}`,
`${MODULE_ID}/packs/${pack}`
);
}
24 changes: 24 additions & 0 deletions build/unpack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { extractPack } from "@foundryvtt/foundryvtt-cli";
import { promises as fs } from "fs";
import path from "path";

const MODULE_ID = process.cwd();

const packs = await fs.readdir("./packs");
for (const pack of packs) {
if (pack === ".gitattributes") continue;
console.log("Unpacking " + pack);
const directory = `./unpacks/${pack}`;
try {
for (const file of await fs.readdir(directory)) {
await fs.unlink(path.join(directory, file));
}
} catch (error) {
if (error.code === "ENOENT") console.log("No files inside of " + pack);
else console.log(error);
}
await extractPack(
`${MODULE_ID}/packs/${pack}`,
`${MODULE_ID}/unpacks/${pack}`
);
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "PF2e Macro & Helper Library",
"main": "scripts/init.mjs",
"scripts": {
"sass": "sass styles/main.scss styles/main.css"
"sass": "sass styles/main.scss styles/main.css",
"unpack": "node build/unpack.mjs",
"pack": "node build/pack.mjs"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion scripts/classes/MHLDialog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { localize } from "../helpers/stringHelpers.mjs";
const PREFIX = "MHL.Dialog";
export class MHLDialog extends Dialog {
constructor(data, options = {}) {
//validate the validator. TODO: add facility for list of non-empty inputs instead of function
//validate the validator.
if ("validator" in data) {
let validator = data.validator;
switch (typeof validator) {
Expand Down
12 changes: 11 additions & 1 deletion scripts/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MODULE = "pf2e-macro-helper-library";
export const MODULE_ID = "pf2e-macro-helper-library";
export const PHYSICAL_ITEM_TYPES = [
"armor",
"backpack",
Expand All @@ -16,3 +16,13 @@ export const COLOURS = {
error: "var(--color-level-error, red)",
};
export const LABELABLE_TAGS = ["button", "input", "meter", "output", "progress", "select", "textarea"];
export const SETTINGS = {
"notify-on-error": {
config: true,
default: true,
hint: "MHL.Settings.NotifyOnError.Hint",
name: "MHL.Settings.NotifyOnError.Name",
scope: "client",
type: Boolean,
},
};
30 changes: 3 additions & 27 deletions scripts/helpers/errorHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,19 @@ export function localizedBanner(
}

export function MHLError(str, data = {}, { notify = null, prefix = "MHL | ", log = {}, func = null } = {}) {
if (func && typeof func === "string") prefix += `${func} |`;
if (func && typeof func === "string") prefix += `${func} | `;
return localizedError(str, data, { notify, prefix, log });
}

// taken from https://stackoverflow.com/a/32728075, slightly modernized
/**
* Checks if value is empty. Deep-checks arrays and objects
* Note: isEmpty([]) == true, isEmpty({}) == true, isEmpty([{0:false},"",0]) == true, isEmpty({0:1}) == false
* @param value
* @returns {boolean}
*/
export function isEmpty(value) {
const isEmptyObject = (a) => {
if (!Array.isArray(a)) {
// it's an Object, not an Array
const hasNonempty = Object.keys(a).some((e) => !isEmpty(a[e]));
return hasNonempty ? false : isEmptyObject(Object.keys(a));
}
return !a.some((e) => !isEmpty(e));
};
return (
value == false ||
typeof value === "undefined" ||
value == null ||
(typeof value === "object" && isEmptyObject(value))
);
}

export function log(loggable, type = null, prefix = null) {
type ??= "debug";
if (!CONSOLE_TYPES.includes(type)) {
throw MHLError(`MHL.Error.LogTypes`, { types: BANNER_TYPES.join(", ") }, { func: "log: ", log: { type } });
throw MHLError(`MHL.Error.LogTypes`, { types: BANNER_TYPES.join(", ") }, { func: "log", log: { type } });
}
prefix ??= "";
return console[type](prefix, loggable);
}

export function mhlog(loggable, type = null, prefix = "MHL |") {
export function mhlog(loggable, type = null, prefix = "MHL | ") {
return log(loggable, type, prefix);
}
17 changes: 12 additions & 5 deletions scripts/init.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as helpers from "./helpers/index.mjs";
import * as macros from "./macros/index.mjs";
import * as classes from './classes/index.mjs';
import { registerSettings } from "./settings.mjs";
import * as classes from "./classes/index.mjs";
import { registerSettings, updateSettingsCache } from "./settings.mjs";
import { MODULE_ID } from "./constants.mjs";
export const MODULE = ()=> game.modules.get(MODULE_ID)
Hooks.on("init", () => {
game.pf2emhl = {
macros,
Expand All @@ -15,11 +17,16 @@ Hooks.on("init", () => {
if (game.modules.get("esheyw-transfer")?.active) {
globalThis.mh = game.pf2emhl;
}
game.pf2emhl.settings = {};
registerSettings();

Handlebars.registerHelper("mhlocalize", (value, options) => {
if ( value instanceof Handlebars.SafeString ) value = value.toString();
if (value instanceof Handlebars.SafeString) value = value.toString();
const data = options.hash;
return helpers.localize(value,data)
return helpers.localize(value, data);
});
});
});

Hooks.once("setup", () => {
updateSettingsCache();
});
2 changes: 1 addition & 1 deletion scripts/macros/lashingCurrents.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pickItemFromActor } from "../helpers/pf2eHelpers.mjs";
import { MHLError, localizedBanner } from "../helpers/errorHelpers.mjs";
const PREFIX = "MHL.Macro.LashingCurrents";
export async function lashingCurrents() {
const func = "lashingCurrents: ";
const func = "lashingCurrents";
const token = oneTokenOnly();
const actor = token.actor;
const FORBIDDEN_RUNES = ["bloodbane", "kinWarding"];
Expand Down
6 changes: 3 additions & 3 deletions scripts/macros/updateInitiativeStatistics.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { anyTokens } from "../helpers/tokenHelpers.mjs";
import { MHLDialog } from "../classes/MHLDialog.mjs";
import { MODULE, fu } from "../constants.mjs";
import { MHLError, mhlog } from "../helpers/errorHelpers.mjs";
import { MODULE_ID, fu } from "../constants.mjs";
import { MHLError } from "../helpers/errorHelpers.mjs";
import { localize } from "../helpers/stringHelpers.mjs";

export async function updateInitiativeStatistics() {
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function updateInitiativeStatistics() {
const dialogData = {
contentData,
title: `Set Initiative Statistics`,
content: `modules/${MODULE}/templates/updateInitiativeStatistics.hbs`,
content: `modules/${MODULE_ID}/templates/updateInitiativeStatistics.hbs`,
buttons: {
yes: {
icon: "<i class='fas fa-check'></i>",
Expand Down
38 changes: 24 additions & 14 deletions scripts/settings.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { MODULE } from "./constants.mjs";
import { localize } from "./helpers/stringHelpers.mjs";
import { MODULE_ID, SETTINGS, fu } from "./constants.mjs";

export function registerSettings() {
game.settings.register(MODULE, "notify-on-error", {
config: true,
default: true,
hint: localize("MHL.Settings.NotifyOnError.Hint"),
name: localize("MHL.Settings.NotifyOnError.Name"),
scope: "client",
type: Boolean,
});
for (const [setting, data] of Object.entries(SETTINGS)) {
const settingPath = setting.replace("_", ".");
fu.setProperty(game.pf2emhl.settings, settingPath, data?.default ?? null);
const originalOnChange = data?.onChange ?? null;
data.onChange = (value) => {
fu.setProperty(game.pf2emhl.settings, settingPath, value);
if (originalOnChange) originalOnChange(value);
};
game.settings.register(MODULE_ID, setting, data);
}
}

export function updateSettingsCache() {
for (const setting of Object.keys(SETTINGS)) {
const settingPath = setting.replace("_", ".");
fu.setProperty(game.pf2emhl.settings, settingPath, game.settings.get(MODULE_ID, setting));
}
}
export const NOTIFY = () => game.settings.get(MODULE, 'notify-on-error');

export function setting(path) {
return game.settings.get(MODULE, path);
}
export function setting(key) {
const settingPath = key.replace("_", ".");
const cached = fu.getProperty(game.pf2mhl.settings, settingPath);
return cached !== undefined ? cached : game.settings.get(MODULE_ID, key);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Lashing Currents",
"type": "script",
"scope": "global",
"author": "xuYHxk9sJoYKM7d6",
"img": "icons/magic/water/waves-water-blue.webp",
"command": "await game.pf2emhl.macros.lashingCurrents();",
"folder": null,
"ownership": {
"default": 0
},
"flags": {
"core": {}
},
"_stats": {
"systemId": "pf2e",
"systemVersion": "5.12.7",
"coreVersion": "11.315",
"createdTime": 1706489620730,
"modifiedTime": 1706489726405,
"lastModifiedBy": "xuYHxk9sJoYKM7d6"
},
"_id": "hRCi5uHwsTJHQ4Dt",
"sort": 0,
"_key": "!macros!hRCi5uHwsTJHQ4Dt"
}

0 comments on commit 68fa136

Please sign in to comment.