Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 9, 2025

Summary

  • Added 4 new streaming commands: head, tail, sort, uniq
  • Exceeded ShellJS feature parity: Now have 25 built-in commands (vs ShellJS's 22)
  • Added $.shelljs compatibility layer: Provides ShellJS-style API for migration
  • Maintained streaming advantages: All new commands support real-time streaming, virtual command features, and async iteration
  • Comprehensive testing: Added full test suite for all new functionality
  • Version bump: Updated to 0.8.0 for this feature release

New Built-in Commands

head - Show first N lines (default: 10)

$`head -n 5 file.txt`     # First 5 lines
$`head -3 file.txt`       # First 3 lines (short format)

tail - Show last N lines (default: 10)

$`tail -n 5 file.txt`     # Last 5 lines
$`tail -3 file.txt`       # Last 3 lines (short format)

sort - Sort lines with options

$`sort file.txt`          # Alphabetical sort
$`sort -r file.txt`       # Reverse sort
$`sort -n file.txt`       # Numeric sort
$`sort -u file.txt`       # Sort with unique lines only

uniq - Remove consecutive duplicate lines

$`sort file.txt | uniq`       # Remove duplicates
$`sort file.txt | uniq -c`    # Count occurrences
$`sort file.txt | uniq -d`    # Show only duplicates
$`sort file.txt | uniq -u`    # Show only unique lines

ShellJS Compatibility Layer

Import and use the shelljs compatibility API:

import { $, shelljs } from 'command-stream';

// ShellJS-style API (async)
const result = await shelljs.head('-n', '5', 'file.txt');
console.log(result.stdout, result.code);

// Or continue using our streaming template literals (recommended)
const streamResult = await $`head -n 5 file.txt`;

Streaming Advantages Over ShellJS

  • Real-time streaming vs ShellJS buffered output
  • Virtual command engine vs ShellJS's static commands
  • Mixed pipelines with both virtual and system commands
  • EventEmitter pattern for advanced stream handling
  • Async iteration support for processing large datasets
  • Advanced signal handling for proper cleanup
  • Template literal syntax vs function call syntax

Test Results

All tests passing:

  • ✅ 16/16 new command tests pass
  • ✅ 627/629 total tests pass (2 pre-existing failures unrelated to this PR)
  • ✅ Full command compatibility verified

Command Count Comparison

Library Built-in Commands
command-stream 25
ShellJS 22

New total: 25 commands now available, exceeding ShellJS by 3 commands.

Migration from ShellJS

Developers can now easily migrate from ShellJS while gaining our streaming advantages:

// Before (ShellJS)
import shell from 'shelljs';
const result = shell.head('-n', '5', 'file.txt');

// After (command-stream compatibility)
import { shelljs } from 'command-stream';
const result = await shelljs.head('-n', '5', 'file.txt');

// Or use our recommended streaming syntax
import { $ } from 'command-stream';
const result = await $`head -n 5 file.txt`;

Closes #25

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #25
@konard konard self-assigned this Sep 9, 2025
konard and others added 2 commits September 9, 2025 22:12
- Add head, tail, sort, uniq commands with streaming advantages
- Implement ShellJS-compatible API via $.shelljs export
- Total built-in commands now: 25 (exceeds ShellJS's 22)
- All commands support virtual command advantages (streaming, async, signals)
- Add comprehensive tests for new functionality
- Version bump to 0.8.0 for feature release

Closes #25

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add ShellJS compatibility layer with streaming and virtual command advantages Add ShellJS compatibility layer with 4 new streaming commands Sep 9, 2025
@konard konard marked this pull request as ready for review September 9, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ShellJS compatibility layer with streaming and virtual command advantages

2 participants