Skip to content

Commit

Permalink
Merge pull request #125 from ruedap/improve-search-results
Browse files Browse the repository at this point in the history
Improve search results
  • Loading branch information
ruedap authored Aug 30, 2020
2 parents b362ffa + 6f793e7 commit 2e2dd3b
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 192 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: Build
run: npm run build

- name: Cmd
run: npm run cmd
- name: Test command
run: npm run test:cmd
68 changes: 32 additions & 36 deletions assets/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>name</key>
<string>Font Awesome 5.14.0.0</string>
<string>Font Awesome 5.14.0.1</string>
<key>version</key>
<string>5.14.0.0</string>
<string>5.14.0.1</string>
<key>webaddress</key>
<string>https://github.com/ruedap/alfred-font-awesome-workflow</string>
<key>readme</key>
Expand All @@ -16,13 +16,15 @@
<string>Search through Font Awesome icons</string>
<key>bundleid</key>
<string>com.ruedap.font-awesome</string>
<key>disabled</key>
<false/>
<key>connections</key>
<dict>
<key>06116C11-3F9B-438E-A515-7D3CA35574BE</key>
<array>
<dict>
<key>destinationuid</key>
<string>61DCB2DD-8EF7-447E-BED3-63AA4B73235C</string>
<string>AA55FF93-E3ED-430B-B08E-62236574DD0F</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
Expand Down Expand Up @@ -114,8 +116,6 @@
</dict>
</array>
</dict>
<key>disabled</key>
<false/>
<key>objects</key>
<array>
<dict>
Expand Down Expand Up @@ -256,25 +256,21 @@
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>open {query}</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<key>browser</key>
<string></string>
<key>type</key>
<integer>0</integer>
<key>spaces</key>
<string></string>
<key>url</key>
<string></string>
<key>utf8</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>61DCB2DD-8EF7-447E-BED3-63AA4B73235C</string>
<string>AA55FF93-E3ED-430B-B08E-62236574DD0F</string>
<key>version</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -305,51 +301,51 @@
<key>06116C11-3F9B-438E-A515-7D3CA35574BE</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<integer>230</integer>
<key>ypos</key>
<real>340</real>
<integer>350</integer>
</dict>
<key>21557827-8003-42B7-A042-16D4C9278FEC</key>
<dict>
<key>xpos</key>
<integer>300</integer>
<integer>30</integer>
<key>ypos</key>
<real>120</real>
<integer>130</integer>
</dict>
<key>2D5AC270-69DB-4E00-BE29-B7F4927E632A</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<integer>230</integer>
<key>ypos</key>
<real>10</real>
<integer>20</integer>
</dict>
<key>61DCB2DD-8EF7-447E-BED3-63AA4B73235C</key>
<key>8CBC1CA3-D946-4766-9551-505842A4BE52</key>
<dict>
<key>xpos</key>
<integer>700</integer>
<integer>430</integer>
<key>ypos</key>
<real>340</real>
<integer>130</integer>
</dict>
<key>8CBC1CA3-D946-4766-9551-505842A4BE52</key>
<key>8EEB02DD-09BA-4657-A9D8-ACE675D342BC</key>
<dict>
<key>xpos</key>
<integer>700</integer>
<integer>230</integer>
<key>ypos</key>
<real>120</real>
<integer>130</integer>
</dict>
<key>8EEB02DD-09BA-4657-A9D8-ACE675D342BC</key>
<key>AA55FF93-E3ED-430B-B08E-62236574DD0F</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<integer>430</integer>
<key>ypos</key>
<real>120</real>
<integer>350</integer>
</dict>
<key>CE9A7E05-0277-46D5-941F-E5DEC7D9F6F7</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<integer>230</integer>
<key>ypos</key>
<real>230</real>
<integer>240</integer>
</dict>
</dict>
<key>variablesdontexport</key>
Expand Down
Empty file added ga
Empty file.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"build": "npm run clean && npm run compile && npm run package && npm run compress",
"build:open": "npm run build && npm run open",
"open": "open ./dist/Font-Awesome.alfredworkflow",
"cmd:find": "./dist/font-awesome-workflow --find font-awesome flag",
"cmd:put:name": "./dist/font-awesome-workflow --put-name font-awesome",
"cmd:put:code": "./dist/font-awesome-workflow --put-code font-awesome",
"cmd:put:ref": "./dist/font-awesome-workflow --put-ref font-awesome",
"cmd:put:url": "./dist/font-awesome-workflow --put-url font-awesome",
"cmd:put": "npm run cmd:put:name && npm run cmd:put:code && npm run cmd:put:ref && npm run cmd:put:url",
"cmd": "npm run cmd:find && npm run cmd:put",
"exec": "npm run clean && npm run compile && node ./dist/index.js",
"test": "jest",
"test:watch": "jest --watchAll",
"test:cmd:find": "./dist/font-awesome-workflow --find font-awesome flag",
"test:cmd:put:name": "./dist/font-awesome-workflow --put-name font-awesome",
"test:cmd:put:code": "./dist/font-awesome-workflow --put-code font-awesome",
"test:cmd:put:ref": "./dist/font-awesome-workflow --put-ref font-awesome",
"test:cmd:put:url": "./dist/font-awesome-workflow --put-url font-awesome",
"test:cmd:put": "npm run test:cmd:put:name && npm run test:cmd:put:code && npm run test:cmd:put:ref && npm run test:cmd:put:url",
"test:cmd": "npm run test:cmd:find && npm run test:cmd:put",
"fmt": "prettier --write .",
"lint": "eslint . --ext 'ts,js'",
"lint:fix": "eslint . --fix --ext 'ts,js'",
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": [
"config:base"
],
"extends": ["config:base"],
"enabledManagers": ["npm"],
"ignoreDeprecated": true,
"timezone": "Asia/Tokyo",
Expand Down
4 changes: 1 addition & 3 deletions src/alfred/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { toJson, TResponse } from "./response";
const response: TResponse = {
items: [
{
uid: "f26e",
title: "500px",
subtitle: "Paste class name: fa-500px",
arg: "f26e",
Expand All @@ -13,7 +12,6 @@ const response: TResponse = {
},
},
{
uid: "f271",
title: "calendar-plus",
subtitle: "Paste class name: fa-calendar-plus",
arg: "f217",
Expand All @@ -28,6 +26,6 @@ const response: TResponse = {
test("toJson", () => {
const actual = toJson(response);
const expected =
'{"items":[{"uid":"f26e","title":"500px","subtitle":"Paste class name: fa-500px","arg":"f26e","icon":{"type":"fileicon","path":"./icons/500px.png"}},{"uid":"f271","title":"calendar-plus","subtitle":"Paste class name: fa-calendar-plus","arg":"f217","icon":{"type":"fileicon","path":"./icons/calendar-plus.png"}}]}';
'{"items":[{"title":"500px","subtitle":"Paste class name: fa-500px","arg":"f26e","icon":{"type":"fileicon","path":"./icons/500px.png"}},{"title":"calendar-plus","subtitle":"Paste class name: fa-calendar-plus","arg":"f217","icon":{"type":"fileicon","path":"./icons/calendar-plus.png"}}]}';
expect(actual).toBe(expected);
});
3 changes: 2 additions & 1 deletion src/alfred/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type TText = Readonly<{
}>;

export type TResponseItem = Readonly<{
uid: string;
// NOTE: If you would like Alfred to always show the results in the order you return them from your script, exclude the UID field.
uid?: string;
title: string;
subtitle: string;
arg: string; // recommended
Expand Down
12 changes: 5 additions & 7 deletions src/icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAllIcons, toResponseItem } from "./icons";

test("toResponseItem()", () => {
const faIconObject = {
const iconObject = {
name: "font-awesome",
free: ["brands"],
label: "Font Awesome",
Expand All @@ -10,9 +10,8 @@ test("toResponseItem()", () => {
unicode: "f2b4",
};

const actual = toResponseItem(faIconObject);
const actual = toResponseItem(iconObject);
const expected = {
uid: "font-awesome",
title: "font-awesome",
subtitle: "Paste class name: fa-font-awesome",
arg: "font-awesome",
Expand All @@ -25,13 +24,12 @@ test("getAllIcons()", () => {
const allIcons = getAllIcons();
expect(allIcons.items.length).toBe(1448);

const faIcon = allIcons.items.find((icon) => icon.uid === "font-awesome");
const faIconExpected = {
const actual = allIcons.items.find((icon) => icon.arg === "font-awesome");
const expected = {
arg: "font-awesome",
icon: { path: "./icons/font-awesome.png" },
subtitle: "Paste class name: fa-font-awesome",
title: "font-awesome",
uid: "font-awesome",
};
expect(faIcon).toStrictEqual(faIconExpected);
expect(actual).toStrictEqual(expected);
});
1 change: 0 additions & 1 deletion src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getAllIconsObject, TIconObject } from "./assets/icons_object";

export const toResponseItem = (iconObject: TIconObject): TResponseItem => {
return {
uid: iconObject.name,
title: iconObject.name,
subtitle: `Paste class name: fa-${iconObject.name}`,
arg: iconObject.name,
Expand Down
53 changes: 30 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,61 @@ import { putCode, putName, putRef, putUrl } from "./put";
import { getArgs, getFlagArgs, includesFlag } from "./query";
import { search, toJson } from "./search";

const FLAG_FIND = "--find";
const FLAG_PUT_NAME = "--put-name";
const FLAG_PUT_CODE = "--put-code";
const FLAG_PUT_REF = "--put-ref";
const FLAG_PUT_URL = "--put-url";
const FLAG = {
FIND: "--find",
PUT: {
NAME: "--put-name",
CODE: "--put-code",
REF: "--put-ref",
URL: "--put-url",
},
};

const output = (str: string): void => {
process.stdout.write(str); // NOTE: Output to Alfred
};

const main = () => {
const args = getArgs();
const list = getAllIconsObject();
const keys = ["name", "search.terms"];

if (includesFlag(args, FLAG_FIND)) {
const query = getFlagArgs(args, FLAG_FIND);
const searchResult = search(list, keys, query);
console.log(toJson(searchResult)); // NOTE: Output to Alfred
if (includesFlag(args, FLAG.FIND)) {
const query = getFlagArgs(args, FLAG.FIND);
const searchResult = search(list, query);
output(toJson(searchResult));
return;
}

if (includesFlag(args, FLAG_PUT_NAME)) {
const query = getFlagArgs(args, FLAG_PUT_NAME);
if (includesFlag(args, FLAG.PUT.NAME)) {
const query = getFlagArgs(args, FLAG.PUT.NAME);
const result = putName(query);
result && console.log(result); // NOTE: Output to Alfred
result && output(result);
return;
}

if (includesFlag(args, FLAG_PUT_CODE)) {
const query = getFlagArgs(args, FLAG_PUT_CODE);
if (includesFlag(args, FLAG.PUT.CODE)) {
const query = getFlagArgs(args, FLAG.PUT.CODE);
const result = putCode(query);
result && console.log(result); // NOTE: Output to Alfred
result && output(result);
return;
}

if (includesFlag(args, FLAG_PUT_REF)) {
const query = getFlagArgs(args, FLAG_PUT_REF);
if (includesFlag(args, FLAG.PUT.REF)) {
const query = getFlagArgs(args, FLAG.PUT.REF);
const result = putRef(query);
result && console.log(result); // NOTE: Output to Alfred
result && output(result);
return;
}

if (includesFlag(args, FLAG_PUT_URL)) {
const query = getFlagArgs(args, FLAG_PUT_URL);
if (includesFlag(args, FLAG.PUT.URL)) {
const query = getFlagArgs(args, FLAG.PUT.URL);
const result = putUrl(query);
result && console.log(result); // NOTE: Output to Alfred
result && output(result);
return;
}

// NOTE: No flags
console.log(toJson(search(list, keys, ""))); // NOTE: Output to Alfred
output(toJson(search(list, "")));
};

main();
3 changes: 1 addition & 2 deletions src/put.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TResponseItem } from "./alfred/response";
import { getAllIconsObject, TIconObject } from "./assets/icons_object";

type Query = TResponseItem["uid"];
type Query = string;

const getIconObject = (query: Query): TIconObject | undefined => {
const allIconsObject = getAllIconsObject();
Expand Down
Loading

0 comments on commit 2e2dd3b

Please sign in to comment.