Skip to content

Commit b68037c

Browse files
committed
docs: add JSDoc comments to install/uninstall script functions
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent c5a2ac7 commit b68037c

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

postinstall.mjs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,27 @@ const packageRoot = getPackageRoot(import.meta.url)
1616
const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot)
1717

1818
/**
19-
* Returns a user-friendly error message based on the error code
20-
* @param {Error & {code?: string}} error - The error object
19+
* Returns a user-friendly error message based on the error code.
20+
*
21+
* Translates Node.js filesystem error codes into human-readable messages
22+
* that help users understand and resolve installation issues.
23+
*
24+
* @param {Error & {code?: string}} error - The error object from a failed fs operation
2125
* @param {string} file - The filename being copied
2226
* @param {string} targetPath - The target path for the file
23-
* @returns {string} A helpful error message
27+
* @returns {string} A helpful error message describing the issue and potential solution
28+
*
29+
* @example
30+
* // Permission denied error
31+
* const err = Object.assign(new Error(), { code: 'EACCES' })
32+
* getErrorMessage(err, 'agent.md', '/home/user/.config/opencode/agents/agent.md')
33+
* // Returns: "Permission denied. Check write permissions for /home/user/.config/opencode/agents"
34+
*
35+
* @example
36+
* // File not found error
37+
* const err = Object.assign(new Error(), { code: 'ENOENT' })
38+
* getErrorMessage(err, 'missing.md', '/target/missing.md')
39+
* // Returns: "Source file not found: missing.md"
2440
*/
2541
function getErrorMessage(error, file, targetPath) {
2642
const code = error.code
@@ -41,6 +57,25 @@ function getErrorMessage(error, file, targetPath) {
4157
}
4258
}
4359

60+
/**
61+
* Main entry point for the postinstall script.
62+
*
63+
* Copies all agent markdown files from the package's agents/ directory
64+
* to the OpenCode configuration directory (~/.config/opencode/agents/).
65+
* This enables OpenCode to discover and use the installed agents.
66+
*
67+
* The function handles partial failures gracefully, installing as many
68+
* agents as possible and reporting individual failures.
69+
*
70+
* @returns {void}
71+
*
72+
* @throws {never} Does not throw - uses process.exit() for error conditions
73+
*
74+
* Exit codes:
75+
* - 0: All agents installed successfully, or partial success with some failures
76+
* - 1: Complete failure - source directory missing, no agent files found,
77+
* or all file copies failed
78+
*/
4479
function main() {
4580
console.log("opencode-plugin-opencoder: Installing agents...")
4681

preuninstall.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ import { AGENTS_TARGET_DIR, getAgentsSourceDir, getPackageRoot } from "./src/pat
1515
const packageRoot = getPackageRoot(import.meta.url)
1616
const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot)
1717

18+
/**
19+
* Main entry point for the preuninstall script.
20+
*
21+
* Removes agent markdown files that were installed by this package
22+
* from the OpenCode configuration directory (~/.config/opencode/agents/).
23+
* Only removes files that match agents in the package's agents/ directory.
24+
*
25+
* The function handles missing directories and files gracefully,
26+
* continuing to remove remaining agents even if some fail.
27+
*
28+
* @returns {void}
29+
*
30+
* @throws {never} Does not throw - handles all errors internally
31+
*
32+
* Exit codes:
33+
* - 0: Always exits successfully, even if no agents were removed or
34+
* some removals failed. This ensures npm uninstall completes.
35+
*/
1836
function main() {
1937
console.log("opencode-plugin-opencoder: Removing agents...")
2038

0 commit comments

Comments
 (0)