Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.2] - 2025-09-02

### Fixed

- Allows exporting a large amount of redirects.

## [1.0.1] - 2024-09-10

### Fixed

- Use http POST instead of graphql client to list redirects
Expand Down
308 changes: 229 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,115 +1,265 @@
# VTEX CLI Plugin Redirects
# VTEX CLI Plugin - Redirects

Extend the `vtex` toolbelt!
> 🚀 High-performance redirect management for VTEX IO

## Developing

1. Clone `vtex/toolbelt` and follow the steps on the Contributing section.
2. Clone/Create a plugin with this template.
3. Change the template name under this project's `package.json`.
4. Run `yarn link` on this project.
5. Now run `vtex link @vtex/cli-plugin-template` (or the new name) on the `vtex/toolbelt` project.
6. Run `yarn watch` on the `vtex/toolbelt`
7. Test the command on a VTEX IO app with `vtex-test hello`

For more information, read [Ocliff Docs](https://oclif.io/docs/introduction).
A powerful VTEX CLI plugin for managing URL redirects in your VTEX account and workspace. Features optimized CSV operations, parallel processing, and memory-efficient file handling for large datasets.

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
![npm](https://img.shields.io/npm/v/@vtex/cli-plugin-redirects)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ✨ Features

- **Export** all redirects to CSV with streaming optimization
- **Import** redirects from CSV files with batch processing
- **Delete** redirects using CSV file input
- **Memory efficient** - handles large datasets without OOM issues
- **Parallel processing** - configurable concurrency for optimal performance
- **Resume support** - automatically recovers from interruptions
- **Progress tracking** - real-time progress indicators

## 📦 Installation

<!-- toc -->
* [VTEX CLI Plugin Redirects](#vtex-cli-plugin-redirects)
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->
```sh-session
$ npm install -g @vtex/cli-plugin-redirects
$ oclif-example COMMAND
running command...
$ oclif-example (-v|--version|version)
@vtex/cli-plugin-redirects/1.0.1 linux-x64 node-v20.18.3
$ oclif-example --help [COMMAND]
USAGE
$ oclif-example COMMAND
...
### Install the Plugin

```bash
# Install the plugin to your VTEX CLI
vtex plugins install @vtex/cli-plugin-redirects
```
<!-- usagestop -->

# Commands
### Development Setup

For development or local testing:

<!-- commands -->
* [`oclif-example redirects:delete CSVPATH`](#oclif-example-redirectsdelete-csvpath)
* [`oclif-example redirects:export CSVPATH`](#oclif-example-redirectsexport-csvpath)
* [`oclif-example redirects:import CSVPATH`](#oclif-example-redirectsimport-csvpath)
```bash
# Clone the repository
git clone https://github.com/vtex/cli-plugin-redirects.git
cd cli-plugin-redirects

## `oclif-example redirects:delete CSVPATH`
# Install dependencies
yarn install

Deletes redirects from the current account and workspace.
# Build the plugin
yarn build

# Link for local development
vtex plugins link
```
USAGE
$ oclif-example redirects:delete CSVPATH

ARGUMENTS
CSVPATH CSV file containing the URL paths to delete.
## 🚀 Commands

### `vtex redirects export [CSV_FILE]`

Exports all redirects from the current account and workspace to a CSV file.

OPTIONS
-h, --help Shows this help message.
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
**Features:**

EXAMPLE
vtex redirects delete csvPath
- Memory-efficient streaming export
- Handles millions of redirects without OOM
- Configurable concurrency and batch processing
- Automatic resume on interruption

```bash
# Basic export
vtex redirects export my-redirects.csv

# With performance tuning
EXPORT_CONCURRENCY=10 EXPORT_BATCH_SIZE=200 vtex redirects export large-export.csv
```

**CSV Format:**

```csv
from,to,type,endDate,binding
/old-page,/new-page,PERMANENT,,
/temporary,/temp-new,TEMPORARY,2024-12-31,
```

_See code: [build/commands/redirects/delete.ts](https://github.com/vtex/cli-plugin-redirects/blob/v1.0.1/build/commands/redirects/delete.ts)_
**Environment Variables:**

- `EXPORT_CONCURRENCY` - Number of parallel processors (default: 5)
- `EXPORT_BATCH_SIZE` - CSV rows per write batch (default: 100)

## `oclif-example redirects:export CSVPATH`
### `vtex redirects import [CSV_FILE]`

Imports redirects from a CSV file to the current account and workspace.

Exports all redirects defined in the current account and workspace to a CSV file.
```bash
# Import redirects
vtex redirects import my-redirects.csv

# Import with reset (removes all existing redirects first)
vtex redirects import my-redirects.csv --reset
```
USAGE
$ oclif-example redirects:export CSVPATH

ARGUMENTS
CSVPATH Name of the CSV file.
**Options:**

OPTIONS
-h, --help Shows this help message.
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
- `-r, --reset` - Remove all existing redirects before importing
- `-v, --verbose` - Show debug level logs
- `--trace` - Trace all requests to VTEX IO

EXAMPLE
vtex redirects export csvPath
### `vtex redirects delete [CSV_FILE]`

Deletes redirects using paths specified in a CSV file.

```bash
# Delete specific redirects
vtex redirects delete redirects-to-delete.csv
```

_See code: [build/commands/redirects/export.ts](https://github.com/vtex/cli-plugin-redirects/blob/v1.0.1/build/commands/redirects/export.ts)_
**CSV Format for deletion:**

## `oclif-example redirects:import CSVPATH`
```csv
from
/page-to-remove
/another-old-page
```

Imports redirects from a CSV file to the current account and workspace.
## 🔧 Performance Configuration

### Optimizing Export Performance

For large datasets, tune these environment variables:

```bash
# High-performance setup for large exports
export EXPORT_CONCURRENCY=10 # More parallel processors
export EXPORT_BATCH_SIZE=500 # Larger write batches

# Memory-constrained setup
export EXPORT_CONCURRENCY=3 # Fewer parallel processors
export EXPORT_BATCH_SIZE=50 # Smaller write batches
```
USAGE
$ oclif-example redirects:import CSVPATH

ARGUMENTS
CSVPATH Name of the CSV file.
### Memory Usage Guidelines

| Dataset Size | Concurrency | Batch Size | Memory Usage |
| ------------------- | ----------- | ------------- | ------------ |
| < 100K redirects | 5 (default) | 100 (default) | ~50MB |
| 100K - 1M redirects | 8 | 200 | ~100MB |
| > 1M redirects | 10 | 500 | ~200MB |

## 📋 CSV File Format

### Export Format

The export command generates CSV files with these columns:

| Column | Description | Example |
| --------- | -------------------------- | -------------------------- |
| `from` | Source URL path | `/old-product` |
| `to` | Target URL path | `/new-product` |
| `type` | Redirect type | `PERMANENT` or `TEMPORARY` |
| `endDate` | Expiration date (optional) | `2024-12-31` |
| `binding` | Store binding (optional) | `store-1` |

### Import Requirements

- CSV files must include at minimum: `from`, `to` columns
- `type` defaults to `PERMANENT` if not specified
- Encoding should be UTF-8
- Maximum file size: No limit (streams processing)

## 🛠️ Development

### Setup

OPTIONS
-h, --help Shows this help message.
-r, --reset Removes all redirects previously defined.
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
```bash
# Clone and setup
git clone https://github.com/vtex/cli-plugin-redirects.git
cd cli-plugin-redirects
yarn install

EXAMPLE
vtex redirects import csvPath
# Development workflow
yarn watch # Auto-rebuild on changes
yarn test # Run tests
yarn lint # Check code style
yarn build # Production build
```

_See code: [build/commands/redirects/import.ts](https://github.com/vtex/cli-plugin-redirects/blob/v1.0.1/build/commands/redirects/import.ts)_
<!-- commandsstop -->
### Testing

```bash
# Run all tests
yarn test

# Run with coverage
yarn test --coverage

# Test specific command
vtex redirects export test-export.csv --verbose
```

## 🐛 Troubleshooting

### Common Issues

**Out of Memory Errors**

```bash
# Reduce concurrency and batch size
export EXPORT_CONCURRENCY=3
export EXPORT_BATCH_SIZE=50
```

**Network Timeouts**

```bash
# Use verbose mode to see detailed logs
vtex redirects export file.csv --verbose
```

**CSV Format Errors**

- Ensure CSV has required columns (`from`, `to`)
- Check for proper UTF-8 encoding
- Validate no empty required fields

### Debug Mode

Enable verbose logging for detailed information:

```bash
vtex redirects export file.csv --verbose --trace
```

## 📊 Performance Benchmarks

| Operation | Dataset Size | Time | Memory |
| --------- | -------------- | ------- | ------ |
| Export | 100K redirects | ~2 min | ~50MB |
| Export | 1M redirects | ~15 min | ~100MB |
| Import | 100K redirects | ~5 min | ~30MB |
| Delete | 10K redirects | ~30 sec | ~20MB |

_Benchmarks measured on standard cloud infrastructure_

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Code Style

This project uses:

- **ESLint** for code linting
- **Prettier** for code formatting
- **TypeScript** for type safety

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🆘 Support

- **Issues**: [GitHub Issues](https://github.com/vtex/cli-plugin-redirects/issues)
- **VTEX Help**: [VTEX Help Center](https://help.vtex.com)
- **Developer Docs**: [VTEX IO Documentation](https://developers.vtex.com)

---

Made with ❤️ by the VTEX team
Loading
Loading