Add initial scripts into the repo

This commit is contained in:
Oliver 2026-01-13 17:03:54 -07:00
commit 1b983cb54d
9 changed files with 1389 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules/

1153
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"devDependencies": {
"@foundryvtt/foundryvtt-cli": "^3.0.2",
"axios": "^1.13.2",
"dotenv": "^17.2.3"
}
}

34
src/buildCompendia.mjs Normal file
View file

@ -0,0 +1,34 @@
import { compilePack } from "@foundryvtt/foundryvtt-cli";
import { existsSync } from "fs";
import { join } from "path";
import { config } from "dotenv";
import { assertEnvKey, getManifest } from "./utils.mjs";
config({ quiet: true });
assertEnvKey("MANIFEST");
const MANIFEST_FILE = process.env.MANIFEST;
const manifest = getManifest(MANIFEST_FILE);
if (!manifest.packs || manifest.packs.length === 0) {
console.log(`No compendium packs defined`);
process.exit(0);
};
for (const compendium of manifest.packs) {
console.debug(`Packing ${compendium.label} (${compendium.name})`);
let src = join(process.cwd(), compendium.path, `_source`);
if (!existsSync(src)) {
console.warn(`${compendium.path} doesn't exist, skipping.`)
continue;
};
await compilePack(
src,
join(process.cwd(), compendium.path),
{ recursive: true },
);
console.debug(`Finished packing ${compendium.name}`);
};
console.log(`Finished packing compendia`);

View file

@ -0,0 +1,53 @@
import axios from "axios";
const {
TAG,
FORGEJO_SERVER_URL: WEB_URL,
FORGEJO_API_URL: API,
FORGEJO_REPOSITORY: REPO,
FORGEJO_TOKEN: TOKEN,
FORGEJO_REF_NAME: TARGET_REF,
CDN_URL,
} = process.env;
// TODO: make this upload the file to Forgejo
async function addReleaseAsset(releaseID, name) {
return;
return axios.post(
`${API}/repos/${REPO}/releases/${releaseID}/assets`,
{ external_url: `${CDN_URL}/${REPO}/${TAG}/${name}`, },
{
headers: {
Authorization: `token ${TOKEN}`,
"Content-Type": `multipart/form-data`,
},
params: { name },
}
);
};
// Initial Release Data
const release = await axios.post(
`${API}/repos/${REPO}/releases`,
{
name: TAG,
tag_name: TAG,
draft: true,
hide_archive_links: true,
target_commitish: TARGET_REF,
body: `<!-- Manifest URL: ${WEB_URL}/${REPO}/releases/download/${TAG}/system.json -->`,
},
{
headers: { Authorization: `token ${TOKEN}` },
}
);
try {
await addReleaseAsset(release.data.id, `release.zip`);
await addReleaseAsset(release.data.id, `system.json`);
} catch (e) {
console.error(`Failed to add assets to the release`);
process.exit(1);
};
console.log(`Release created`);

28
src/extractCompendia.mjs Normal file
View file

@ -0,0 +1,28 @@
import { readFile } from "fs/promises";
import { join } from "path";
import { extractPack } from "@foundryvtt/foundryvtt-cli";
import { assertEnvKey, getManifest } from "./utils.mjs";
config({ quiet: true });
assertEnvKey("MANIFEST");
const MANIFEST_FILE = process.env.MANIFEST;
const manifest = getManifest(MANIFEST_FILE);
if (!manifest.packs || manifest.packs.length === 0) {
console.log(`No compendium packs defined`);
process.exit(0);
};
for (const compendium of manifest.packs) {
console.debug(`Unpacking ${compendium.label} (${compendium.name})`);
let src = join(process.cwd(), compendium.path, `_source`);
await extractPack(
join(process.cwd(), compendium.path),
src,
{ recursive: true },
);
console.debug(`Finished packing ${compendium.name}`);
};
console.log(`Finished unpacking compendia`);

43
src/linkFoundry.mjs Normal file
View file

@ -0,0 +1,43 @@
import { existsSync } from "fs";
import { symlink, unlink } from "fs/promises";
import { join } from "path";
import { config } from "dotenv";
import { assertEnvKey } from "./utils.mjs";
config({ quiet: true });
assertEnvKey("FOUNDRY_ROOT");
const root = process.env.FOUNDRY_ROOT;
// Assert Foundry exists
if (!existsSync(root)) {
console.error(`Foundry root not found.`);
process.exit(1);
};
// Removing existing symlink
if (existsSync(`foundry`)) {
console.log(`Attempting to unlink foundry instance`);
try {
await unlink(`foundry`);
} catch {
console.error(`Failed to unlink foundry folder.`);
process.exit(1);
};
};
// Account for if the root is pointing at an Electron install
let targetRoot = root;
if (existsSync(join(root, `resources`, `app`))) {
console.log(`Switching to use the "${root}/resources/app" directory`);
targetRoot = join(root, `resources`, `app`);
};
// Create symlink
console.log(`Linking foundry source into folder`)
try {
await symlink(targetRoot, `foundry`);
} catch (e) {
console.error(e);
process.exit(1);
};

50
src/prepareManifest.mjs Normal file
View file

@ -0,0 +1,50 @@
/*
The intent of this script is to do all of the modifications of the
manifest file that we need to do in order to release the system.
This can include removing dev-only fields/attributes that end
users will never, and should never, care about nor need.
*/
import { readFile, writeFile } from "fs/promises";
import { config } from "dotenv";
import { assertEnvKey } from "./utils.mjs";
config({ quiet: true });
assertEnvKey("MANIFEST");
const MANIFEST_PATH = process.env.MANIFEST;
const {
DOWNLOAD_URL,
LATEST_URL,
} = process.env;
let manifest;
try {
manifest = JSON.parse(await readFile(MANIFEST_PATH, `utf-8`));
console.log(`Manifest loaded from disk`);
} catch {
console.error(`Failed to parse manifest file.`);
process.exit(1);
};
console.log(`Updating download/manifest URLs`)
manifest.download = DOWNLOAD_URL;
manifest.manifest = LATEST_URL;
// Filter out dev-only resources
if (manifest.esmodules) {
console.log(`Removing dev-only esmodules`);
manifest.esmodules = manifest.esmodules.filter(
filepath => !filepath.startsWith(`dev/`)
);
};
// Remove dev flags
console.log(`Cleaning up flags`);
delete manifest.flags?.hotReload;
if (Object.keys(manifest.flags).length === 0) {
delete manifest.flags;
};
await writeFile(MANIFEST_PATH, JSON.stringify(manifest, undefined, `\t`));
console.log(`Manifest written back to disk`);

20
src/utils.mjs Normal file
View file

@ -0,0 +1,20 @@
import { readFile } from "fs/promises";
export async function getManifest(manifest) {
let data = undefined;
try {
data = JSON.parse(await readFile(manifest, `utf-8`));
} catch {};
return data;
};
export function assertEnvKey(key, { checkTruthiness = true }) {
if (!(key in process.env)) {
console.error(`Must provide a ${key} environment variable`);
process.exit(1);
};
if (checkTruthiness && !process.env[key]) {
console.error(`The ${key} environment variable must be truthy`);
process.exit(1);
};
};