-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path04-pine-develop.sh
More file actions
executable file
·53 lines (46 loc) · 1.93 KB
/
Copy path04-pine-develop.sh
File metadata and controls
executable file
·53 lines (46 loc) · 1.93 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
#!/usr/bin/env bash
# Example 04: Pine develop loop — write, compile (server-side), fix, re-compile.
#
# Prereqs:
# - TradingView Desktop with --remote-debugging-port=9222
# - jq
#
# What this proves: the full Pine editing loop — draft a script, hit the server
# compile endpoint to get real compiler diagnostics, fix the error, and
# re-compile to green. Uses `pine check` (server-side) so the Pine Editor
# panel doesn't need to be open. For the full editor flow (set source, save,
# persist to TradingView account), open the Pine Editor in the app first and
# call `tv pine set` then `tv pine save`.
set -euo pipefail
cd "$(dirname "$0")/../.."
TV="node src/cli/index.js"
OUT_DIR="/tmp/tvcontrol-examples"
mkdir -p "$OUT_DIR"
echo "→ Draft a Pine script with a deliberate bug (references undefined function):"
cat > "$OUT_DIR/draft-v1.pine" <<'PINE'
//@version=6
indicator("TVControl Demo v1", overlay=true)
length = input.int(20, "Length")
plot(undefined_fn(close, length))
PINE
echo "→ Server-side compile check:"
BAD=$($TV pine check -f "$OUT_DIR/draft-v1.pine")
echo "$BAD" | jq '{success, compiled, error_count, first_error: .errors[0]}'
ERRS=$(echo "$BAD" | jq -r '.error_count')
[ "$ERRS" -ge 1 ] || { echo "✗ expected compile errors, got $ERRS"; exit 1; }
echo
echo "→ Fix the script (swap undefined_fn for ta.sma):"
cat > "$OUT_DIR/draft-v2.pine" <<'PINE'
//@version=6
indicator("TVControl Demo v2", overlay=true)
length = input.int(20, "Length")
plot(ta.sma(close, length))
PINE
echo "→ Re-compile:"
GOOD=$($TV pine check -f "$OUT_DIR/draft-v2.pine")
echo "$GOOD" | jq '{success, compiled, error_count, warning_count}'
COMPILED=$(echo "$GOOD" | jq -r '.compiled')
[ "$COMPILED" = "true" ] || { echo "✗ fixed script did not compile"; exit 1; }
echo
echo "✓ Pine develop loop works: draft → compile → diagnose → fix → green."
echo " (Full editor persistence: open Pine Editor panel, then 'tv pine set < file' and 'tv pine save'.)"