-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdevtb
More file actions
executable file
·159 lines (141 loc) · 4.72 KB
/
Copy pathdevtb
File metadata and controls
executable file
·159 lines (141 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# =============================================================================
# DEVTB - DevelopmentTranslation Bridge CLI
# =============================================================================
# Unified CLI wrapper that routes commands to the appropriate backend:
# - transform, transform-all, transform-site, analyze → Python engine
# - list-frameworks, validate → PHP engine (WordPress runtime utilities)
#
# Version: 5.1.0
# =============================================================================
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Version
VERSION="5.1.0"
# Show version
show_version() {
echo "DevelopmentTranslation Bridge v${VERSION}"
echo " One schema, two conforming runtimes (parse -> universal -> convert)"
echo " Python engine: transform commands"
echo " PHP engine: WordPress runtime utilities"
}
# Show help
show_help() {
echo ""
echo "DevelopmentTranslation Bridge v${VERSION}"
echo "========================================"
echo ""
echo "Universal page builder translation with JSON-native transforms"
echo ""
echo "USAGE:"
echo " devtb <command> [options]"
echo ""
echo "COMMANDS (Python engine - JSON-native, lossless):"
echo " transform <source> <target> <file> Transform a file (100% metadata preserved)"
echo " transform-all <source> <file> Transform to every other framework"
echo " transform-site <source> <target> <dir> Transform all files in directory"
echo " analyze <framework> <file> Analyze page builder content"
echo ""
echo "COMMANDS (PHP engine utilities):"
echo " list-frameworks List supported frameworks"
echo " validate <framework> <file> Validate file format"
echo ""
echo "OPTIONS:"
echo " -h, --help Show this help message"
echo " -v, --version Show version information"
echo " -n, --dry-run Preview without writing files"
echo " -d, --debug Show debug information"
echo " -o, --output <file> Specify output file path"
echo ""
echo "EXAMPLES:"
echo " # v4 JSON-native transform (recommended for Elementor JSON)"
echo " devtb transform elementor bootstrap page.json"
echo " devtb analyze elementor page.json"
echo ""
echo " # fan out to every framework at once"
echo " devtb transform-all bootstrap page.html"
echo ""
echo "NOTE:"
echo " Every conversion rides the lossless parse → universal → convert"
echo " path; fidelity is reported per conversion. 'translate' was"
echo " removed in 5.1 — use 'transform'."
echo ""
echo "For more info: https://github.com/coryhubbell/development-translation-bridge"
echo ""
}
# Check if Python module is installed
check_python() {
if python3 -c "import translation_bridge" 2>/dev/null; then
return 0
else
return 1
fi
}
# Run Python command
run_python() {
if check_python; then
python3 -m translation_bridge.cli "$@"
else
# Try running from source directory
PYTHONPATH="${SCRIPT_DIR}/src:${PYTHONPATH:-}" python3 -m translation_bridge.cli "$@"
fi
}
# Run PHP command
run_php() {
local cmd="$1"
shift
# Run the PHP CLI
php "${SCRIPT_DIR}/devtb-php" "$cmd" "$@"
}
# Main command routing
main() {
# Handle no arguments
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
# Parse global options
case "$1" in
-h|--help|help)
show_help
exit 0
;;
-v|--version|version)
show_version
exit 0
;;
esac
# Route commands
local cmd="$1"
shift
case "$cmd" in
# Python engine (JSON-native)
transform|transform-all|transform-site|analyze)
run_python "$cmd" "$@"
;;
# Removed in 5.1 (deprecated since 4.14.0)
translate|translate-all)
echo -e "${RED}'$cmd' was removed in 5.1 — use 'devtb transform' / 'devtb transform-all'.${NC}"
exit 1
;;
# PHP engine utilities (WordPress runtime)
list-frameworks|validate)
run_php "$cmd" "$@"
;;
# Unknown command - try PHP as fallback
*)
echo -e "${YELLOW}Unknown command: $cmd${NC}"
echo "Trying PHP backend..."
run_php "$cmd" "$@"
;;
esac
}
# Run main with all arguments
main "$@"