@boltic/cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -0
- package/api/integration.js +469 -0
- package/api/login.js +50 -0
- package/cli.js +128 -0
- package/commands/integration.js +952 -0
- package/commands/login.js +170 -0
- package/config/environments.js +13 -0
- package/helper/command-suggestions.js +54 -0
- package/helper/env.js +27 -0
- package/helper/error.js +123 -0
- package/helper/folder.js +204 -0
- package/helper/secure-storage.js +74 -0
- package/helper/verbose.js +20 -0
- package/index.js +14 -0
- package/package.json +57 -0
- package/templates/schemas.js +506 -0
- package/utils/integration.js +47 -0
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boltic/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A powerful CLI tool for managing Boltic Workflow integrations",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"boltic": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "Ahmed Sakri <ahmedsakri@gofynd.com>",
|
|
10
|
+
"homepage": "https://www.boltic.io",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "node index.js",
|
|
13
|
+
"dev": "nodemon index.js",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"prepare": "husky"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cli",
|
|
19
|
+
"boltic",
|
|
20
|
+
"developer-tools",
|
|
21
|
+
"integration",
|
|
22
|
+
"workflow",
|
|
23
|
+
"automation",
|
|
24
|
+
"fynd"
|
|
25
|
+
],
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"registry": "https://registry.npmjs.org/"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@inquirer/prompts": "^7.3.2",
|
|
34
|
+
"axios": "^1.8.2",
|
|
35
|
+
"chalk": "^5.3.0",
|
|
36
|
+
"keytar": "^7.9.0",
|
|
37
|
+
"open": "^10.1.0",
|
|
38
|
+
"uuid": "^11.1.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/core": "^7.26.9",
|
|
42
|
+
"@babel/preset-env": "^7.26.9",
|
|
43
|
+
"@commitlint/cli": "^19.7.1",
|
|
44
|
+
"@commitlint/config-conventional": "^19.7.1",
|
|
45
|
+
"@jest/globals": "^29.7.0",
|
|
46
|
+
"axios-mock-adapter": "^2.1.0",
|
|
47
|
+
"babel-jest": "^29.7.0",
|
|
48
|
+
"eslint": "^9.21.0",
|
|
49
|
+
"eslint-config-prettier": "^10.0.2",
|
|
50
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
51
|
+
"husky": "^9.1.7",
|
|
52
|
+
"jest": "^29.7.0",
|
|
53
|
+
"lint-staged": "^15.4.3",
|
|
54
|
+
"nodemon": "^3.1.9",
|
|
55
|
+
"prettier": "^3.5.3"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
const authentication = {
|
|
2
|
+
parameters: [
|
|
3
|
+
{
|
|
4
|
+
name: "type",
|
|
5
|
+
meta: {
|
|
6
|
+
displayName: "Authentication Type",
|
|
7
|
+
displayType: "select",
|
|
8
|
+
placeholder: "Select an authentication type",
|
|
9
|
+
description:
|
|
10
|
+
"Choose the type of authentication you want to use.",
|
|
11
|
+
options: [
|
|
12
|
+
{
|
|
13
|
+
label: "API Key",
|
|
14
|
+
value: "api_key",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
value: "api_key",
|
|
18
|
+
validation: {
|
|
19
|
+
required: true,
|
|
20
|
+
requiredDetail: {
|
|
21
|
+
errorMsg: "Authentication type is required",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
api_key: {
|
|
28
|
+
parameters: [
|
|
29
|
+
{
|
|
30
|
+
name: "api_key",
|
|
31
|
+
meta: {
|
|
32
|
+
displayName: "API Key",
|
|
33
|
+
displayType: "password",
|
|
34
|
+
placeholder: "Enter API Key",
|
|
35
|
+
description: "Your API key for authentication",
|
|
36
|
+
validation: {
|
|
37
|
+
required: true,
|
|
38
|
+
requiredDetail: {
|
|
39
|
+
errorMsg: "API key is required",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const base = (name) => {
|
|
49
|
+
return {
|
|
50
|
+
parameters: [
|
|
51
|
+
{
|
|
52
|
+
name: "secret",
|
|
53
|
+
meta: {
|
|
54
|
+
displayName: "Service Account",
|
|
55
|
+
displayType: "autocomplete",
|
|
56
|
+
placeholder: "Select Service Account",
|
|
57
|
+
description:
|
|
58
|
+
"Your service account credentials are encrypted & can be removed at any time.",
|
|
59
|
+
options: [],
|
|
60
|
+
config: {
|
|
61
|
+
urlType: "secret",
|
|
62
|
+
method: "get",
|
|
63
|
+
url: `/${name.toUpperCase()}?current_page=1&page_size=999`,
|
|
64
|
+
labelKey: "name",
|
|
65
|
+
valueKey: "_id",
|
|
66
|
+
},
|
|
67
|
+
htmlProps: {
|
|
68
|
+
showAddNew: true,
|
|
69
|
+
},
|
|
70
|
+
value: "",
|
|
71
|
+
validation: {
|
|
72
|
+
required: true,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "resource",
|
|
78
|
+
meta: {
|
|
79
|
+
displayName: "Resource",
|
|
80
|
+
displayType: "select",
|
|
81
|
+
placeholder: "Select a resource",
|
|
82
|
+
description: "Select the resource you want to work with.",
|
|
83
|
+
options: [{ label: "Resource 1", value: "resource1" }],
|
|
84
|
+
value: "",
|
|
85
|
+
validation: {
|
|
86
|
+
required: true,
|
|
87
|
+
},
|
|
88
|
+
dependencies: {
|
|
89
|
+
conditions: [
|
|
90
|
+
{
|
|
91
|
+
field: "secret",
|
|
92
|
+
operator: "NOT_EMPTY",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const webhook = (name) => {
|
|
103
|
+
return {
|
|
104
|
+
parameters: [
|
|
105
|
+
{
|
|
106
|
+
name: "secret",
|
|
107
|
+
meta: {
|
|
108
|
+
displayName: "Service Account",
|
|
109
|
+
displayType: "autocomplete",
|
|
110
|
+
placeholder: "Select Service Account",
|
|
111
|
+
description:
|
|
112
|
+
"Your service account credentials are encrypted & can be removed at any time.",
|
|
113
|
+
options: [],
|
|
114
|
+
config: {
|
|
115
|
+
urlType: "secret",
|
|
116
|
+
method: "get",
|
|
117
|
+
url: `/${name.toUpperCase()}?current_page=1&page_size=999`,
|
|
118
|
+
labelKey: "name",
|
|
119
|
+
valueKey: "_id",
|
|
120
|
+
},
|
|
121
|
+
htmlProps: {
|
|
122
|
+
showAddNew: true,
|
|
123
|
+
},
|
|
124
|
+
value: "",
|
|
125
|
+
validation: {
|
|
126
|
+
required: true,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "resource",
|
|
132
|
+
meta: {
|
|
133
|
+
displayName: "Resource",
|
|
134
|
+
displayType: "select",
|
|
135
|
+
options: [
|
|
136
|
+
{
|
|
137
|
+
label: "Webhook",
|
|
138
|
+
value: "webhook",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
value: "",
|
|
142
|
+
validation: {
|
|
143
|
+
required: true,
|
|
144
|
+
},
|
|
145
|
+
dependencies: {
|
|
146
|
+
conditions: [
|
|
147
|
+
{
|
|
148
|
+
field: "secret",
|
|
149
|
+
operator: "NOT_EMPTY",
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "operation",
|
|
157
|
+
meta: {
|
|
158
|
+
displayName: "Events",
|
|
159
|
+
displayType: "select",
|
|
160
|
+
description: "",
|
|
161
|
+
placeholder: "",
|
|
162
|
+
options: [
|
|
163
|
+
{
|
|
164
|
+
label: "Data Submission",
|
|
165
|
+
value: "webhook.data_submission",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
value: "",
|
|
169
|
+
validation: {
|
|
170
|
+
required: true,
|
|
171
|
+
},
|
|
172
|
+
dependencies: {
|
|
173
|
+
conditions: [
|
|
174
|
+
{
|
|
175
|
+
field: "secret",
|
|
176
|
+
operator: "NOT_EMPTY",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
field: "resource",
|
|
180
|
+
operator: "EQUALS",
|
|
181
|
+
value: "webhook",
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
data_submission: {
|
|
189
|
+
parameters: [
|
|
190
|
+
{
|
|
191
|
+
name: "site_id",
|
|
192
|
+
meta: {
|
|
193
|
+
displayName: "Service Site",
|
|
194
|
+
displayType: "select",
|
|
195
|
+
options: [],
|
|
196
|
+
placeholder: "",
|
|
197
|
+
description:
|
|
198
|
+
"Select the site that you would like to receive notifications from.",
|
|
199
|
+
value: "",
|
|
200
|
+
validation: {
|
|
201
|
+
required: true,
|
|
202
|
+
},
|
|
203
|
+
dependencies: {
|
|
204
|
+
conditions: [
|
|
205
|
+
{
|
|
206
|
+
field: "secret",
|
|
207
|
+
operator: "NOT_EMPTY",
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
field: "resource",
|
|
211
|
+
operator: "EQUALS",
|
|
212
|
+
value: "webhook",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
field: "operation",
|
|
216
|
+
operator: "EQUALS",
|
|
217
|
+
value: "webhook.data_submission",
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "form_id",
|
|
225
|
+
meta: {
|
|
226
|
+
displayName: "Data Form",
|
|
227
|
+
displayType: "select",
|
|
228
|
+
description:
|
|
229
|
+
"Forms will only show here if they have been published and have received at least 1 submission.",
|
|
230
|
+
options: [],
|
|
231
|
+
placeholder: "",
|
|
232
|
+
value: "",
|
|
233
|
+
validation: {
|
|
234
|
+
required: true,
|
|
235
|
+
},
|
|
236
|
+
config: {
|
|
237
|
+
urlType: "options",
|
|
238
|
+
method: "post",
|
|
239
|
+
url: "integrations/options",
|
|
240
|
+
body: {
|
|
241
|
+
name: "service",
|
|
242
|
+
resource: "webhook",
|
|
243
|
+
operation: "webhook.data_submission",
|
|
244
|
+
secret: "{{parameters.secret}}",
|
|
245
|
+
loadOptionsMethod: "getForms",
|
|
246
|
+
webhook: true,
|
|
247
|
+
site_id: "{{parameters.site_id}}",
|
|
248
|
+
},
|
|
249
|
+
labelKey: "displayName",
|
|
250
|
+
valueKey: "id",
|
|
251
|
+
},
|
|
252
|
+
dependencies: {
|
|
253
|
+
conditions: [
|
|
254
|
+
{
|
|
255
|
+
field: "site_id",
|
|
256
|
+
operator: "NOT_EMPTY",
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
attach: {
|
|
264
|
+
definition: {
|
|
265
|
+
method: "post",
|
|
266
|
+
url: "https://service.com/api/v2/sites/{{parameters.site_id}}/webhooks",
|
|
267
|
+
headers: {
|
|
268
|
+
Accept: "application/json",
|
|
269
|
+
"Content-Type": "application/json",
|
|
270
|
+
Authorization: "Bearer {{secrets.access_token}}",
|
|
271
|
+
},
|
|
272
|
+
body: {
|
|
273
|
+
triggerType: "{{parameters.operation}}",
|
|
274
|
+
url: "{{webhook.url}}",
|
|
275
|
+
},
|
|
276
|
+
response: {
|
|
277
|
+
output: "{{response.data}}",
|
|
278
|
+
error: {
|
|
279
|
+
code: "{{response.data.code}}",
|
|
280
|
+
message: "{{response.data.message}}",
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
detach: {
|
|
286
|
+
definition: {
|
|
287
|
+
method: "delete",
|
|
288
|
+
url: "https://service.com/api/v2/webhooks/{{webhook.id}}",
|
|
289
|
+
headers: {
|
|
290
|
+
Accept: "application/json",
|
|
291
|
+
Authorization: "Bearer {{secrets.access_token}}",
|
|
292
|
+
},
|
|
293
|
+
response: {
|
|
294
|
+
output: "{{response.data}}",
|
|
295
|
+
error: {
|
|
296
|
+
code: "{{response.data.code}}",
|
|
297
|
+
message: "{{response.data.message}}",
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
update: {},
|
|
303
|
+
getSites: {
|
|
304
|
+
definition: {
|
|
305
|
+
method: "get",
|
|
306
|
+
url: "https://service.com/api/v2/sites",
|
|
307
|
+
headers: {
|
|
308
|
+
Accept: "application/json",
|
|
309
|
+
Authorization: "Bearer {{secrets.access_token}}",
|
|
310
|
+
},
|
|
311
|
+
qs: {
|
|
312
|
+
limit: 100,
|
|
313
|
+
},
|
|
314
|
+
response: {
|
|
315
|
+
output: "{{response.data.sites}}",
|
|
316
|
+
error: {
|
|
317
|
+
code: "{{response.status}}",
|
|
318
|
+
message: "{{response.data.message}}",
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
getForms: {
|
|
324
|
+
definition: {
|
|
325
|
+
method: "get",
|
|
326
|
+
url: "https://service.com/api/v2/sites/{{parameters.site_id}}/forms",
|
|
327
|
+
headers: {
|
|
328
|
+
Accept: "application/json",
|
|
329
|
+
Authorization: "Bearer {{secrets.access_token}}",
|
|
330
|
+
},
|
|
331
|
+
response: {
|
|
332
|
+
output: "{{response.data.forms}}",
|
|
333
|
+
error: {
|
|
334
|
+
code: "{{response.status}}",
|
|
335
|
+
message: "{{response.data.message}}",
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
test: {
|
|
341
|
+
form_submission: {
|
|
342
|
+
definition: {
|
|
343
|
+
url: "https://service.com/api/v2/forms/{{parameters.form_id}}",
|
|
344
|
+
qs: {},
|
|
345
|
+
method: "get",
|
|
346
|
+
headers: {
|
|
347
|
+
Accept: "application/json",
|
|
348
|
+
Authorization: "Bearer {{secrets.access_token}}",
|
|
349
|
+
},
|
|
350
|
+
transform: {
|
|
351
|
+
output: "const sampleOutput = { triggerType: 'form_submission', payload: { name: output.displayName, siteId: output.siteId, data: {}, submittedAt: new Date().toISOString(), id: 'sample-id-12345', formId: output.id || null, formElementId: output.formElementId, pageId: output.pageId, publishedPath: '/sample-path', output: [] } }; for (const fieldId in output.fields) { const field = output.fields[fieldId]; sampleOutput.payload.data[field.displayName] = field.placeholder || `Sample value for ${field.displayName}`; } return sampleOutput;",
|
|
352
|
+
},
|
|
353
|
+
response: {
|
|
354
|
+
output: "{{response.data}}",
|
|
355
|
+
error: {
|
|
356
|
+
code: "{{response.status}}",
|
|
357
|
+
message: "{{response.data.message}}",
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const resource1 = {
|
|
368
|
+
parameters: [
|
|
369
|
+
{
|
|
370
|
+
name: "operation",
|
|
371
|
+
meta: {
|
|
372
|
+
displayName: "Operation",
|
|
373
|
+
displayType: "select",
|
|
374
|
+
placeholder: "Select an operation",
|
|
375
|
+
description: "Select the operation you want to perform.",
|
|
376
|
+
options: [
|
|
377
|
+
{
|
|
378
|
+
label: "Create Account",
|
|
379
|
+
value: "resource1.create",
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
label: "Delete Account",
|
|
383
|
+
value: "resource1.delete",
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
validation: {
|
|
387
|
+
required: true,
|
|
388
|
+
},
|
|
389
|
+
dependencies: {
|
|
390
|
+
conditions: [
|
|
391
|
+
{
|
|
392
|
+
field: "resource",
|
|
393
|
+
operator: "EQUALS",
|
|
394
|
+
value: "resource1",
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
create: {
|
|
402
|
+
definition: {
|
|
403
|
+
method: "post",
|
|
404
|
+
url: "https://dummyjson.com/products",
|
|
405
|
+
headers: {
|
|
406
|
+
ContentType: "application/json",
|
|
407
|
+
},
|
|
408
|
+
body: "{{parameters}}",
|
|
409
|
+
response: {
|
|
410
|
+
output: "{{response.data}}",
|
|
411
|
+
error: {
|
|
412
|
+
message: "{{response.data.errors.message}}",
|
|
413
|
+
code: "{{response.data.errors.code}}",
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
parameters: [
|
|
418
|
+
{
|
|
419
|
+
name: "name",
|
|
420
|
+
meta: {
|
|
421
|
+
displayName: "Product Name",
|
|
422
|
+
displayType: "text",
|
|
423
|
+
placeholder: "Enter the name of the product",
|
|
424
|
+
description:
|
|
425
|
+
"Enter the name of the product you want to create.",
|
|
426
|
+
validation: {
|
|
427
|
+
required: true,
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: "description",
|
|
433
|
+
meta: {
|
|
434
|
+
displayName: "Product Description",
|
|
435
|
+
displayType: "text",
|
|
436
|
+
placeholder: "Enter the description of the product",
|
|
437
|
+
description:
|
|
438
|
+
"Enter the description of the product you want to create.",
|
|
439
|
+
validation: {
|
|
440
|
+
required: true,
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
name: "price",
|
|
446
|
+
meta: {
|
|
447
|
+
displayName: "Product Price",
|
|
448
|
+
displayType: "number",
|
|
449
|
+
placeholder: "Enter the price of the product",
|
|
450
|
+
description:
|
|
451
|
+
"Enter the price of the product you want to create.",
|
|
452
|
+
validation: {
|
|
453
|
+
required: true,
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: "discountPercentage",
|
|
459
|
+
meta: {
|
|
460
|
+
displayName: "Discount Percentage",
|
|
461
|
+
displayType: "number",
|
|
462
|
+
placeholder: "Enter the discount percentage",
|
|
463
|
+
description:
|
|
464
|
+
"Enter the discount percentage for the product you want to create.",
|
|
465
|
+
validation: {
|
|
466
|
+
required: true,
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
},
|
|
472
|
+
delete: {
|
|
473
|
+
parameters: [
|
|
474
|
+
{
|
|
475
|
+
name: "id",
|
|
476
|
+
meta: {
|
|
477
|
+
displayName: "Account ID",
|
|
478
|
+
displayType: "text",
|
|
479
|
+
placeholder: "Enter the Account ID",
|
|
480
|
+
description:
|
|
481
|
+
"Enter the ID of the account you want to delete.",
|
|
482
|
+
validation: {
|
|
483
|
+
required: true,
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
definition: {
|
|
489
|
+
method: "delete",
|
|
490
|
+
url: "https://dummyjson.com/products/{{parameters.id}}",
|
|
491
|
+
headers: {
|
|
492
|
+
ContentType: "application/json",
|
|
493
|
+
},
|
|
494
|
+
|
|
495
|
+
response: {
|
|
496
|
+
output: "{{response.data}}",
|
|
497
|
+
error: {
|
|
498
|
+
message: "{{response.data.errors.message}}",
|
|
499
|
+
code: "{{response.data.errors.code}}",
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
export { authentication, base, resource1, webhook };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
|
|
3
|
+
async function pickSvgFile() {
|
|
4
|
+
const platform = process.platform;
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
if (platform === "darwin") {
|
|
8
|
+
// macOS: Use AppleScript to open file dialog
|
|
9
|
+
const script = `
|
|
10
|
+
set theFile to choose file of type {"svg"} with prompt "Select an SVG file"
|
|
11
|
+
set thePath to POSIX path of theFile
|
|
12
|
+
return thePath
|
|
13
|
+
`;
|
|
14
|
+
const filePath = execSync(`osascript -e '${script}'`)
|
|
15
|
+
.toString()
|
|
16
|
+
.trim();
|
|
17
|
+
return filePath;
|
|
18
|
+
} else if (platform === "win32") {
|
|
19
|
+
// Windows: Use PowerShell to open file dialog
|
|
20
|
+
const psScript = `
|
|
21
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
22
|
+
$dialog = New-Object System.Windows.Forms.OpenFileDialog
|
|
23
|
+
$dialog.Filter = "SVG files (*.svg)|*.svg"
|
|
24
|
+
if ($dialog.ShowDialog() -eq "OK") { $dialog.FileName }
|
|
25
|
+
`;
|
|
26
|
+
const filePath = execSync(`powershell -Command "${psScript}"`)
|
|
27
|
+
.toString()
|
|
28
|
+
.trim();
|
|
29
|
+
return filePath;
|
|
30
|
+
} else if (platform === "linux") {
|
|
31
|
+
// Linux: Use zenity if available
|
|
32
|
+
const filePath = execSync(
|
|
33
|
+
`zenity --file-selection --file-filter="*.svg"`
|
|
34
|
+
)
|
|
35
|
+
.toString()
|
|
36
|
+
.trim();
|
|
37
|
+
return filePath;
|
|
38
|
+
} else {
|
|
39
|
+
console.error("Unsupported platform for file picker");
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
} catch (_) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { pickSvgFile };
|