Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:04:14 +08:00
commit 70c36b5eff
248 changed files with 47482 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# Create oclif command from template
# Usage: ./create-command.sh <command-name> <template-type>
# Template types: basic, advanced, async
set -e
COMMAND_NAME="$1"
TEMPLATE_TYPE="${2:-basic}"
if [ -z "$COMMAND_NAME" ]; then
echo "Error: Command name is required"
echo "Usage: ./create-command.sh <command-name> <template-type>"
echo "Template types: basic, advanced, async"
exit 1
fi
# Validate template type
if [[ ! "$TEMPLATE_TYPE" =~ ^(basic|advanced|async)$ ]]; then
echo "Error: Invalid template type. Must be: basic, advanced, or async"
exit 1
fi
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE_DIR="$(dirname "$SCRIPT_DIR")/templates"
# Determine output directory
if [ -d "src/commands" ]; then
OUTPUT_DIR="src/commands"
elif [ -d "commands" ]; then
OUTPUT_DIR="commands"
else
echo "Error: Cannot find commands directory. Are you in the CLI project root?"
exit 1
fi
# Convert command name to proper format
# e.g., "my-command" -> "MyCommand"
COMMAND_CLASS=$(echo "$COMMAND_NAME" | sed -r 's/(^|-)([a-z])/\U\2/g')
# Determine output file path
OUTPUT_FILE="$OUTPUT_DIR/${COMMAND_NAME}.ts"
# Check if file already exists
if [ -f "$OUTPUT_FILE" ]; then
echo "Error: Command file already exists: $OUTPUT_FILE"
exit 1
fi
# Select template file
TEMPLATE_FILE="$TEMPLATE_DIR/command-${TEMPLATE_TYPE}.ts"
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "Error: Template file not found: $TEMPLATE_FILE"
exit 1
fi
# Create command file from template
echo "Creating command from template: $TEMPLATE_TYPE"
cp "$TEMPLATE_FILE" "$OUTPUT_FILE"
# Replace placeholders
sed -i "s/{{COMMAND_NAME}}/$COMMAND_CLASS/g" "$OUTPUT_FILE"
sed -i "s/{{DESCRIPTION}}/Command description for $COMMAND_NAME/g" "$OUTPUT_FILE"
echo "✓ Created command: $OUTPUT_FILE"
echo ""
echo "Next steps:"
echo " 1. Edit the command: $OUTPUT_FILE"
echo " 2. Update the description and flags"
echo " 3. Implement the run() method"
echo " 4. Build: npm run build"
echo " 5. Test: npm test"
echo ""
echo "Run the command:"
echo " ./bin/run.js $COMMAND_NAME --help"

View File

@@ -0,0 +1,127 @@
#!/usr/bin/env bash
# Create oclif plugin structure
# Usage: ./create-plugin.sh <plugin-name>
set -e
PLUGIN_NAME="$1"
if [ -z "$PLUGIN_NAME" ]; then
echo "Error: Plugin name is required"
echo "Usage: ./create-plugin.sh <plugin-name>"
exit 1
fi
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE_DIR="$(dirname "$SCRIPT_DIR")/templates"
# Determine output directory
PLUGIN_DIR="plugin-$PLUGIN_NAME"
if [ -d "$PLUGIN_DIR" ]; then
echo "Error: Plugin directory already exists: $PLUGIN_DIR"
exit 1
fi
echo "Creating plugin: $PLUGIN_NAME"
# Create directory structure
mkdir -p "$PLUGIN_DIR/src/commands"
mkdir -p "$PLUGIN_DIR/src/hooks"
mkdir -p "$PLUGIN_DIR/test"
# Copy package.json template
cp "$TEMPLATE_DIR/plugin-package.json" "$PLUGIN_DIR/package.json"
# Replace placeholders in package.json
sed -i "s/{{PLUGIN_NAME}}/$PLUGIN_NAME/g" "$PLUGIN_DIR/package.json"
sed -i "s/{{DESCRIPTION}}/Plugin for $PLUGIN_NAME/g" "$PLUGIN_DIR/package.json"
sed -i "s/{{AUTHOR}}/Your Name/g" "$PLUGIN_DIR/package.json"
sed -i "s/{{GITHUB_USER}}/yourusername/g" "$PLUGIN_DIR/package.json"
# Copy TypeScript config
cp "$TEMPLATE_DIR/tsconfig.json" "$PLUGIN_DIR/tsconfig.json"
# Copy ESLint config
cp "$TEMPLATE_DIR/.eslintrc.json" "$PLUGIN_DIR/.eslintrc.json"
# Create plugin command
cp "$TEMPLATE_DIR/plugin-command.ts" "$PLUGIN_DIR/src/commands/$PLUGIN_NAME.ts"
sed -i "s/{{PLUGIN_NAME}}/$PLUGIN_NAME/g" "$PLUGIN_DIR/src/commands/$PLUGIN_NAME.ts"
sed -i "s/{{COMMAND_NAME}}/main/g" "$PLUGIN_DIR/src/commands/$PLUGIN_NAME.ts"
sed -i "s/{{COMMAND_CLASS}}/Main/g" "$PLUGIN_DIR/src/commands/$PLUGIN_NAME.ts"
sed -i "s/{{DESCRIPTION}}/Main plugin command/g" "$PLUGIN_DIR/src/commands/$PLUGIN_NAME.ts"
# Create hooks
cp "$TEMPLATE_DIR/plugin-hooks.ts" "$PLUGIN_DIR/src/hooks/init.ts"
sed -i "s/{{PLUGIN_NAME}}/$PLUGIN_NAME/g" "$PLUGIN_DIR/src/hooks/init.ts"
# Create index.ts
cat > "$PLUGIN_DIR/src/index.ts" << EOF
export { default as init } from './hooks/init'
EOF
# Create README
cat > "$PLUGIN_DIR/README.md" << EOF
# @mycli/plugin-$PLUGIN_NAME
Plugin for mycli: $PLUGIN_NAME
## Installation
\`\`\`bash
mycli plugins:install @mycli/plugin-$PLUGIN_NAME
\`\`\`
## Usage
\`\`\`bash
mycli $PLUGIN_NAME:main --help
\`\`\`
## Commands
<!-- commands -->
<!-- commandsstop -->
## Development
\`\`\`bash
npm install
npm run build
npm test
\`\`\`
## License
MIT
EOF
# Create .gitignore
cat > "$PLUGIN_DIR/.gitignore" << EOF
*-debug.log
*-error.log
*.tgz
.DS_Store
/.nyc_output
/dist
/lib
/package-lock.json
/tmp
node_modules
oclif.manifest.json
tsconfig.tsbuildinfo
EOF
echo "✓ Created plugin structure: $PLUGIN_DIR"
echo ""
echo "Next steps:"
echo " cd $PLUGIN_DIR"
echo " npm install"
echo " npm run build"
echo " npm test"
echo ""
echo "To install plugin locally:"
echo " mycli plugins:link $PWD/$PLUGIN_DIR"

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Generate oclif documentation
# Usage: ./generate-docs.sh
set -e
echo "Generating oclif documentation..."
# Check if oclif is installed
if ! command -v oclif &> /dev/null; then
echo "Error: oclif CLI not found. Install with: npm install -g oclif"
exit 1
fi
# Generate manifest
echo "→ Generating command manifest..."
oclif manifest
# Generate README
echo "→ Generating README..."
oclif readme
echo "✓ Documentation generated successfully"
echo ""
echo "Generated files:"
echo " - oclif.manifest.json (command metadata)"
echo " - README.md (updated with command reference)"

View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Validate oclif command structure
# Usage: ./validate-command.sh <command-file>
set -e
COMMAND_FILE="$1"
if [ -z "$COMMAND_FILE" ]; then
echo "Error: Command file path is required"
echo "Usage: ./validate-command.sh <command-file>"
exit 1
fi
if [ ! -f "$COMMAND_FILE" ]; then
echo "Error: Command file not found: $COMMAND_FILE"
exit 1
fi
echo "Validating command: $COMMAND_FILE"
# Check for required imports
if ! grep -q "from '@oclif/core'" "$COMMAND_FILE"; then
echo "✗ Missing import from @oclif/core"
exit 1
fi
echo "✓ Has @oclif/core import"
# Check for Command class
if ! grep -q "extends Command" "$COMMAND_FILE"; then
echo "✗ Missing 'extends Command'"
exit 1
fi
echo "✓ Extends Command class"
# Check for description
if ! grep -q "static description" "$COMMAND_FILE"; then
echo "⚠ Warning: Missing static description"
else
echo "✓ Has static description"
fi
# Check for examples
if ! grep -q "static examples" "$COMMAND_FILE"; then
echo "⚠ Warning: Missing static examples"
else
echo "✓ Has static examples"
fi
# Check for run method
if ! grep -q "async run()" "$COMMAND_FILE"; then
echo "✗ Missing async run() method"
exit 1
fi
echo "✓ Has async run() method"
# Check for proper flag access
if grep -q "this.parse(" "$COMMAND_FILE"; then
echo "✓ Properly parses flags"
else
echo "⚠ Warning: May not be parsing flags correctly"
fi
# Check TypeScript
if command -v tsc &> /dev/null; then
echo "→ Checking TypeScript compilation..."
if tsc --noEmit "$COMMAND_FILE" 2>/dev/null; then
echo "✓ TypeScript compilation successful"
else
echo "⚠ Warning: TypeScript compilation has issues"
fi
fi
echo ""
echo "✓ Command validation complete"

View File

@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# Validate oclif plugin structure
# Usage: ./validate-plugin.sh <plugin-directory>
set -e
PLUGIN_DIR="${1:-.}"
if [ ! -d "$PLUGIN_DIR" ]; then
echo "Error: Plugin directory not found: $PLUGIN_DIR"
exit 1
fi
echo "Validating plugin: $PLUGIN_DIR"
# Check for package.json
if [ ! -f "$PLUGIN_DIR/package.json" ]; then
echo "✗ Missing package.json"
exit 1
fi
echo "✓ Has package.json"
# Check for oclif configuration in package.json
if ! grep -q '"oclif"' "$PLUGIN_DIR/package.json"; then
echo "✗ Missing oclif configuration in package.json"
exit 1
fi
echo "✓ Has oclif configuration"
# Check for commands directory
if [ ! -d "$PLUGIN_DIR/src/commands" ]; then
echo "⚠ Warning: Missing src/commands directory"
else
echo "✓ Has src/commands directory"
# Check for at least one command
COMMAND_COUNT=$(find "$PLUGIN_DIR/src/commands" -name "*.ts" | wc -l)
if [ "$COMMAND_COUNT" -eq 0 ]; then
echo "⚠ Warning: No commands found"
else
echo "✓ Has $COMMAND_COUNT command(s)"
fi
fi
# Check for hooks directory (optional)
if [ -d "$PLUGIN_DIR/src/hooks" ]; then
echo "✓ Has src/hooks directory"
HOOK_COUNT=$(find "$PLUGIN_DIR/src/hooks" -name "*.ts" | wc -l)
echo " ($HOOK_COUNT hook(s))"
fi
# Check for test directory
if [ ! -d "$PLUGIN_DIR/test" ]; then
echo "⚠ Warning: Missing test directory"
else
echo "✓ Has test directory"
# Check for test files
TEST_COUNT=$(find "$PLUGIN_DIR/test" -name "*.test.ts" | wc -l)
if [ "$TEST_COUNT" -eq 0 ]; then
echo "⚠ Warning: No test files found"
else
echo "✓ Has $TEST_COUNT test file(s)"
fi
fi
# Check for TypeScript config
if [ ! -f "$PLUGIN_DIR/tsconfig.json" ]; then
echo "⚠ Warning: Missing tsconfig.json"
else
echo "✓ Has tsconfig.json"
fi
# Check for README
if [ ! -f "$PLUGIN_DIR/README.md" ]; then
echo "⚠ Warning: Missing README.md"
else
echo "✓ Has README.md"
fi
# Check dependencies in package.json
if grep -q '"@oclif/core"' "$PLUGIN_DIR/package.json"; then
echo "✓ Has @oclif/core dependency"
else
echo "✗ Missing @oclif/core dependency"
fi
# Check if plugin can be built
if [ -f "$PLUGIN_DIR/package.json" ]; then
if grep -q '"build"' "$PLUGIN_DIR/package.json"; then
echo "✓ Has build script"
else
echo "⚠ Warning: Missing build script"
fi
fi
echo ""
echo "✓ Plugin validation complete"

View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Validate test coverage for oclif CLI
# Usage: ./validate-tests.sh
set -e
echo "Validating test coverage..."
# Check if test directory exists
if [ ! -d "test" ]; then
echo "✗ Missing test directory"
exit 1
fi
echo "✓ Has test directory"
# Count test files
TEST_COUNT=$(find test -name "*.test.ts" | wc -l)
if [ "$TEST_COUNT" -eq 0 ]; then
echo "✗ No test files found"
exit 1
fi
echo "✓ Has $TEST_COUNT test file(s)"
# Count command files
if [ -d "src/commands" ]; then
COMMAND_COUNT=$(find src/commands -name "*.ts" | wc -l)
echo " $COMMAND_COUNT command file(s) in src/commands"
# Check if each command has tests
for cmd in src/commands/*.ts; do
CMD_NAME=$(basename "$cmd" .ts)
if [ ! -f "test/commands/$CMD_NAME.test.ts" ]; then
echo "⚠ Warning: No test for command: $CMD_NAME"
fi
done
fi
# Run tests if available
if command -v npm &> /dev/null && grep -q '"test"' package.json; then
echo ""
echo "→ Running tests..."
if npm test; then
echo "✓ All tests passed"
else
echo "✗ Some tests failed"
exit 1
fi
fi
# Check for test coverage script
if grep -q '"test:coverage"' package.json; then
echo ""
echo "→ Checking test coverage..."
npm run test:coverage
fi
echo ""
echo "✓ Test validation complete"