-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathcheck-layer-variables.ts
More file actions
77 lines (61 loc) · 2.01 KB
/
check-layer-variables.ts
File metadata and controls
77 lines (61 loc) · 2.01 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
import { getSupabaseAdmin } from '../lib/supabase-server';
import type { Layer } from '../types';
const pageId = 'e9c9a71d-ff08-4eb5-84af-94bd21c9b046';
async function checkLayerVariables() {
const client = await getSupabaseAdmin();
if (!client) {
console.error('Supabase not configured');
process.exit(1);
}
// Get draft layers
const { data, error } = await client
.from('page_layers')
.select('*')
.eq('page_id', pageId)
.eq('is_published', false)
.is('deleted_at', null)
.order('created_at', { ascending: false })
.limit(1)
.single();
if (error) {
console.error('Error fetching layers:', error);
process.exit(1);
}
if (!data || !data.layers) {
console.log('No layers found');
process.exit(0);
}
// Recursively find all text and heading layers with variables.text
function findTextLayers(layers: Layer[], path = ''): any[] {
const results: any[] = [];
for (const layer of layers) {
const currentPath = path ? `${path} > ${layer.name}` : layer.name;
if (['text', 'heading'].includes(layer.name) && layer.variables?.text) {
results.push({
id: layer.id,
name: layer.name,
customName: layer.customName || layer.name,
path: currentPath,
variableType: layer.variables.text.type,
data: layer.variables.text.data
});
}
if (layer.children && layer.children.length > 0) {
results.push(...findTextLayers(layer.children, currentPath));
}
}
return results;
}
const textLayers = findTextLayers(data.layers);
console.log(`Found ${textLayers.length} text/heading layers with variables.text:`);
console.log('');
for (const layer of textLayers) {
console.log('Layer:', layer.customName);
console.log(' Path:', layer.path);
console.log(' Type:', layer.variableType);
console.log(' Data:', JSON.stringify(layer.data, null, 2));
console.log('');
}
process.exit(0);
}
checkLayerVariables();