BRANDING FUNCTION REFERENCE - nself-org/cli GitHub Wiki
Complete reference of all 36 functions implemented in the branding system.
File: /Users/admin/Sites/nself/src/lib/whitelabel/branding.sh
Total Functions: 36
Validates brand name format
-
Parameters:
$1- Brand name - Returns: 0 if valid, 1 if invalid
- Validation: Alphanumeric + spaces, hyphens, underscores
Validates tenant ID format
-
Parameters:
$1- Tenant ID - Returns: 0 if valid, 1 if invalid
- Validation: Lowercase alphanumeric + hyphens
Validates logo type is supported
-
Parameters:
$1- Logo type (main, icon, email, favicon) - Returns: 0 if valid, 1 if invalid
Validates file size is within limits
-
Parameters:
$1- File path,$2- Max size in MB - Returns: 0 if valid, 1 if too large
Validates file extension is allowed
-
Parameters:
$1- File path,$2- Allowed extensions (space-separated) - Returns: 0 if valid, 1 if invalid
Validates file MIME type matches extension
-
Parameters:
$1- File path - Returns: 0 if valid, 1 if mismatch
-
Uses:
filecommand for detection
Validates string length is within bounds
-
Parameters:
$1- String,$2- Min length,$3- Max length - Returns: 0 if valid, 1 if invalid
Scans CSS for security vulnerabilities
-
Parameters:
$1- CSS file path - Returns: 0 (always, but prints warnings)
- Checks: External URLs, @import, expression()
Validates hex color format
-
Parameters:
$1- Color code - Returns: 0 if valid, 1 if invalid
- Format: #RGB or #RRGGBB
Validates color palette for accessibility
-
Parameters:
$1- Primary color,$2- Secondary color,$3- Background color (optional) - Returns: 0 if valid, 1 if invalid
- Checks: Hex format, color similarity
Escapes HTML special characters
-
Parameters:
$1- String to escape - Returns: Escaped string via stdout
- Escapes: <, >, &, ", '
Escapes JSON special characters
-
Parameters:
$1- String to escape - Returns: Escaped string via stdout
- Escapes: , ", newlines
Initializes the branding system
-
Parameters:
$1- Tenant ID (optional, default: "default") - Returns: 0 on success
- Creates: Directory structure, default config, .gitignore
Creates a new brand
-
Parameters:
$1- Brand name,$2- Tenant ID (optional),$3- Tagline (optional),$4- Description (optional) - Returns: 0 on success, 1 on error
- Actions: Updates config, creates version backup
Updates existing brand information
-
Parameters:
--name,--tagline,--description(at least one required) - Returns: 0 on success, 1 on error
- Actions: Updates specified fields, creates version backup
Deletes brand with confirmation
-
Parameters:
$1- Tenant ID (optional) - Returns: 0 on success
- Actions: Prompts for confirmation, creates final backup, removes directory
Sets brand color palette
-
Parameters:
--primary,--secondary,--accent,--background,--text(at least one required) - Returns: 0 on success, 1 on error
- Actions: Validates colors, updates config, generates CSS variables
Sets brand font families
-
Parameters:
--primary,--secondary,--code(at least one required) - Returns: 0 on success, 1 on error
- Actions: Updates config, generates CSS variables
Sets typography settings (sizes, weights, line heights)
-
Parameters:
--base-size,--h1-size,--h2-size,--normal-weight,--bold-weight,--line-height - Returns: 0 on success, 1 on error
- Actions: Updates typography config, generates CSS variables
Uploads custom font file
-
Parameters:
$1- Font file path,$2- Font name (optional, default: "custom") - Returns: 0 on success, 1 on error
- Validation: Format (WOFF, WOFF2, TTF, OTF), Size (1MB max)
- Actions: Validates, copies with versioning, updates config
Uploads logo file (internal implementation)
-
Parameters:
$1- Logo file path,$2- Logo type (main, icon, email, favicon) - Returns: 0 on success, 1 on error
- Validation: Format, Size (5MB max), MIME type
- Actions: Validates, copies with versioning, creates symlink, updates config
Uploads logo file (user-facing wrapper)
-
Parameters:
$1- Logo file path,--type <type> - Returns: 0 on success, 1 on error
-
Calls:
upload_brand_logo()
Lists all configured logos
- Returns: 0
- Output: Logo types and filenames
Removes a logo
-
Parameters:
$1- Logo type - Returns: 0 on success
- Actions: Deletes file, removes symlink, updates config
Sets custom CSS file
-
Parameters:
$1- CSS file path - Returns: 0 on success, 1 on error
- Validation: Extension (.css), Size (2MB max), Syntax (balanced braces)
- Security: Scans for vulnerabilities
- Actions: Validates, copies with versioning, creates symlink, updates config
Removes custom CSS
- Returns: 0 on success
- Actions: Deletes file, removes symlink, updates config
Generates CSS variables from configuration
- Returns: 0 on success, 1 on error
-
Output:
branding/css/variables.css - Variables: Colors, fonts, sizes, weights, line heights
Displays branding preview
- Returns: 0
- Output: Brand name, colors, fonts, logos, update timestamp
Lists all configured tenants
- Returns: 0
- Output: Tenant IDs from directory structure
Removes unused asset files
- Returns: 0
- Actions: Compares files with config references, deletes unreferenced files
Wrapper for preview_branding()
-
Parameters: Same as
preview_branding() - Returns: 0
-
Calls:
preview_branding()
Wrapper for branding system initialization
-
Parameters:
$1- Tenant ID (optional) - Returns: 0
-
Calls:
initialize_branding_system()
Lists all white-label resources
- Returns: 0
- Output: Brands, logos, tenants
Exports branding configuration
-
Parameters:
$1- Format (json or yaml),$2- Tenant ID (optional) - Returns: 0 on success, 1 on error
- Output: Configuration in specified format to stdout
Imports branding configuration
-
Parameters:
$1- Config file path,$2- Tenant ID (optional) - Returns: 0 on success, 1 on error
- Validation: JSON structure, required fields
- Actions: Validates, backs up existing, imports new, regenerates CSS
Validates branding configuration
-
Parameters:
$1- Tenant ID (optional) - Returns: 0 if valid, 1 if errors
- Checks: JSON structure, required fields, color formats, file references
- Output: Detailed validation report
Additional helper functions used internally:
Creates directory with secure permissions
-
Parameters:
$1- Directory path - Actions: Creates dir, sets permissions to 0755
Creates default configuration file
-
Parameters:
$1- Config file path,$2- Tenant ID - Actions: Generates default JSON config
Internal logo validation
-
Parameters:
$1- Logo file path - Returns: 0 if valid, 1 if invalid
Internal CSS validation
-
Parameters:
$1- CSS file path - Returns: 0 if valid, 1 if invalid
Internal font validation
-
Parameters:
$1- Font file path - Returns: 0 if valid, 1 if invalid
Gets file size in MB (cross-platform)
-
Parameters:
$1- File path - Returns: File size via stdout
Resolves to absolute path
-
Parameters:
$1- File path - Returns: Absolute path via stdout
Scans CSS for security issues
-
Parameters:
$1- CSS file path - Returns: 0 (prints warnings)
Creates version backup of config
- Actions: Copies config to versions/ with timestamp
Cleans up old version backups
- Actions: Keeps only last 10 versions
Lists all version backups
- Returns: 0
- Output: Formatted list of versions with timestamps
Restores a previous version
-
Parameters:
$1- Version timestamp - Returns: 0 on success, 1 on error
- Actions: Backs up current, restores specified version, regenerates CSS
Gets config file path for tenant
-
Parameters:
$1- Tenant ID - Returns: Config file path via stdout
Ensures tenant has isolated directory structure
-
Parameters:
$1- Tenant ID - Actions: Creates tenant-specific directories
Gets detailed asset information
-
Parameters:
$1- Asset file path - Returns: 0 on success, 1 if not found
- Output: Size, MIME type, permissions, modified date
Validation (10)
- validate_brand_name, validate_tenant_id, validate_logo_type
- validate_file_size, validate_file_extension, validate_file_magic_bytes
- validate_string_length, validate_css_security
- validate_hex_color, validate_color_palette
Brand Management (4)
- initialize_branding_system, create_brand, update_brand, delete_brand
Color Management (1)
- set_brand_colors
Typography (3)
- set_brand_fonts, set_typography, upload_font
Logo Management (4)
- upload_brand_logo, upload_logo, list_logos, remove_logo
CSS Management (3)
- set_custom_css, remove_custom_css, generate_css_variables
Display (2)
- preview_branding, list_tenants
Asset Management (1)
- clean_unused_assets
Config Management (3)
- export_whitelabel_config, import_whitelabel_config, validate_branding_config
Utilities (2)
- escape_html, escape_json_string
Wrappers (3)
- view_whitelabel_settings, initialize_whitelabel_system, list_whitelabel_resources
Initial Setup
initialize_branding_system โ create_brand โ set_brand_colors โ upload_logo โ generate_css_variablesUpdate Colors
set_brand_colors โ generate_css_variablesUpdate Typography
set_brand_fonts โ generate_css_variables
set_typography โ generate_css_variablesUpload Assets
upload_logo โ (validates) โ (creates version backup) โ (updates config)
upload_font โ (validates) โ (creates version backup) โ (updates config)
set_custom_css โ (validates) โ (scans security) โ (creates version backup) โ (updates config)Version Management
(any change) โ branding::create_version_backup โ (operation) โ branding::cleanup_old_versions-
jq- JSON manipulation (required) -
file- MIME type detection (recommended) -
yqorpython3- YAML export (optional) -
stat- File information (cross-platform handled) -
find,grep,awk,sed- Standard POSIX utilities
-
src/lib/utils/platform-compat.sh- Cross-platform utilities -
src/lib/utils/validation.sh- Additional validation functions
All functions follow consistent error handling:
- Return 0 on success
- Return 1 on error
- Print error messages to stderr
- Use color-coded output (RED for errors, YELLOW for warnings, GREEN for success)
- Provide helpful error messages with suggested solutions
Last Updated: January 30, 2026 Total Functions: 36 (user-facing) + ~14 (internal helpers) Status: Production-ready