@tertium/hlpr 0.5.8 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ # Git Commands
2
+
3
+ Helpful git utilities for common development workflows.
4
+
5
+ ## Platform Support
6
+
7
+ All Git commands work on:
8
+
9
+ - ✅ **Linux** - Fully supported
10
+ - ✅ **macOS** - Fully supported
11
+ - ✅ **Windows** - Requires Git for Windows (includes Git Bash)
12
+
13
+ ---
14
+
15
+ ## fodd
16
+
17
+ Fetch and update develop branch from origin.
18
+
19
+ **Usage:**
20
+ ```bash
21
+ hlpr git fodd
22
+ ```
23
+
24
+ **What it does:**
25
+ - Fetches the `develop` branch from origin
26
+ - Updates your local `develop` branch to match the remote
27
+
28
+ **When to use:**
29
+ - Before starting work to ensure you have the latest develop branch
30
+ - To sync your local develop with the remote
31
+
32
+ **Command:**
33
+ ```bash
34
+ git fetch origin develop:develop
35
+ ```
36
+
37
+ ---
38
+
39
+ ## precommit
40
+
41
+ Run build and stage binaries before commit.
42
+
43
+ **Usage:**
44
+ ```bash
45
+ hlpr git precommit
46
+ ```
47
+
48
+ **What it does:**
49
+ 1. Runs `bun run build` to compile your project
50
+ 2. Stages the `bin/` directory for commit
51
+
52
+ **When to use:**
53
+ - Before committing changes to ensure binaries are up-to-date
54
+ - As a git pre-commit hook to automate the process
55
+
56
+ **Example workflow:**
57
+ ```bash
58
+ # Make changes to source files
59
+ hlpr git precommit # Build and stage bin/
60
+ git commit -m "feat: add new feature"
61
+ ```
62
+
63
+ ---
64
+
65
+ ## switch-clean
66
+
67
+ Safely switch to a target branch and delete the previous branch (both local and remote).
68
+
69
+ **Usage:**
70
+ ```bash
71
+ hlpr git switch-clean <target-branch>
72
+ ```
73
+
74
+ **What it does:**
75
+
76
+ 1. **Validates current state**
77
+ - Checks you're on a branch (not detached HEAD)
78
+ - Ensures you're not already on the target branch
79
+ - Verifies there are no uncommitted changes
80
+
81
+ 2. **Checks for unpushed commits**
82
+ - Fails if current branch has commits that haven't been pushed
83
+ - Prevents accidental loss of work
84
+
85
+ 3. **Fetches target branch**
86
+ - Runs `git fetch origin <target-branch>:<target-branch>`
87
+ - Updates the target branch to match remote
88
+
89
+ 4. **Switches to target branch**
90
+ - Checks out the target branch
91
+
92
+ 5. **Deletes previous branch**
93
+ - Deletes local branch: `git branch -d <old-branch>`
94
+ - Deletes remote branch (if exists): `git push origin --delete <old-branch>`
95
+
96
+ **Safety Features:**
97
+
98
+ - ✅ **Uncommitted changes check** - Prevents switching if you have uncommitted work
99
+ - ✅ **Unpushed commits check** - Ensures all work is pushed before deletion
100
+ - ✅ **Remote existence check** - Only deletes remote branch if it exists
101
+ - ✅ **Safe branch deletion** - Uses `git branch -d` (not `-D`), refuses to delete unmerged branches
102
+
103
+ **Examples:**
104
+
105
+ ```bash
106
+ # Switch from feature branch to develop and clean up
107
+ hlpr git switch-clean develop
108
+ # ✓ Switched to 'develop' and deleted 'feature/add-auth' (local & remote)
109
+
110
+ # Switch to main
111
+ hlpr git switch-clean main
112
+ # ✓ Switched to 'main' and deleted 'develop' (local only)
113
+ ```
114
+
115
+ **Error Handling:**
116
+
117
+ The command will fail and exit if:
118
+
119
+ - No target branch is specified
120
+ - Not currently on a branch (detached HEAD)
121
+ - Already on the target branch
122
+ - There are uncommitted changes
123
+ - Current branch has unpushed commits
124
+ - Target branch doesn't exist on remote
125
+
126
+ **Solution:**
127
+ - Commit or stash uncommitted changes
128
+ - Push unpushed commits: `git push origin <branch>`
129
+ - Ensure target branch exists on remote
@@ -0,0 +1,35 @@
1
+ # Hello Commands
2
+
3
+ Example/demo commands for testing the hlpr CLI tool.
4
+
5
+ ## Platform Support
6
+
7
+ - ✅ **Linux** - Fully supported
8
+ - ✅ **macOS** - Fully supported
9
+ - ✅ **Windows** - Requires Git Bash or WSL
10
+
11
+ ## world
12
+
13
+ Print a personalized hello world message.
14
+
15
+ ### Usage
16
+
17
+ ```bash
18
+ hlpr hello world
19
+ ```
20
+
21
+ The command will prompt you for a name and then print a personalized greeting.
22
+
23
+ ### Example
24
+
25
+ ```bash
26
+ $ hlpr hello world
27
+ Enter name: Alice
28
+ Hello World, Alice
29
+ ```
30
+
31
+ ### Variables
32
+
33
+ - `name` - Your name (prompted during execution)
34
+
35
+ This command demonstrates the variable substitution feature of hlpr, where `{{name}}` in the script is replaced with user input.
@@ -0,0 +1,55 @@
1
+ # Help Command
2
+
3
+ Displays help information about available commands in the hlpr CLI tool.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ hlpr help
9
+ # or
10
+ hlpr --help
11
+ # or
12
+ hlpr -h
13
+ # or just
14
+ hlpr
15
+ ```
16
+
17
+ ## Description
18
+
19
+ The help command automatically discovers all available commands in the `commands/` directory and displays them in an organized format. It shows:
20
+
21
+ - Command categories (e.g., file, git, ssh, nvm)
22
+ - Command names and full usage
23
+ - Command type (TypeScript or Shell)
24
+ - Command descriptions (when available)
25
+ - Usage examples
26
+
27
+ ## Features
28
+
29
+ - Auto-discovers commands from the commands directory
30
+ - Groups commands by category
31
+ - Shows command types (TypeScript or Shell scripts)
32
+ - Extracts descriptions from:
33
+ - `@description` comments in source files
34
+ - README.md files in command directories
35
+ - Displays formatted help with usage examples
36
+
37
+ ## Examples
38
+
39
+ ```bash
40
+ # Show all available commands
41
+ hlpr help
42
+
43
+ # If no command is provided, help is shown automatically
44
+ hlpr
45
+ ```
46
+
47
+ ## Output
48
+
49
+ The help command displays:
50
+
51
+ 1. **Header** - Tool name and version
52
+ 2. **Usage** - Basic syntax
53
+ 3. **Options** - Available flags (-f, -v, help)
54
+ 4. **Available Commands** - Grouped by category with descriptions
55
+ 5. **Examples** - Common usage patterns
@@ -0,0 +1,90 @@
1
+ # NVM Commands
2
+
3
+ Node Version Manager (nvm) utility commands.
4
+
5
+ ## install
6
+
7
+ Install Node Version Manager (nvm).
8
+
9
+ ### Usage
10
+
11
+ ```bash
12
+ hlpr nvm install
13
+ ```
14
+
15
+ ### Platform Support
16
+
17
+ - ✅ **Linux** - Fully supported
18
+ - ✅ **macOS** - Fully supported
19
+ - ⚠️ **Windows** - Requires Git Bash or WSL (Windows Subsystem for Linux)
20
+ - **Alternative for Windows**: Use [nvm-windows](https://github.com/coreybutler/nvm-windows) instead
21
+
22
+ ### What it does
23
+
24
+ Downloads and installs nvm from the official repository using the installation script:
25
+
26
+ ```bash
27
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
28
+ ```
29
+
30
+ ### Post-installation
31
+
32
+ After installation, you may need to:
33
+
34
+ 1. Close and reopen your terminal
35
+ 2. Or source your shell profile:
36
+
37
+ ```bash
38
+ source ~/.bashrc # or ~/.zshrc, ~/.bash_profile, etc.
39
+ ```
40
+
41
+ ### Verify installation
42
+
43
+ ```bash
44
+ nvm --version
45
+ ```
46
+
47
+ ## lts
48
+
49
+ Install and use the latest Node.js LTS (Long Term Support) version.
50
+
51
+ ### Platform Support (lts)
52
+
53
+ Same as `install` command - requires nvm to be installed.
54
+
55
+ ### Usage
56
+
57
+ ```bash
58
+ hlpr nvm lts
59
+ ```
60
+
61
+ ### What it does (lts)
62
+
63
+ 1. Downloads and installs the latest LTS version of Node.js
64
+ 2. Switches to use the newly installed LTS version
65
+
66
+ Equivalent to running:
67
+
68
+ ```bash
69
+ nvm install --lts
70
+ nvm use --lts
71
+ ```
72
+
73
+ ### Example
74
+
75
+ ```bash
76
+ $ hlpr nvm lts
77
+ Downloading and installing node v20.11.0...
78
+ Now using node v20.11.0 (npm v10.2.4)
79
+ ```
80
+
81
+ ### Prerequisites
82
+
83
+ - nvm must be installed first (use `hlpr nvm install`)
84
+
85
+ ### Verify (lts)
86
+
87
+ ```bash
88
+ node --version # Should show the LTS version
89
+ npm --version # npm comes with Node.js
90
+ ```
@@ -0,0 +1,49 @@
1
+ # kill-port
2
+
3
+ Kill process(es) running on a specified port. Supports both Windows and Linux/macOS.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ hlpr process kill-port <port> [options]
9
+ ```
10
+
11
+ ## Arguments
12
+
13
+ - `port` - Port number (1-65535)
14
+
15
+ ## Options
16
+
17
+ - `-f, --force` - Force kill (SIGKILL on Linux, /F on Windows)
18
+ - `-v, --verbose` - Show verbose output
19
+ - `-h, --help` - Show help message
20
+
21
+ ## Examples
22
+
23
+ ```bash
24
+ # Kill process on port 3000
25
+ hlpr process kill-port 3000
26
+
27
+ # Force kill with verbose output
28
+ hlpr process kill-port 8080 --force --verbose
29
+
30
+ # Kill process on port 5432
31
+ hlpr process kill-port 5432 -v
32
+ ```
33
+
34
+ ## Platform Support
35
+
36
+ ### Windows
37
+ - Uses `netstat -ano` to find processes
38
+ - Uses `taskkill` to kill processes
39
+ - `-f/--force` flag uses `/F` switch (force termination)
40
+
41
+ ### Linux/macOS
42
+ - Uses `lsof` (preferred) or `netstat` to find processes
43
+ - Uses `kill` command to terminate processes
44
+ - `-f/--force` flag sends SIGKILL instead of SIGTERM
45
+
46
+ ## Exit Codes
47
+
48
+ - `0` - Success (all processes killed or no processes found)
49
+ - `1` - Failure (some processes could not be killed)
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/commands/process/kill-port/kill-port.ts
5
+ import { execSync, spawnSync } from "child_process";
6
+ import { platform } from "os";
7
+ function getProcessOnWindowsPort(port) {
8
+ try {
9
+ const output = execSync(`netstat -ano | findstr :${port}`, { encoding: "utf-8" });
10
+ const pids = [];
11
+ const lines = output.split(`
12
+ `);
13
+ for (const line of lines) {
14
+ const match = line.match(/\s+(\d+)\s*$/);
15
+ if (match) {
16
+ const pid = parseInt(match[1], 10);
17
+ if (pid > 0 && !pids.includes(pid)) {
18
+ pids.push(pid);
19
+ }
20
+ }
21
+ }
22
+ return pids;
23
+ } catch (error) {
24
+ return [];
25
+ }
26
+ }
27
+ function getProcessOnLinuxPort(port) {
28
+ try {
29
+ const output = execSync(`lsof -i :${port} -n -P`, { encoding: "utf-8" });
30
+ const pids = [];
31
+ const lines = output.split(`
32
+ `);
33
+ for (let i = 1;i < lines.length; i++) {
34
+ const parts = lines[i].trim().split(/\s+/);
35
+ if (parts.length > 1) {
36
+ const pid = parseInt(parts[1], 10);
37
+ if (!isNaN(pid) && !pids.includes(pid)) {
38
+ pids.push(pid);
39
+ }
40
+ }
41
+ }
42
+ return pids;
43
+ } catch {
44
+ try {
45
+ const output = execSync(`netstat -tulnp 2>/dev/null | grep :${port}`, { encoding: "utf-8" });
46
+ const pids = [];
47
+ const lines = output.split(`
48
+ `);
49
+ for (const line of lines) {
50
+ const match = line.match(/(\d+)\//);
51
+ if (match) {
52
+ const pid = parseInt(match[1], 10);
53
+ if (!pids.includes(pid)) {
54
+ pids.push(pid);
55
+ }
56
+ }
57
+ }
58
+ return pids;
59
+ } catch {
60
+ return [];
61
+ }
62
+ }
63
+ }
64
+ function killProcessOnWindows(pid, force, verbose) {
65
+ try {
66
+ const args = force ? ["/PID", pid.toString(), "/F"] : ["/PID", pid.toString()];
67
+ const result = spawnSync("taskkill", args, { encoding: "utf-8" });
68
+ if (result.status === 0) {
69
+ if (verbose)
70
+ console.log(`\u2713 Killed process ${pid}`);
71
+ return true;
72
+ } else {
73
+ if (verbose)
74
+ console.error(`\u2717 Failed to kill process ${pid}: ${result.stderr}`);
75
+ return false;
76
+ }
77
+ } catch (error) {
78
+ if (verbose)
79
+ console.error(`\u2717 Error killing process ${pid}: ${error}`);
80
+ return false;
81
+ }
82
+ }
83
+ function killProcessOnLinux(pid, force, verbose) {
84
+ try {
85
+ const signal = force ? "SIGKILL" : "SIGTERM";
86
+ const result = spawnSync("kill", [`-${signal}`, pid.toString()], { encoding: "utf-8" });
87
+ if (result.status === 0) {
88
+ if (verbose)
89
+ console.log(`\u2713 Killed process ${pid} with ${signal}`);
90
+ return true;
91
+ } else {
92
+ if (verbose)
93
+ console.error(`\u2717 Failed to kill process ${pid}: ${result.stderr}`);
94
+ return false;
95
+ }
96
+ } catch (error) {
97
+ if (verbose)
98
+ console.error(`\u2717 Error killing process ${pid}: ${error}`);
99
+ return false;
100
+ }
101
+ }
102
+ async function killPort(port, options = {}) {
103
+ const { force = false, verbose = false } = options;
104
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
105
+ throw new Error(`Invalid port number: ${port}. Port must be between 1 and 65535.`);
106
+ }
107
+ const os = platform();
108
+ let pids = [];
109
+ if (verbose)
110
+ console.log(`Searching for processes on port ${port} (${os})...`);
111
+ if (os === "win32") {
112
+ pids = getProcessOnWindowsPort(port);
113
+ } else {
114
+ pids = getProcessOnLinuxPort(port);
115
+ }
116
+ if (pids.length === 0) {
117
+ if (verbose)
118
+ console.log(`No processes found on port ${port}`);
119
+ return { killed: [], failed: [] };
120
+ }
121
+ if (verbose)
122
+ console.log(`Found ${pids.length} process(es) on port ${port}: ${pids.join(", ")}`);
123
+ const killed = [];
124
+ const failed = [];
125
+ for (const pid of pids) {
126
+ let success;
127
+ if (os === "win32") {
128
+ success = killProcessOnWindows(pid, force, verbose);
129
+ } else {
130
+ success = killProcessOnLinux(pid, force, verbose);
131
+ }
132
+ if (success) {
133
+ killed.push(pid);
134
+ } else {
135
+ failed.push(pid);
136
+ }
137
+ }
138
+ return { killed, failed };
139
+ }
140
+ if (import.meta.url.endsWith(process.argv[1]?.replace(/\\/g, "/"))) {
141
+ const args = process.argv.slice(2);
142
+ if (args.includes("--help") || args.includes("-h") || args.length === 0) {
143
+ console.log("Usage: kill-port <port> [options]");
144
+ console.log("Kill process(es) running on a specified port (Windows & Linux support)");
145
+ console.log();
146
+ console.log("Arguments:");
147
+ console.log(" port Port number (1-65535)");
148
+ console.log();
149
+ console.log("Options:");
150
+ console.log(" -f, --force Force kill (SIGKILL on Linux, /F on Windows)");
151
+ console.log(" -v, --verbose Show verbose output");
152
+ console.log(" -h, --help Show this help message");
153
+ console.log();
154
+ console.log("Examples:");
155
+ console.log(" hlpr process kill-port 3000");
156
+ console.log(" hlpr process kill-port 8080 --force");
157
+ console.log(" hlpr process kill-port 5432 -v");
158
+ process.exit(0);
159
+ }
160
+ const port = parseInt(args[0], 10);
161
+ const force = args.includes("-f") || args.includes("--force");
162
+ const verbose = args.includes("-v") || args.includes("--verbose");
163
+ killPort(port, { force, verbose }).then((result) => {
164
+ if (result.killed.length > 0) {
165
+ console.log(`Successfully killed ${result.killed.length} process(es) on port ${port}`);
166
+ }
167
+ if (result.failed.length > 0) {
168
+ console.error(`Failed to kill ${result.failed.length} process(es): ${result.failed.join(", ")}`);
169
+ process.exit(1);
170
+ }
171
+ if (result.killed.length === 0 && result.failed.length === 0) {
172
+ console.log(`No processes found on port ${port}`);
173
+ }
174
+ process.exit(0);
175
+ }).catch((error) => {
176
+ console.error("Error:", error.message);
177
+ process.exit(1);
178
+ });
179
+ }
180
+ var kill_port_default = { killPort };
181
+ export {
182
+ killPort,
183
+ kill_port_default as default
184
+ };
@@ -0,0 +1,58 @@
1
+ # list-port
2
+
3
+ List process(es) running on a specified port. Supports both Windows and Linux/macOS.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ hlpr process list-port <port> [options]
9
+ ```
10
+
11
+ ## Arguments
12
+
13
+ - `port` - Port number (1-65535)
14
+
15
+ ## Options
16
+
17
+ - `-v, --verbose` - Show verbose output
18
+ - `-h, --help` - Show help message
19
+
20
+ ## Examples
21
+
22
+ ```bash
23
+ # List processes on port 3000
24
+ hlpr process list-port 3000
25
+
26
+ # List with verbose output
27
+ hlpr process list-port 8080 -v
28
+
29
+ # List processes on port 5432
30
+ hlpr process list-port 5432
31
+ ```
32
+
33
+ ## Output Format
34
+
35
+ Displays a table with:
36
+ - **PID** - Process ID
37
+ - **STATE** - Connection state (LISTENING, ESTABLISHED, etc.)
38
+ - **COMMAND** - Process name/command
39
+
40
+ ## Platform Support
41
+
42
+ ### Windows
43
+ - Uses `netstat -ano` to find processes
44
+ - Uses `tasklist` to get process names
45
+ - Shows PID, state, and command
46
+
47
+ ### Linux/macOS
48
+ - Uses `lsof` (preferred) or `netstat` (fallback) to find processes
49
+ - Shows PID, state, and command name
50
+
51
+ ## Exit Codes
52
+
53
+ - `0` - Success (processes found)
54
+ - `1` - No processes found or error
55
+
56
+ ## See Also
57
+
58
+ - `hlpr process kill-port` - Kill processes on a port