-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
163 lines (159 loc) · 4.86 KB
/
index.js
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
160
161
162
163
const arvish = require('arvish')
const utils = require('./lib/utils')
const items = []
// teams config
const teams = arvish.config.get('figma.teams') ? JSON.parse(arvish.config.get('figma.teams')) : []
const isAddingTeam = arvish.input.match(/^add\shttps:\/\/www\.figma\.com\/files\/team\/(\d+)\/([^\/]+)/i)
if(isAddingTeam) {
return arvish.output([{
title: isAddingTeam[2],
subtitle: `Add ${isAddingTeam[2]} team’s project files to your search results.`,
arg: JSON.stringify({id: isAddingTeam[1], name: isAddingTeam[2]}),
variables: {
action: 'add',
notification: `${isAddingTeam[2]} team’s projects and files added to search results.`
}
}])
}
Promise.all(teams.map(team => {
return Promise.resolve(items.push({
uid: `${team.name}.${team.id}`,
title: team.name,
subtitle: `Open team page.`,
arg: utils.getUrl(`/files/team/${team.id}/${team.name}`, 'app'),
text: {
copy: utils.getUrl(`/files/team/${team.id}/${team.name}`, 'browser'),
},
variables: {
action: 'browser'
},
mods: {
alt: {
subtitle: `Remove ${team.name} projects and files from search results.`,
arg: JSON.stringify({id: team.id, name: team.name}),
variables: {
action: 'remove',
notification: `${team.name} team’s projects and files removed from search results.`
}
},
cmd: {
subtitle: 'Open team page in a web browser',
arg: utils.getUrl(`/files/team/${team.id}/${team.name}`, 'browser')
}
}
}))
.then(() => utils.getResults(`/teams/${team.id}/projects`))
.then(results => {
return Promise.all(results.projects.map((p) => {
return Promise.resolve(items.push({
uid: `${p.id}/${p.name}`,
title: p.name,
subtitle: `Open project page for team ${team.name}.`,
arg: utils.getUrl(`/files/project/${p.id}/${p.name}`, 'app'),
text: {
copy: utils.getUrl(`/files/project/${p.id}/${p.name}`, 'browser'),
},
variables: {
action: 'browser'
},
mods: {
cmd: {
subtitle: 'Open project in web browser',
arg: utils.getUrl(`/files/project/${p.key}/${p.name}`, 'browser')
}
}
}))
.then(() => utils.getResults(`/projects/${p.id}/files`))
.then(results => {
return Promise.all(results.files.map((f) => {
// set the project name for formatting
f.project = p.name
f.team = team.name
return Promise.resolve(items.push({
uid: f.key,
title: f.name,
subtitle: utils.subtitle(f, ['team', 'project', 'modified']),
arg: utils.getUrl(`/file/${f.key}/${f.name}`, 'app'),
variables: {
action: 'browser'
},
quicklookurl: `https://www.figma.com${f.thumbnail_url}`,
text: {
copy: utils.getUrl(`/file/${f.key}/${f.name}`, 'browser'),
},
mods: {
alt: {
subtitle: 'Duplicate file to your drafts.',
arg: utils.getUrl(`/file/${f.key}/${f.name}/duplicate`, 'browser')
},
cmd: {
subtitle: 'Open file in web browser',
arg: utils.getUrl(`/file/${f.key}/${f.name}`, 'browser')
}
}
}))
}))
})
}))
})
}))
.then(() => {
if(!isAddingTeam) {
// Add Figma Team Item
items.push({
title: 'Add new Figma team',
subtitle: 'Add Figma team projects to search results with url.',
arg: 'figma add ',
autocomplete: 'add ',
variables: {
action: 'rerun'
}
})
}
items.push({
title: 'Recent Files',
arg: utils.getUrl('/files/recent', 'app'),
mods: {
cmd: {
subtitle: 'Open recent files in web browser',
arg: utils.getUrl('/files/recent', 'browser')
}
},
variables: {
action: 'browser'
}
})
items.push({
title: 'Drafts',
arg: utils.getUrl(`/files/drafts`, 'app'),
mods: {
cmd: {
subtitle: 'Open drafts in web browser',
arg: utils.getUrl('/files/drafts', 'browser')
}
},
variables: {
action: 'browser'
}
})
items.push({
title: 'Deleted Files',
arg: utils.getUrl(`/files/deleted`, 'app'),
mods: {
cmd: {
subtitle: 'Open deleted files in web browser',
arg: utils.getUrl('/files/deleted', 'browser')
}
},
variables: {
action: 'browser'
}
})
})
.then(() => items.filter(item => {
if (item.title.toLowerCase().includes(arvish.input.toLowerCase())) {
return true
}
return false
}))
.then((filteredItems) => arvish.output(filteredItems))