### Install Project Dependencies Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Installs all necessary project dependencies using npm. This command should be run in the project's root directory. ```bash npm install ``` -------------------------------- ### Start Development Watch Mode Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Starts a development server that watches for file changes and automatically rebuilds the project. This is useful for active development. ```bash npm run dev ``` -------------------------------- ### Manual Plugin Installation for Testing Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Copy plugin files to the Obsidian plugins directory for manual testing. Ensure the plugin is enabled in settings after reloading Obsidian. ```bash cp main.js, manifest.json, styles.css (if any) /.obsidian/plugins// ``` -------------------------------- ### Example Obsidian Plugin File Structure Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Organize your plugin code into logical directories for better maintainability. Place the main entry point in `src/main.ts` and keep it focused on plugin lifecycle events. ```plaintext src/ main.ts # Plugin entry point, lifecycle management settings.ts # Settings interface and defaults commands/ # Command implementations command1.ts command2.ts ui/ # UI components, modals, views modal.ts view.ts utils/ # Utility functions, helpers helpers.ts constants.ts types.ts # TypeScript interfaces and types ``` -------------------------------- ### Get Icon from Type Source: https://github.com/obsidianmd/obsidian-maps/blob/master/examples/Readme.md Retrieves the icon property from the assigned type of a note. Ensure the type has an 'icon' property defined. ```javascript // Get the icon from the type list(type)[0].asFile().properties.icon ``` -------------------------------- ### Get Color from Type Source: https://github.com/obsidianmd/obsidian-maps/blob/master/examples/Readme.md Retrieves the color property from the assigned type of a note. Ensure the type has a 'color' property defined. ```javascript // Get the color from the type list(type)[0].asFile().properties.color ``` -------------------------------- ### Lint Single TypeScript File Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Analyzes a single TypeScript file (`main.ts`) for potential code quality issues and style violations using ESLint. Requires ESLint to be installed globally. ```bash eslint main.ts ``` -------------------------------- ### Lint TypeScript Files in a Folder Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Analyzes all TypeScript files within a specified folder (e.g., `./src/`) for code quality and style issues using ESLint. Requires ESLint to be installed globally. ```bash eslint ./src/ ``` -------------------------------- ### Minimal Plugin Lifecycle (main.ts) Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md This snippet shows the minimal structure for an Obsidian plugin's main file, handling loading and settings initialization. ```typescript import { Plugin } from "obsidian"; import { MySettings, DEFAULT_SETTINGS } from "./settings"; import { registerCommands } from "./commands"; export default class MyPlugin extends Plugin { settings: MySettings; async onload() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); registerCommands(this); } } ``` -------------------------------- ### Registering Plugin Commands (commands/index.ts) Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Organizes command registration into a separate file, importing the actual command logic. ```typescript import { Plugin } from "obsidian"; import { doSomething } from "./my-command"; export function registerCommands(plugin: Plugin) { plugin.addCommand({ id: "do-something", name: "Do something", callback: () => doSomething(plugin), }); } ``` -------------------------------- ### Create Production Build Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Generates the production-ready build artifacts for the Obsidian plugin. This includes bundling the code and creating necessary manifest files. ```bash npm run build ``` -------------------------------- ### Persist Plugin Settings Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Shows how to load and save plugin settings, ensuring persistence across reloads. ```typescript interface MySettings { enabled: boolean } const DEFAULT_SETTINGS: MySettings = { enabled: true }; async onload() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); await this.saveData(this.settings); } ``` -------------------------------- ### Add a Command to the Plugin Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Demonstrates how to add a new command to the Obsidian plugin. ```typescript this.addCommand({ id: "your-command-id", name: "Do the thing", callback: () => this.doTheThing(), }); ``` -------------------------------- ### Plugin Settings Interface and Defaults (settings.ts) Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Defines the interface for plugin settings and provides default values. ```typescript export interface MySettings { enabled: boolean; apiKey: string; } export const DEFAULT_SETTINGS: MySettings = { enabled: true, apiKey: "", }; ``` -------------------------------- ### Safely Register Listeners and Intervals Source: https://github.com/obsidianmd/obsidian-maps/blob/master/AGENTS.md Illustrates using `this.register*` helpers to ensure listeners, DOM events, and intervals are cleaned up properly. ```typescript this.registerEvent(this.app.workspace.on("file-open", f => { /* ... */ })); this.registerDomEvent(window, "resize", () => { /* ... */ }); this.registerInterval(window.setInterval(() => { /* ... */ }, 1000)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.