### Install foundryvtt-cli Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Installs the foundryvtt-cli globally using npm. This command makes the `fvtt` executable available in your system's PATH. ```bash npm install -g @foundryvtt/foundryvtt-cli ``` -------------------------------- ### Module JSON Example with Subdirectory Packs Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md An example of a `module.json` file defining packs with subdirectory paths for different systems. This allows for organized storage of pack data within a module. ```json { "packs": [ { "name": "mymodule_items_sfrpg", "label": "MyModule Items", "path": "packs/items/sfrpg", "type": "Item", "private": false, "system": "sfrpg" }, { "name": "mymodule_items_pf2e", "label": "MyModule Items", "path": "packs/items/pf2e", "type": "Item", "private": false, "system": "pf2e" } ] } ``` -------------------------------- ### Display CLI Version Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Shows the currently installed version of the foundryvtt-cli. This is helpful for troubleshooting or verifying the installation. ```bash fvtt --version ``` -------------------------------- ### Complete Workflow Example: Foundry VTT CLI and API Source: https://context7.com/foundryvtt/foundryvtt-cli/llms.txt Demonstrates a full development workflow using both Foundry VTT CLI commands and its programmatic API. This includes extracting packs for editing, making programmatic modifications to content files, and recompiling them. It also shows a CI/CD build script for creating release-ready packs with production cleanup. ```javascript import { compilePack, extractPack } from "@foundryvtt/foundryvtt-cli"; import fs from "fs"; import path from "path"; // Development workflow: Extract, modify, and recompile async function developmentWorkflow() { const packPath = "mymodule/packs/items"; const sourcePath = "mymodule/packs/src/items"; // Step 1: Extract current pack for editing console.log("Extracting pack for development..."); await extractPack(packPath, sourcePath, { yaml: true, folders: true, omitVolatile: true, log: true }); // Step 2: Make programmatic modifications const files = fs.readdirSync(sourcePath, { recursive: true }); for (const file of files) { if (!file.endsWith('.yml')) continue; const filePath = path.join(sourcePath, file); const content = fs.readFileSync(filePath, 'utf8'); // Example: Update all items to new schema version const updated = content.replace(/schemaVersion: 1/g, 'schemaVersion: 2'); fs.writeFileSync(filePath, updated); } // Step 3: Recompile the pack console.log("Recompiling pack..."); await compilePack(sourcePath, packPath, { yaml: true, recursive: true, log: true }); console.log("Development cycle complete!"); } // CI/CD build script async function buildForRelease() { const config = { packs: [ { name: 'actors', type: 'Actor' }, { name: 'items', type: 'Item' }, { name: 'journal', type: 'JournalEntry' } ], srcDir: 'src/packs', distDir: 'dist/packs' }; // Clean dist directory fs.rmSync(config.distDir, { recursive: true, force: true }); fs.mkdirSync(config.distDir, { recursive: true }); // Build each pack for (const pack of config.packs) { await compilePack( path.join(config.srcDir, pack.name), path.join(config.distDir, pack.name), { recursive: true, log: true, transformEntry: async (entry) => { // Production cleanup delete entry.flags?.debug; delete entry._stats?.lastModifiedBy; } } ); } } await developmentWorkflow(); ``` -------------------------------- ### Example Workflow for Package Management Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Demonstrates a typical workflow for managing Foundry VTT packages using the CLI, including configuration, setting a working package, unpacking, making edits, and repacking. ```bash fvtt configure fvtt package workon "1001-fish" fvtt package unpack "fish" . . . // Make some updates to the files fvtt package pack "fish" ``` -------------------------------- ### Develop foundryvtt-cli Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Steps to clone the foundryvtt-cli repository, install dependencies, build the project, and link it locally for development. ```bash git clone cd foundryvtt-cli npm install npm run build npm link ``` -------------------------------- ### Get CLI Configuration Path Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Outputs the file path to the current configuration file used by the foundryvtt-cli. Useful for manual inspection or editing. ```bash fvtt configure path ``` -------------------------------- ### Get CLI Configuration Value Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Retrieves a specific configuration value from the foundryvtt-cli settings. Requires the key of the configuration setting. ```bash fvtt configure get "key" ``` -------------------------------- ### API: Extract and Compile Packs Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Example usage of the foundryvtt-cli API for extracting NeDB compendium packs and compiling LevelDB compendium packs programmatically. Requires importing functions from the library. ```javascript import { compilePack, extractPack } from "@foundryvtt/foundryvtt-cli"; // Extract a NeDB compendium pack. await extractpack("mymodule/packs/actors.db", "mymodule/packs/src/actors", { nedb: true }); // Compile a LevelDB compendium pack. await compilePack("mymodule/packs/src/actors", "mymodule/packs/actors"); ``` -------------------------------- ### Display CLI Help Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Displays the help message for the foundryvtt-cli, outlining available commands and options. This is useful for discovering functionality. ```bash fvtt --help ``` -------------------------------- ### View CLI Configuration Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Displays the current configuration settings of the foundryvtt-cli. This command allows users to inspect their settings. ```bash fvtt configure view ``` -------------------------------- ### Configure Foundry VTT CLI Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Initiates the configuration process for the foundryvtt-cli. If the configuration is incorrect, it will prompt the user to fix it. ```bash fvtt configure ``` -------------------------------- ### Pack Compendium with Options Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Packs individual JSON files into a compendium. Supports specifying the compendium name (including subdirectories) and the input directory for JSON files. ```bash fvtt package pack -n "items/pf2e" --inputDirectory "~/jsons/items/pf2e" --outputDirectory "packs" fvtt package pack -n "items/sfrpg" --inputDirectory "~/jsons/items/sfrpg" --outputDirectory "packs" ``` -------------------------------- ### Launch Foundry VTT Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Launches the Foundry VTT application. Supports various options to customize the launch behavior, such as demo mode, port, world, UPnP, updates, and admin key. ```bash fvtt launch fvtt launch --demo fvtt launch --port 30000 fvtt launch --world my-world fvtt launch --noupnp fvtt launch --noupdate fvtt launch --adminKey "ABC123" ``` -------------------------------- ### Manage Foundry VTT Packages Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Provides commands for managing Foundry VTT packages, including outputting the current working package, setting a package to work on, clearing the current package, unpacking, and packing. ```bash fvtt package fvtt package workon "1001-fish" --type "Module" fvtt package clear fvtt package unpack "compendiumName" fvtt package pack "compendiumName" ``` -------------------------------- ### Unpack Compendium with Options Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Unpacks a compendium into individual JSON files. Supports specifying the compendium name (including subdirectories) and an output directory. ```bash fvtt package unpack -n "items/pf2e" --outputDirectory "~/jsons/items/pf2e" fvtt package unpack -n "items/sfrpg" --outputDirectory "~/jsons/items/sfrpg" ``` -------------------------------- ### Set CLI Configuration Value Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Sets a specific configuration value for the foundryvtt-cli. Requires a key and a value to be provided as arguments. ```bash fvtt configure set "key" "value" ``` -------------------------------- ### Compile Source Files into Compendium Pack Database - JavaScript Source: https://context7.com/foundryvtt/foundryvtt-cli/llms.txt The `compilePack` function reconstructs compendium pack databases from source files. It supports various source formats (JSON, YAML), database targets (LevelDB, NeDB), and allows for filtering and transforming entries during the compilation. Options include recursive directory searching and logging. ```javascript import { compilePack } from "@foundryvtt/foundryvtt-cli"; // Basic compilation to LevelDB await compilePack( "mymodule/packs/src/actors", "mymodule/packs/actors" ); // Compile from YAML sources with logging await compilePack( "mymodule/packs/src/items", "mymodule/packs/items", { yaml: true, log: true } ); // Compile to NeDB database await compilePack( "mymodule/packs/src/actors", "mymodule/packs/actors.db", { nedb: true, log: true } ); // Compile with recursive directory search await compilePack( "mymodule/packs/src/items", "mymodule/packs/items", { recursive: true, log: true } ); // Compile with entry transformation and filtering await compilePack( "mymodule/packs/src/items", "mymodule/packs/items", { log: true, transformEntry: async (entry, context) => { // Skip draft entries if (entry.flags?.draft) return false; // Remove development-only fields delete entry.flags?.devNotes; delete entry._devMeta; // Add build metadata entry.flags = entry.flags || {}; entry.flags.buildVersion = process.env.npm_package_version; } } ); // Build pipeline example async function buildCompendiums() { const packs = ['actors', 'items', 'journal', 'scenes']; for (const pack of packs) { console.log(`Building ${pack}...`); await compilePack( `src/packs/${pack}`, `dist/packs/${pack}`, { recursive: true, yaml: true, log: true, transformEntry: async (entry) => { // Validate required fields if (!entry._id || !entry._key) { console.warn(`Skipping invalid entry: ${entry.name || 'unnamed'}`); return false; } } } ); } } await buildCompendiums(); ``` -------------------------------- ### Import Compendium Pack from Source Files - Foundry VTT CLI Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Imports source files into a Foundry VTT compendium pack. It supports various options for database types (NeDB/LevelDB), file formats (JSON/YAML), logging, recursion, and custom transformations for entries, names, folder names, and serialized content. It also handles expanding adventures and omitting volatile data. ```typescript import { importPack } from "@foundryvtt/foundryvtt-cli"; async function runImport() { await importPack( "path/to/source/files", "MyCompendium.db", { nedb: false, yaml: true, log: true, recursive: true, transformEntry: async (entry, context) => { // Custom logic to transform entry return entry; }, transformName: async (entry, context) => { // Custom logic to transform entry name return `${entry.name}.yml`; }, transformFolderName: async (entry) => { // Custom logic to transform folder name return entry.name; }, transformSerialized: async (content, context) => { // Custom logic to transform serialized content return content; }, folders: true, documentType: "Item", expandAdventures: true, omitVolatile: true, yamlOptions: { indent: 2 }, jsonOptions: { space: 2 } } ); } ``` -------------------------------- ### API: compilePack Function Signature Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Defines the function signature for `compilePack`, which compiles source files into a compendium pack. It takes source and destination paths, and an optional options object. ```typescript compilePack(src: string, dest: string, options?: object): Promise ``` -------------------------------- ### Extract Compendium Pack to Source Files - Foundry VTT CLI Source: https://github.com/foundryvtt/foundryvtt-cli/blob/main/README.md Extracts the contents of a Foundry VTT compendium pack into individual source files. This function supports NeDB/LevelDB operations, JSON/YAML formats, logging, and custom transformations for entries, names, folder names, and serialized content. It can also create a directory structure matching pack folders and optionally expand adventures. ```typescript import { extractPack } from "@foundryvtt/foundryvtt-cli"; async function runExtract() { await extractPack( "MyCompendium.db", "path/to/destination/directory", { nedb: false, yaml: true, yamlOptions: { indent: 2 }, log: true, folders: true, documentType: "Item", transformEntry: async (entry, context) => { // Custom logic to transform entry return entry; }, transformName: async (entry, context) => { // Custom logic to transform entry name return `${entry.name}.yml`; }, transformFolderName: async (entry) => { // Custom logic to transform folder name return entry.name; }, transformSerialized: async (content, context) => { // Custom logic to transform serialized content return content; }, expandAdventures: true, omitVolatile: true, jsonOptions: { space: 2 } } ); } ``` -------------------------------- ### Extract Compendium Pack Contents to Source Files - JavaScript Source: https://context7.com/foundryvtt/foundryvtt-cli/llms.txt The `extractPack` function exports compendium pack data into individual source files. It supports various output formats like JSON and YAML, different database types, and allows for custom transformations of entries and filenames during the extraction process. Options include handling folder structures, expanding adventure data, and omitting volatile fields. ```javascript import { extractPack } from "@foundryvtt/foundryvtt-cli"; // Basic extraction from LevelDB to JSON await extractPack( "mymodule/packs/actors", "mymodule/packs/src/actors" ); // Extract to YAML format with logging await extractPack( "mymodule/packs/items", "mymodule/packs/src/items", { yaml: true, log: true, yamlOptions: { lineWidth: 120 } } ); // Extract from NeDB database await extractPack( "mymodule/packs/actors.db", "mymodule/packs/src/actors", { nedb: true, documentType: "Actor" } ); // Extract with folder structure and expanded adventures await extractPack( "mymodule/packs/adventures", "mymodule/packs/src/adventures", { folders: true, expandAdventures: true, log: true } ); // Extract with custom entry transformation await extractPack( "mymodule/packs/items", "mymodule/packs/src/items", { log: true, transformEntry: async (entry, context) => { // Skip entries without a name if (!entry.name) return false; // Modify entries before writing entry.flags = entry.flags || {}; entry.flags.exported = Date.now(); }, transformName: async (entry, context) => { // Custom filename generation return `${entry.type}/${entry.name.toLowerCase().replace(/\s+/g, '-')}_${entry._id}.json`; } } ); // Extract with volatile field handling (skip unchanged entries) await extractPack( "mymodule/packs/actors", "mymodule/packs/src/actors", { omitVolatile: true, log: true, jsonOptions: { space: 2, replacer: (key, value) => key.startsWith('_') ? undefined : value } } ); // Extract with serialization transformation await extractPack( "mymodule/packs/journal", "mymodule/packs/src/journal", { transformSerialized: async (content, context) => { // Add header comment to each file return `// Extracted: ${new Date().toISOString()}\n${content}`; } } ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.