-
Notifications
You must be signed in to change notification settings - Fork 43
/
test-usage.sh
executable file
·151 lines (129 loc) · 3.03 KB
/
test-usage.sh
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
#!/usr/bin/env bash
set -xueo pipefail
rm -rf test-artifacts
mkdir -p test-artifacts
pushd test-artifacts
cat > package.json << EOF
{}
EOF
cat > tsconfig.json << EOF
{
"compilerOptions": {
"target": "es6",
"lib": ["es6"],
"strict": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@figma"
]
}
}
EOF
cat > code.ts << EOF
/**
* Test file to make sure that plugin-typings work as expected.
*/
function main() {
// figma globals is there
if (figma.command && figma.editorType) {
// console.log works
console.log(figma.root, figma.currentPage)
// setTimeout works
setTimeout(() => {
figma.currentPage.selection = [];
}, 100)
// setInterval works too
clearTimeout(setInterval(() => {
figma.ui.onmessage = msg => {}
}, 100))
}
}
function testErrorFn(): void {
// @ts-expect-error
if (figma.NON_EXISTENT_ATTR) {
}
}
// Node types are available as globals
function testFn1(node: SceneNode): node is FrameNode {
return node.type === 'FRAME'
}
// Paint types are available as globals too
function testFn(paint: SolidPaint | GradientPaint | ImagePaint | null): boolean {
return !!paint
}
function testNotify() {
figma.notify("normal")
figma.notify("error", {error: true})
figma.notify("timeout", {timeout: 10000})
figma.notify("Infinity", {timeout: Infinity})
figma.notify("button", {button: {
text: "button",
action: () => {
return false
}
}})
figma.notify("button", {
button: {
text: "button",
action: () => {},
}
})
figma.notify("onDequeue", {
onDequeue: (reason: NotifyDequeueReason) => {
switch (reason) {
case 'timeout':
break;
case 'dismiss':
break;
case 'action_button_click':
break;
default:
function assertNever(x: never): never {
throw new Error("Unexpected object: " + x);
}
assertNever(reason);
break;
}
}
})
}
function testCodegen() {
figma.codegen.on("generate", async () => {
return [
{
language: "TYPESCRIPT",
code: JSON.stringify(figma.codegen.preferences.unit),
title: "Code snippet 1"
},
{
language: "JAVASCRIPT",
code: JSON.stringify(figma.codegen.preferences.scaleFactor),
title: "Code snippet 2"
},
{
language: "JAVASCRIPT",
code: JSON.stringify(figma.codegen.preferences.customSettings),
title: "Code snippet 3"
}
]
})
}
function testFindAllWithCriteria() {
const nodes = figma.root.findAllWithCriteria({ types: ["TEXT"] });
console.log(nodes.map(n => {
return [n.id, n.characters]
}))
const frame = figma.createFrame()
const nodes2 = frame.findAllWithCriteria({ sharedPluginData: { namespace: 'foo' } })
console.log(nodes2[0].id)
}
function testParameters() {
figma.on('run', async ({ command, parameters }) => {
console.log(command, parameters)
})
}
EOF
npm install typescript
npm install ../
npx tsc --noEmit
popd