Skip to content

chore: Maintenance #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-poems-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"foundry-db-packer": patch
---

Maintenance
5 changes: 5 additions & 0 deletions .changeset/tall-queens-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"foundry-db-packer": minor
---

Breaking! Moves to foundryvtt/cli. Removed pack_nedb and v11 support. Added remove_input to allow removing the \_source directory from packed db directories
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20.x
cache: "npm"
- run: npm ci
- run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20.x
cache: "npm"
- run: npm ci
- run: npm run build
Expand Down
31 changes: 31 additions & 0 deletions __fixtures__/dummy-json/test/_source/test_2_gOQQZVQtGII9IKy4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "Test 2",
"type": "base",
"folder": null,
"img": "icons/svg/item-bag.svg",
"system": {
"groups": {},
"attributes": {},
"quantity": null,
"weight": null
},
"effects": [],
"ownership": {
"default": 0,
"iCyBZJPuowWIkGSH": 3
},
"flags": {
"core": {}
},
"_stats": {
"systemId": "worldbuilding",
"systemVersion": "0.8.0",
"coreVersion": "11.299",
"createdTime": 1685056073079,
"modifiedTime": 1685056102010,
"lastModifiedBy": "iCyBZJPuowWIkGSH"
},
"_id": "gOQQZVQtGII9IKy4",
"sort": 0,
"_key": "!items!gOQQZVQtGII9IKy4"
}
31 changes: 0 additions & 31 deletions __fixtures__/dummy-json/test/test_2_gOQQZVQtGII9IKy4.json

This file was deleted.

3 changes: 1 addition & 2 deletions __fixtures__/test-module/packs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test/
test.db
test/
43 changes: 8 additions & 35 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
import { exec } from "@actions/exec";
import { existsSync } from "node:fs";
import { readFile, rm } from "node:fs/promises";
import { rm } from "node:fs/promises";
import { afterAll, beforeEach, describe, expect, it } from "vitest";

import { Package } from "../src/package.js";
import * as utils from "../src/utils.js";

const jsonDir = new URL("../__fixtures__/dummy-json", import.meta.url).pathname;
const moduleDir = new URL("../__fixtures__/test-module/packs", import.meta.url).pathname;
const moduleDir = new URL("../__fixtures__/test-module/packs/test", import.meta.url).pathname;

afterAll(async () => {
if (existsSync(`${moduleDir}/test`)) await rm(`${moduleDir}/test`, { recursive: true });
if (existsSync(`${moduleDir}/test.db`)) await rm(`${moduleDir}/test.db`);
if (existsSync(`${moduleDir}`)) await rm(`${moduleDir}`, { recursive: true });
});

describe("Package", () => {
beforeEach(async () => {
if (existsSync(`${moduleDir}/test`)) await rm(`${moduleDir}/test`, { recursive: true });
if (existsSync(`${moduleDir}/test.db`)) await rm(`${moduleDir}/test.db`);
if (existsSync(`${moduleDir}`)) await rm(`${moduleDir}`, { recursive: true });
});

it("should produce a valid Classic levelDB structure", async () => {
const module = await import((await utils.ensureClassicLevel()) + "/index.js");
const ClassicLevel = module.ClassicLevel;
await Package.packClassicLevel(moduleDir + "/test", jsonDir + "/test", ClassicLevel);
expect(existsSync(`${moduleDir}/test/LOCK`)).toBe(true);
});

it("should produce a valid nedb database file", async () => {
await Package.packNedb(moduleDir, jsonDir + "/test", "test");
expect(existsSync(`${moduleDir}/test.db`)).toBe(true);

const dbFile = await readFile(`${moduleDir}/test.db`, "utf8");
expect(dbFile).toMatch(/_id":"JZbNhxKEWMarDvp9"/);
await utils.createDB({ inputdir: jsonDir, packsdir: moduleDir });
expect(existsSync(`${moduleDir}/LOCK`)).toBe(true);
});
});

Expand All @@ -45,28 +32,14 @@ describe("Utils:ensureClassicLevel", () => {

describe("Utils:createDB", () => {
beforeEach(async () => {
if (existsSync(`${moduleDir}/test`)) await rm(`${moduleDir}/test`, { recursive: true });
if (existsSync(`${moduleDir}/test.db`)) await rm(`${moduleDir}/test.db`);
if (existsSync(`${moduleDir}`)) await rm(`${moduleDir}`, { recursive: true });
});

it("should pack a directory of JSON files into a Classic LevelDB", async () => {
await utils.createDB({
inputdir: jsonDir,
packsdir: moduleDir,
packNeDB: false,
packClassicLevel: true,
ClassicLevel: (await import((await utils.ensureClassicLevel()) + "/index.js")).ClassicLevel,
});
expect(existsSync(`${moduleDir}/test/LOCK`)).toBe(true);
});

it("should pack a directory of JSON files into a NeDB", async () => {
await utils.createDB({
inputdir: jsonDir,
packsdir: moduleDir,
packNeDB: true,
packClassicLevel: false,
});
expect(existsSync(`${moduleDir}/test.db`)).toBe(true);
expect(existsSync(`${moduleDir}/LOCK`)).toBe(true);
});
});
28 changes: 12 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
name: 'FoundryVTT Release DB Packer'
description: 'Aids in packing FoundryVTT db files for release.'
author: '@aMediocreDad / Filip Ambrosius'
name: "FoundryVTT Release DB Packer"
description: "Aids in packing FoundryVTT db files for release."
author: "@aMediocreDad / Filip Ambrosius"
branding:
icon: 'code'
color: 'blue'
icon: "code"
color: "blue"
runs:
using: 'node20'
main: 'dist/index.js'
using: "node20"
main: "dist/index.js"
inputs:
inputdir:
description: 'The directory containing the json files to pack.'
description: "The directory containing the json files to pack."
required: true
packsdir:
description: "The module/system's packs directory."
required: false
default: 'packs/'
pack_classiclevel:
description: 'Whether to pack the classic level db files.'
default: "packs/"
remove_input:
description: "Remove the input directory after packing."
required: false
default: 'true'
pack_nedb:
description: 'Whether to pack the nedb type db files as well.'
required: false
default: 'false'
default: "false"
Loading
Loading