forked from kbshl/alfred-vscode
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
45 lines (37 loc) · 1.11 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
import alfy from 'alfy';
import { fetch, getProjectFilePath, inputMatchesData } from './lib/utils.mjs';
async function main() {
try {
const file = getProjectFilePath();
// console.log(`[info] Using file: ${file}`);
// alfy.log(`[info] Using file: ${file}`);
let projects = await fetch(file, {});
if (alfy.input) {
projects = inputMatchesData(projects, alfy.input, ['title', 'subtitle']);
}
// alfy.log(`[info] Found ${projects.length} projects`);
// console.log(`[info] Found ${projects.length} projects`);
if (projects.length === 0) {
alfy.output([
{
title: 'No projects found',
},
]);
} else {
const formatted = projects.map((p) => ({
title: decodeURIComponent(p.title),
subtitle: decodeURIComponent(p.subtitle),
// icon: p.icon,
arg: p.folderUri,
uid: p.uid,
}));
// console.log(`[info] Outputting projects:`, formatted);
alfy.output(formatted);
}
} catch (err) {
alfy.error(`[error] ${err}`);
// console.error(`[error] ${err}`);
throw err;
}
}
main();