Framework for transforming cascading style sheets (CSS) from left-to-right (LTR) to right-to-left (RTL)
—
RTLCSS provides a comprehensive command-line interface for batch processing CSS files, supporting various input/output methods and configuration options.
Transform CSS files from command line with various input and output options.
# Basic file transformation
rtlcss input.css output.css
# Auto-generate output filename (input.rtl.css)
rtlcss input.css
# Process from stdin to stdout
cat input.css | rtlcss -
# Read from stdin, write to file
rtlcss - output.css
# Process directory recursively
rtlcss -d input-dir output-dirComplete set of CLI options for controlling RTLCSS behavior.
# Help and version
rtlcss -h, --help # Display help message
rtlcss -v, --version # Display version number
# Configuration
rtlcss -c, --config PATH # Specify configuration file path
# Input/output options
rtlcss -, --stdin # Read from stdin stream
rtlcss -d, --directory # Process all *.css files recursively
rtlcss -e, --ext EXT # Set output file extension (default: .rtl.css)
# Processing options
rtlcss -s, --silent # Silent mode - suppress warnings and infoUsage Examples:
# Display help
rtlcss --help
# Show version
rtlcss --version
# Use custom config file
rtlcss -c ./my-rtlcss-config.json styles.css styles.rtl.css
# Process directory with custom extension
rtlcss -d -e .arabic.css ./src/styles ./dist/styles
# Silent processing
rtlcss -s input.css output.css
# Process from stdin in silent mode
cat styles.css | rtlcss -s - > output.rtl.cssProcess entire directories of CSS files recursively.
# Process directory recursively
rtlcss -d SOURCE_DIR DEST_DIR
# Process directory with custom extension
rtlcss -d -e .rtl.css SOURCE_DIR DEST_DIR
# Process current directory
rtlcss -d . ./rtl-outputDirectory Processing Examples:
# Basic directory processing
rtlcss -d ./src/css ./dist/css
# Preserve directory structure
# Input: src/css/components/header.css
# Output: dist/css/components/header.rtl.css
rtlcss -d ./src/css ./dist/css
# Custom extension
rtlcss -d -e .arabic.css ./styles ./arabic-styles
# Process with config
rtlcss -c .rtlcssrc -d ./src ./distUse configuration files with the CLI for consistent processing options.
# Use specific config file
rtlcss -c CONFIG_FILE input.css output.css
# Use config with directory processing
rtlcss -c CONFIG_FILE -d SOURCE_DIR DEST_DIRConfiguration File Examples:
.rtlcssrc:
{
"options": {
"autoRename": true,
"clean": false,
"stringMap": [
{
"name": "theme-names",
"search": ["light", "dark"],
"replace": ["فاتح", "داكن"],
"priority": 100
}
]
}
}Usage:
rtlcss -c .rtlcssrc styles.css styles.rtl.cssProcess CSS through standard input and output streams.
# Read from stdin, write to stdout
rtlcss -
# Read from stdin, write to file
rtlcss - output.css
# Pipe operations
cat input.css | rtlcss - > output.css
# Process with other tools
cat input.css | rtlcss - | gzip > output.css.gzStdin/Stdout Examples:
# Simple pipe
echo ".test { float: left; }" | rtlcss -
# Output: .test { float: right; }
# Process multiple files through stdin
find ./css -name "*.css" -exec cat {} \; | rtlcss - > combined.rtl.css
# Integration with build tools
webpack --mode production | rtlcss - > bundle.rtl.css
# Process with preprocessing
sass input.scss | rtlcss - > output.rtl.cssCLI provides specific exit codes for different error conditions.
# Exit codes
# 0: Success
# 1: Argument error (invalid options, missing files)
# 2: Processing error (CSS parsing, transformation errors)Error Handling Examples:
# Check exit code
rtlcss input.css output.css
echo $? # 0 for success, 1 for argument error, 2 for processing error
# Handle errors in scripts
if rtlcss -c config.json input.css output.css; then
echo "RTL conversion successful"
else
echo "RTL conversion failed with exit code $?"
exit 1
fi
# Silent error handling
rtlcss -s input.css output.css 2>/dev/null
if [ $? -eq 0 ]; then
echo "Success"
fiCommon integration patterns with build tools and workflows.
Makefile Integration:
# Makefile
.PHONY: rtl
rtl:
rtlcss -d ./src/css ./dist/css-rtl
rtl-clean:
rtlcss -c .rtlcssrc -d ./src/css ./dist/css-rtlNPM Scripts:
{
"scripts": {
"build:rtl": "rtlcss -d ./src/styles ./dist/styles-rtl",
"build:rtl:clean": "rtlcss -c .rtlcssrc -d ./src/styles ./dist/styles-rtl",
"watch:rtl": "chokidar './src/styles/**/*.css' -c 'rtlcss {path} ./dist/styles-rtl/{name}.rtl.css'"
}
}Shell Script Integration:
#!/bin/bash
# build-rtl.sh
set -e
CONFIG_FILE=".rtlcssrc"
SOURCE_DIR="./src/styles"
OUTPUT_DIR="./dist/styles-rtl"
echo "Building RTL stylesheets..."
if [ -f "$CONFIG_FILE" ]; then
rtlcss -c "$CONFIG_FILE" -d "$SOURCE_DIR" "$OUTPUT_DIR"
else
echo "Warning: No config file found, using defaults"
rtlcss -d "$SOURCE_DIR" "$OUTPUT_DIR"
fi
echo "RTL build complete"CI/CD Integration:
# GitHub Actions example
name: Build RTL CSS
on: [push]
jobs:
build-rtl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- run: npm install rtlcss
- run: npx rtlcss -d ./src/css ./dist/css-rtl
- run: npx rtlcss -c .rtlcssrc -e .arabic.css ./src/css ./dist/css-arabicCLI automatically searches for configuration files in the following order:
-c option.rtlcssrc in current directory and parent directories.rtlcss.json in current directory and parent directoriesrtlcssConfig property in package.json# Automatic config discovery
rtlcss input.css output.css # Will find and use .rtlcssrc if present
# Override automatic discovery
rtlcss -c /path/to/specific/config.json input.css output.cssInstall with Tessl CLI
npx tessl i tessl/npm-rtlcss