diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c533a54 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,53 @@ +import { CompileOptions, ExtractOptions } from "./lib/package.mjs"; + +declare module "foundryvtt-cli" { + /** + * A mapping of primary document types to collection names. + * @type {Record} + */ + export const TYPE_COLLECTION_MAP: Record = { + Actor: "actors", + Adventure: "adventures", + Cards: "cards", + ChatMessage: "messages", + Combat: "combats", + FogExploration: "fog", + Folder: "folders", + Item: "items", + JournalEntry: "journal", + Macro: "macros", + Playlist: "playlists", + RollTable: "tables", + Scene: "scenes", + Setting: "settings", + User: "users", + }; + + /** + * Compile source files into a compendium pack. + * @param {string} src The directory containing the source files. + * @param {string} dest The target compendium pack. This should be a directory for LevelDB packs, or a .db file for + * NeDB packs. + * @param {CompileOptions} [options] + * @returns {Promise} + */ + export function compilePack( + src: string, + dest: string, + options: CompileOptions + ): Promise; + + /** + * Extract the contents of a compendium pack into individual source files for each primary Document. + * @param {string} src The source compendium pack. This should be a directory for LevelDB pack, or a .db file for + * NeDB packs. + * @param {string} dest The directory to write the extracted files into. + * @param {ExtractOptions} [options] + * @returns {Promise} + */ + export async function extractPack( + src: string, + dest: string, + options: ExtractOptions + ): Promise; +} diff --git a/index.mjs b/index.mjs index 372d936..566c85b 100644 --- a/index.mjs +++ b/index.mjs @@ -1 +1,5 @@ -export { compilePack, extractPack } from "./lib/package.mjs"; +export { + compilePack, + extractPack, + TYPE_COLLECTION_MAP, +} from "./lib/package.mjs"; \ No newline at end of file diff --git a/lib/package.mjs b/lib/package.mjs index 260a324..7b41ba3 100644 --- a/lib/package.mjs +++ b/lib/package.mjs @@ -283,8 +283,8 @@ async function compileClassicLevel(pack, files, { log, transformEntry }={}) { const ext = path.extname(file); const isYaml = ext === ".yml" || ext === ".yaml"; const doc = isYaml ? YAML.load(contents) : JSON.parse(contents); - const [, collection] = doc._key.split("!"); if ( await transformEntry?.(doc) === false ) continue; + const [, collection] = doc._key.split("!"); await packDoc(doc, collection); if ( log ) console.log(`Packed ${chalk.blue(doc._id)}${chalk.blue(doc.name ? ` (${doc.name})` : "")}`); } catch ( err ) { diff --git a/package.json b/package.json index 0901e55..86a961c 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { - "name": "@foundryvtt/foundryvtt-cli", + "name": "foundryvtt-cli", "productName": "Foundry VTT CLI", "description": "The Official CLI for Foundry VTT", - "version": "0.0.5", + "version": "1.0.4", "author": { "name": "Foundry Gaming LLC", "email": "admin@foundryvtt.com", "url": "https://foundryvtt.com" }, + "types": "index.d.ts", "main": "index.mjs", "bin": { "fvtt": "fvtt.mjs"