From 7b196df3f03f733e147913cae81d469fb23d16e2 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 14:48:22 +0900 Subject: [PATCH 1/8] improvement(src): Remove uid from response item for exact search results --- src/alfred/response.test.ts | 4 +--- src/alfred/response.ts | 3 ++- src/icons.test.ts | 12 +++++------- src/icons.ts | 1 - src/put.ts | 3 +-- src/search.test.ts | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/alfred/response.test.ts b/src/alfred/response.test.ts index 1b15715f..c0a5b5d3 100644 --- a/src/alfred/response.test.ts +++ b/src/alfred/response.test.ts @@ -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", @@ -13,7 +12,6 @@ const response: TResponse = { }, }, { - uid: "f271", title: "calendar-plus", subtitle: "Paste class name: fa-calendar-plus", arg: "f217", @@ -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); }); diff --git a/src/alfred/response.ts b/src/alfred/response.ts index 55b874e7..da757aaa 100644 --- a/src/alfred/response.ts +++ b/src/alfred/response.ts @@ -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 diff --git a/src/icons.test.ts b/src/icons.test.ts index 8c204d65..844305eb 100644 --- a/src/icons.test.ts +++ b/src/icons.test.ts @@ -1,7 +1,7 @@ import { getAllIcons, toResponseItem } from "./icons"; test("toResponseItem()", () => { - const faIconObject = { + const iconObject = { name: "font-awesome", free: ["brands"], label: "Font Awesome", @@ -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", @@ -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); }); diff --git a/src/icons.ts b/src/icons.ts index 2156ca74..1f7c37d5 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -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, diff --git a/src/put.ts b/src/put.ts index 7a212d50..3e9f9847 100644 --- a/src/put.ts +++ b/src/put.ts @@ -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(); diff --git a/src/search.test.ts b/src/search.test.ts index 54badd62..45f20d18 100644 --- a/src/search.test.ts +++ b/src/search.test.ts @@ -171,7 +171,7 @@ describe("toJson()", () => { ]; const actual = toJson(searchResult); const expected = - '{"items":[{"uid":"BBBCCC","title":"BBBCCC","subtitle":"Paste class name: fa-BBBCCC","arg":"BBBCCC","icon":{"path":"./icons/BBBCCC.png"}},{"uid":"AAABBB","title":"AAABBB","subtitle":"Paste class name: fa-AAABBB","arg":"AAABBB","icon":{"path":"./icons/AAABBB.png"}}]}'; + '{"items":[{"title":"BBBCCC","subtitle":"Paste class name: fa-BBBCCC","arg":"BBBCCC","icon":{"path":"./icons/BBBCCC.png"}},{"title":"AAABBB","subtitle":"Paste class name: fa-AAABBB","arg":"AAABBB","icon":{"path":"./icons/AAABBB.png"}}]}'; expect(actual).toStrictEqual(expected); }); From 4d19dee23be80d4ba37e8719481db3e87ebd9f6f Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 14:49:41 +0900 Subject: [PATCH 2/8] style(lint): npm run check --- renovate.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/renovate.json b/renovate.json index b224bc9f..da439513 100644 --- a/renovate.json +++ b/renovate.json @@ -1,7 +1,5 @@ { - "extends": [ - "config:base" - ], + "extends": ["config:base"], "enabledManagers": ["npm"], "ignoreDeprecated": true, "timezone": "Asia/Tokyo", From 2dc1808f85c380c9f7c282288f539ddc5796d915 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 14:51:29 +0900 Subject: [PATCH 3/8] build(npm): Improve npm script name --- .github/workflows/test.yml | 4 ++-- package.json | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5b1e59d..4449f3ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/package.json b/package.json index 629f8ba4..306d9afd 100644 --- a/package.json +++ b/package.json @@ -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'", From 239412858c9a36b8c2cb61878e7c7e8957eadef4 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 14:54:51 +0900 Subject: [PATCH 4/8] improvement(src): Improve search key --- src/index.ts | 5 +- src/search.test.ts | 155 +++++++++++++++------------------------------ src/search.ts | 11 +++- 3 files changed, 62 insertions(+), 109 deletions(-) diff --git a/src/index.ts b/src/index.ts index 088126a5..a2ce58bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,11 +12,10 @@ const FLAG_PUT_URL = "--put-url"; 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); + const searchResult = search(list, query); console.log(toJson(searchResult)); // NOTE: Output to Alfred return; } @@ -50,7 +49,7 @@ const main = () => { } // NOTE: No flags - console.log(toJson(search(list, keys, ""))); // NOTE: Output to Alfred + console.log(toJson(search(list, ""))); // NOTE: Output to Alfred }; main(); diff --git a/src/search.test.ts b/src/search.test.ts index 45f20d18..51c78f53 100644 --- a/src/search.test.ts +++ b/src/search.test.ts @@ -1,72 +1,59 @@ import { TIconObject } from "./assets/icons_object"; import { search, toJson } from "./search"; -describe("search()", () => { - const list: TIconObject[] = [ - { - name: "AAABBB", - search: { - terms: ["111", "222", "333"], - }, - unicode: "unicode", - label: "label", - free: ["free"], - }, - { - name: "BBBCCC", - search: { - terms: ["222", "444", "666"], - }, - unicode: "unicode", - label: "label", - free: ["free"], - }, - { - name: "CCCDDD", - search: { - terms: ["333", "666", "999"], - }, - unicode: "unicode", - label: "label", - free: ["free"], - }, - ]; +const EXAMPLE_LIST_1: TIconObject = { + name: "AAABBB", + search: { + terms: ["111", "222", "333"], + }, + unicode: "unicode", + label: "label", + free: ["free"], +}; + +const EXAMPLE_LIST_2: TIconObject = { + name: "BBBCCC", + search: { + terms: ["222", "444", "666"], + }, + unicode: "unicode", + label: "label", + free: ["free"], +}; +const EXAMPLE_LIST_3: TIconObject = { + name: "CCCDDD", + search: { + terms: ["333", "666", "999"], + }, + unicode: "unicode", + label: "label", + free: ["free"], +}; + +const EXAMPLE_LIST: TIconObject[] = [ + EXAMPLE_LIST_1, + EXAMPLE_LIST_2, + EXAMPLE_LIST_3, +]; + +describe("search()", () => { test("empty query", () => { - const keys = ["name", "search.terms"]; const query = ""; - const actual = search(list, keys, query); + const actual = search(EXAMPLE_LIST, query); const expected = [ { - item: { - free: ["free"], - label: "label", - name: "AAABBB", - search: { terms: ["111", "222", "333"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_1, refIndex: 0, score: 0, }, { - item: { - free: ["free"], - label: "label", - name: "BBBCCC", - search: { terms: ["222", "444", "666"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_2, refIndex: 1, score: 0, }, { - item: { - free: ["free"], - label: "label", - name: "CCCDDD", - search: { terms: ["333", "666", "999"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_3, refIndex: 2, score: 0, }, @@ -77,31 +64,18 @@ describe("search()", () => { }); test("name key", () => { - const keys = ["name", "search.terms"]; const query = "BBB"; - const actual = search(list, keys, query); + const actual = search(EXAMPLE_LIST, query); const expected = [ { - item: { - free: ["free"], - label: "label", - name: "BBBCCC", - search: { terms: ["222", "444", "666"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_2, refIndex: 1, - score: 0.001, + score: 0.007943282347242817, }, { - item: { - free: ["free"], - label: "label", - name: "AAABBB", - search: { terms: ["111", "222", "333"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_1, refIndex: 0, - score: 0.03, + score: 0.08589836120408871, }, ]; @@ -110,31 +84,18 @@ describe("search()", () => { }); test("search.terms key", () => { - const keys = ["name", "search.terms"]; const query = "666"; - const actual = search(list, keys, query); + const actual = search(EXAMPLE_LIST, query); const expected = [ { - item: { - free: ["free"], - label: "label", - name: "BBBCCC", - search: { terms: ["222", "444", "666"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_2, refIndex: 1, - score: 2.220446049250313e-16, + score: 0.000020134092876783674, }, { - item: { - free: ["free"], - label: "label", - name: "CCCDDD", - search: { terms: ["333", "666", "999"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_3, refIndex: 2, - score: 2.220446049250313e-16, + score: 0.000020134092876783674, }, ]; @@ -147,24 +108,12 @@ describe("toJson()", () => { test("", () => { const searchResult = [ { - item: { - free: ["free"], - label: "label", - name: "BBBCCC", - search: { terms: ["222", "444", "666"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_2, refIndex: 1, score: 0.001, }, { - item: { - free: ["free"], - label: "label", - name: "AAABBB", - search: { terms: ["111", "222", "333"] }, - unicode: "unicode", - }, + item: EXAMPLE_LIST_1, refIndex: 0, score: 0.03, }, diff --git a/src/search.ts b/src/search.ts index bd8840da..f612d4b2 100644 --- a/src/search.ts +++ b/src/search.ts @@ -9,10 +9,15 @@ type TSearchResult = Readonly<{ score: number; }>; +const DEFAULT_KEYS = [ + { name: "name", weight: 0.7 }, + { name: "search.terms", weight: 0.3 }, +]; + export const search = ( list: TIconObject[], - keys: string[], - query: string + query: string, + keys?: string[] ): TSearchResult[] => { if (!query) { return list.map((item, i) => { @@ -27,7 +32,7 @@ export const search = ( const options = { includeScore: true, useExtendedSearch: true, - keys: keys, + keys: keys ?? DEFAULT_KEYS, } as const; const fuse = new Fuse(list, options, undefined); From 5f98ce16c44d1c096dbdc28ad4db826c2e82af11 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 15:04:57 +0900 Subject: [PATCH 5/8] refactor(src): Improve FLAG constant --- src/index.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index a2ce58bb..8093e118 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,46 +3,50 @@ 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 main = () => { const args = getArgs(); const list = getAllIconsObject(); - if (includesFlag(args, FLAG_FIND)) { - const query = getFlagArgs(args, FLAG_FIND); + if (includesFlag(args, FLAG.FIND)) { + const query = getFlagArgs(args, FLAG.FIND); const searchResult = search(list, query); console.log(toJson(searchResult)); // NOTE: Output to Alfred 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 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 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 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 return; From 176b59a906d7311c8d2df41db040d397c32d945a Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 15:07:09 +0900 Subject: [PATCH 6/8] refactor(src): Change output method --- src/index.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8093e118..0498c728 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,10 @@ const FLAG = { }, }; +const output = (str: string): void => { + process.stdout.write(str); // NOTE: Output to Alfred +}; + const main = () => { const args = getArgs(); const list = getAllIconsObject(); @@ -20,40 +24,40 @@ const main = () => { if (includesFlag(args, FLAG.FIND)) { const query = getFlagArgs(args, FLAG.FIND); const searchResult = search(list, query); - console.log(toJson(searchResult)); // NOTE: Output to Alfred + output(toJson(searchResult)); return; } 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); 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); 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); const result = putUrl(query); - result && console.log(result); // NOTE: Output to Alfred + result && output(result); return; } // NOTE: No flags - console.log(toJson(search(list, ""))); // NOTE: Output to Alfred + output(toJson(search(list, ""))); }; main(); From 53f450ad5604e531285436ab5519ddd51102f6d9 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 15:14:02 +0900 Subject: [PATCH 7/8] improvement(assets): Update info.plist --- assets/info.plist | 64 ++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/assets/info.plist b/assets/info.plist index 9c4b487c..75076fe5 100644 --- a/assets/info.plist +++ b/assets/info.plist @@ -16,13 +16,15 @@ Search through Font Awesome icons bundleid com.ruedap.font-awesome + disabled + connections 06116C11-3F9B-438E-A515-7D3CA35574BE destinationuid - 61DCB2DD-8EF7-447E-BED3-63AA4B73235C + AA55FF93-E3ED-430B-B08E-62236574DD0F modifiers 0 modifiersubtext @@ -114,8 +116,6 @@ - disabled - objects @@ -256,25 +256,21 @@ config - concurrently - - escaping - 0 - script - open {query} - scriptargtype - 0 - scriptfile + browser - type - 0 + spaces + + url + + utf8 + type - alfred.workflow.action.script + alfred.workflow.action.openurl uid - 61DCB2DD-8EF7-447E-BED3-63AA4B73235C + AA55FF93-E3ED-430B-B08E-62236574DD0F version - 2 + 1 config @@ -305,51 +301,51 @@ 06116C11-3F9B-438E-A515-7D3CA35574BE xpos - 500 + 230 ypos - 340 + 350 21557827-8003-42B7-A042-16D4C9278FEC xpos - 300 + 30 ypos - 120 + 130 2D5AC270-69DB-4E00-BE29-B7F4927E632A xpos - 500 + 230 ypos - 10 + 20 - 61DCB2DD-8EF7-447E-BED3-63AA4B73235C + 8CBC1CA3-D946-4766-9551-505842A4BE52 xpos - 700 + 430 ypos - 340 + 130 - 8CBC1CA3-D946-4766-9551-505842A4BE52 + 8EEB02DD-09BA-4657-A9D8-ACE675D342BC xpos - 700 + 230 ypos - 120 + 130 - 8EEB02DD-09BA-4657-A9D8-ACE675D342BC + AA55FF93-E3ED-430B-B08E-62236574DD0F xpos - 500 + 430 ypos - 120 + 350 CE9A7E05-0277-46D5-941F-E5DEC7D9F6F7 xpos - 500 + 230 ypos - 230 + 240 variablesdontexport From 6f793e7b9dcb0793bd85709b71d0706bff839ca5 Mon Sep 17 00:00:00 2001 From: ruedap Date: Sun, 30 Aug 2020 15:15:35 +0900 Subject: [PATCH 8/8] chore(release): Bump verstion to 5.14.0.1 --- assets/info.plist | 4 ++-- ga | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 ga diff --git a/assets/info.plist b/assets/info.plist index 75076fe5..42b6fdf2 100644 --- a/assets/info.plist +++ b/assets/info.plist @@ -3,9 +3,9 @@ name - Font Awesome 5.14.0.0 + Font Awesome 5.14.0.1 version - 5.14.0.0 + 5.14.0.1 webaddress https://github.com/ruedap/alfred-font-awesome-workflow readme diff --git a/ga b/ga new file mode 100644 index 00000000..e69de29b