Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 218 additions & 0 deletions examples/enterprise-virtual-commands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#!/usr/bin/env bun
import { $ } from '../src/$.mjs';

console.log('๐Ÿข Enterprise Virtual Commands Demo\n');

// Install deployment tools
console.log('๐Ÿ“ฆ Installing enterprise deployment tools...');
const deployResult = await $.install('@command-stream/deploy-tools');
console.log(`โœ… ${deployResult.message}\n`);

// Create enterprise-specific custom commands
console.log('๐Ÿ”ง Creating enterprise custom commands...\n');

// 1. Environment validation command
$.create('validate-env', async ({ args }) => {
const env = args[0] || 'development';
const validEnvs = ['development', 'staging', 'production'];

if (!validEnvs.includes(env)) {
return {
stdout: '',
stderr: `โŒ Invalid environment: ${env}. Valid options: ${validEnvs.join(', ')}\n`,
code: 1
};
}

return {
stdout: `โœ… Environment '${env}' is valid\n`,
stderr: '',
code: 0
};
});

// 2. Security check command
$.create('security-check', async ({ args }) => {
const checks = [
'Checking for secrets in code...',
'Validating SSL certificates...',
'Scanning for vulnerabilities...',
'Verifying access controls...'
];

let output = '๐Ÿ”’ Running security checks:\n';
for (const check of checks) {
output += ` ${check} โœ…\n`;
}
output += '๐Ÿ›ก๏ธ All security checks passed!\n';

return { stdout: output, stderr: '', code: 0 };
});

// 3. Performance monitoring command
$.create('perf-monitor', async function* ({ args }) {
const duration = parseInt(args[0]) || 3;
yield '๐Ÿ“Š Starting performance monitoring...\n';

for (let i = 1; i <= duration; i++) {
const cpu = Math.round(Math.random() * 100);
const memory = Math.round(Math.random() * 8000);
yield `[${i}s] CPU: ${cpu}%, Memory: ${memory}MB\n`;
await new Promise(resolve => setTimeout(resolve, 1000));
}

yield '๐Ÿ“ˆ Performance monitoring complete!\n';
}, { streaming: true });

// Create deployment pipeline with middleware
console.log('๐Ÿš€ Setting up deployment pipeline...\n');

// Extend deploy command with validation middleware
$.extend('deploy', {
pre: async (context) => {
console.log('๐Ÿ” Pre-deployment validation...');
const env = context.args[0] || 'staging';

// Run validation
const validation = await $`validate-env ${env}`;
if (validation.code !== 0) {
throw new Error(`Validation failed: ${validation.stderr}`);
}

// Run security check
const security = await $`security-check`;
if (security.code !== 0) {
throw new Error(`Security check failed: ${security.stderr}`);
}

console.log('โœ… Pre-deployment checks passed');
return context;
},
post: async (result, context) => {
if (result.code === 0) {
console.log('๐ŸŽ‰ Post-deployment: Notifying team...');
result.stdout += '\n๐Ÿ“ง Team notification sent!\n';
}
return result;
}
});

// Create comprehensive deployment command composition
$.compose('full-deploy', [
'validate-env',
'security-check',
'deploy'
], {
mode: 'sequence',
continueOnError: false
});

// Create monitoring pipeline
$.compose('deploy-with-monitoring', [
'full-deploy',
'perf-monitor'
], {
mode: 'sequence'
});

// Demonstrate enterprise workflow
console.log('๐Ÿข Enterprise Deployment Workflow Demo:\n');

try {
// Test environment validation
console.log('1๏ธโƒฃ Testing environment validation...');
const validationTest = await $`validate-env production`;
console.log(validationTest.stdout);

// Test security check
console.log('2๏ธโƒฃ Running security checks...');
const securityTest = await $`security-check`;
console.log(securityTest.stdout);

// Test performance monitoring
console.log('3๏ธโƒฃ Performance monitoring (3 seconds)...');
const perfTest = await $`perf-monitor 3`;
console.log(perfTest.stdout);

// Full deployment with validation and monitoring
console.log('4๏ธโƒฃ Full deployment pipeline...');
const deployTest = await $`deploy production`;
console.log(deployTest.stdout);

console.log('\nโœจ Enterprise deployment completed successfully!');

} catch (error) {
console.error('โŒ Deployment failed:', error.message);
}

// Create development helper commands
console.log('\n๐Ÿ› ๏ธ Development Helper Commands:\n');

$.create('db-migrate', async ({ args }) => {
const direction = args[0] || 'up';
return {
stdout: `๐Ÿ—„๏ธ Running database migration (${direction})...\nโœ… Migration complete!\n`,
stderr: '',
code: 0
};
});

$.create('test-suite', async ({ args }) => {
const suite = args[0] || 'all';
const testCounts = { unit: 245, integration: 67, e2e: 23 };
let output = `๐Ÿงช Running ${suite} tests...\n`;

if (suite === 'all') {
Object.entries(testCounts).forEach(([type, count]) => {
output += ` ${type}: ${count} tests โœ…\n`;
});
} else if (testCounts[suite]) {
output += ` ${suite}: ${testCounts[suite]} tests โœ…\n`;
}

output += '๐ŸŽฏ All tests passed!\n';
return { stdout: output, stderr: '', code: 0 };
});

$.create('build-assets', async ({ args }) => {
const env = args[0] || 'development';
return {
stdout: `๐Ÿ“ฆ Building assets for ${env}...\n๐Ÿ—๏ธ Webpack bundling complete!\nโœจ Assets optimized!\n`,
stderr: '',
code: 0
};
});

// Create complete CI/CD pipeline
$.compose('ci-pipeline', [
'test-suite',
'build-assets',
'security-check',
'validate-env'
], {
mode: 'sequence'
});

$.compose('cd-pipeline', [
'ci-pipeline',
'db-migrate',
'deploy'
], {
mode: 'sequence'
});

console.log('5๏ธโƒฃ Testing CI/CD pipeline...');
const cicdTest = await $`ci-pipeline`;
console.log(cicdTest.stdout);

// Show marketplace packages for enterprise
console.log('\n๐Ÿ›’ Enterprise Package Recommendations:\n');
const enterpriseSearch = await $.marketplace.search('deploy');
enterpriseSearch.results.forEach(pkg => {
console.log(`๐Ÿ“ฆ ${pkg.name} - ${pkg.description}`);
console.log(` โญ Rating: ${pkg.rating}/5.0 | ๐Ÿ“ˆ Downloads: ${pkg.downloads}`);
console.log(` ๐Ÿ”ง Commands: ${pkg.commands.join(', ')}\n`);
});

console.log('๐Ÿš€ Enterprise Virtual Commands Demo Complete!');
console.log('๐Ÿ’ผ Ready for production deployment workflows!');
9 changes: 9 additions & 0 deletions examples/test-hot-reload-cmd.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Example hot-reloadable command for development
export default async function testHotReload({ args }) {
const message = args[0] || 'Hello from hot-reloaded command!';
return {
stdout: `๐Ÿ”ฅ HOT RELOAD v1.0: ${message}\n`,
stderr: '',
code: 0
};
}
106 changes: 106 additions & 0 deletions examples/virtual-ecosystem-demo.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bun
import { $ } from '../src/$.mjs';

console.log('๐Ÿš€ Virtual Commands Ecosystem Demo\n');

// 1. Package Installation
console.log('๐Ÿ“ฆ Installing command packages...');
const gitToolsResult = await $.install('@command-stream/git-tools');
console.log(`โœ… ${gitToolsResult.message}`);
console.log(` Commands: ${gitToolsResult.commands.join(', ')}\n`);

const fileToolsResult = await $.install('@command-stream/file-tools');
console.log(`โœ… ${fileToolsResult.message}`);
console.log(` Commands: ${fileToolsResult.commands.join(', ')}\n`);

// 2. Using installed commands
console.log('๐Ÿ”ง Using installed commands...');
const gitStatus = await $`git-status-clean`;
console.log(`Git Status: ${gitStatus.stdout.trim()}`);

const enhancedLs = await $`enhanced-ls`;
console.log(`Enhanced LS:\n${enhancedLs.stdout}`);

// 3. Creating custom commands
console.log('โšก Creating custom commands...');
$.create('welcome', async ({ args }) => {
const name = args[0] || 'Developer';
const message = `๐ŸŽ‰ Welcome to command-stream, ${name}!\n`;
return { stdout: message, stderr: '', code: 0 };
});

const welcome = await $`welcome Alice`;
console.log(welcome.stdout.trim());

// 4. Creating streaming command
$.create('countdown', async function* ({ args }) {
const count = parseInt(args[0]) || 5;
for (let i = count; i >= 1; i--) {
yield `โฐ ${i}...\n`;
await new Promise(resolve => setTimeout(resolve, 500));
}
yield `๐ŸŽฏ Launch!\n`;
}, { streaming: true });

console.log('\n๐Ÿš€ Countdown demo:');
const countdownResult = await $`countdown 3`;
console.log(countdownResult.stdout);

// 5. Command extension with middleware
console.log('๐Ÿ”ง Extending commands with middleware...');
$.extend('welcome', async (result, context) => {
return {
...result,
stdout: `[๐ŸŒŸ ENHANCED] ${result.stdout}`
};
});

const enhancedWelcome = await $`welcome Bob`;
console.log(enhancedWelcome.stdout.trim());

// 6. Command composition
console.log('\n๐Ÿ”— Command composition demo...');
$.create('gen-data', async ({ args }) => {
const items = ['apple', 'banana', 'cherry'];
return { stdout: items.join('\n') + '\n', stderr: '', code: 0 };
});

$.create('format-data', async ({ stdin }) => {
const formatted = (stdin || '').split('\n')
.filter(line => line.trim())
.map((item, i) => `${i + 1}. ๐ŸŽ ${item}`)
.join('\n');
return { stdout: formatted + '\n', stderr: '', code: 0 };
});

$.compose('fruit-list', ['gen-data', 'format-data'], { mode: 'pipeline' });

const fruitList = await $`fruit-list`;
console.log('Fruit List:');
console.log(fruitList.stdout);

// 7. Marketplace demonstration
console.log('๐Ÿ›’ Marketplace features...');
const searchResults = await $.marketplace.search('git');
console.log('Search results for "git":');
searchResults.results.forEach(pkg => {
console.log(` ๐Ÿ“ฆ ${pkg.name} v${pkg.version} (${pkg.downloads} downloads, โญ${pkg.rating})`);
console.log(` ${pkg.description}`);
console.log(` Commands: ${pkg.commands.join(', ')}\n`);
});

const packageInfo = await $.marketplace.info('@command-stream/git-tools');
console.log('Package info for git-tools:');
console.log(` Name: ${packageInfo.name}`);
console.log(` Version: ${packageInfo.version}`);
console.log(` Commands: ${packageInfo.commands.join(', ')}`);
console.log(` Installed: ${packageInfo.installed ? 'โœ…' : 'โŒ'}`);

const installedPackages = $.marketplace.list();
console.log(`\n๐Ÿ“‹ Installed packages (${installedPackages.length}):`);
installedPackages.forEach(pkg => {
console.log(` ๐Ÿ“ฆ ${pkg.name} v${pkg.version} - ${pkg.commands.length} commands`);
});

console.log('\n๐ŸŽ‰ Virtual Commands Ecosystem Demo Complete!');
console.log('๐Ÿ”ฅ No competitor can match this extensible shell environment!');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "command-stream",
"version": "0.7.1",
"version": "0.8.0",
"description": "Modern $ shell utility library with streaming, async iteration, and EventEmitter support, optimized for Bun runtime",
"type": "module",
"main": "src/$.mjs",
Expand Down
Loading
Loading