alfy 0.11.0 → 0.12.2

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/cleanup.js CHANGED
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
- const execa = require('execa');
2
+ import process from 'node:process';
3
+ import {fileURLToPath} from 'node:url';
4
+ import path from 'node:path';
5
+ import execa from 'execa';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
8
 
5
9
  (async () => {
6
10
  try {
7
11
  await execa('alfred-unlink', {
8
12
  preferLocal: true,
9
- localDir: __dirname
13
+ localDir: __dirname,
10
14
  });
11
15
  } catch (error) {
12
16
  console.error(error);
package/index.d.ts ADDED
@@ -0,0 +1,554 @@
1
+ import Conf from 'conf';
2
+ import {Options} from 'got';
3
+
4
+ export interface FetchOptions extends Options {
5
+ /**
6
+ URL search parameters.
7
+ */
8
+ readonly query?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams | undefined;
9
+
10
+ /**
11
+ Number of milliseconds this request should be cached.
12
+ */
13
+ readonly maxAge?: number;
14
+
15
+ /**
16
+ Transform the response before it gets cached.
17
+ */
18
+ readonly transform?: (body: unknown) => unknown;
19
+ }
20
+
21
+ export interface OutputOptions {
22
+ /**
23
+ A script can be set to re-run automatically after some interval.
24
+
25
+ The script will only be re-run if the script filter is still active and the user hasn't changed the state of the filter by typing and triggering a re-run. For example, it could be used to update the progress of a particular task:
26
+ */
27
+ readonly rerunInterval?: number;
28
+ }
29
+
30
+ export interface CacheConfGetOptions {
31
+ /**
32
+ Get the item for the key provided without taking the `maxAge` of the item into account.
33
+ */
34
+ readonly ignoreMaxAge?: boolean;
35
+ }
36
+
37
+ export interface CacheConfSetOptions {
38
+ /**
39
+ Number of milliseconds the cached value is valid.
40
+ */
41
+ readonly maxAge?: number;
42
+ }
43
+
44
+ export interface CacheConf<T> extends Conf<T> {
45
+ isExpired: (key: T) => boolean;
46
+
47
+ get<Key extends keyof T>(key: Key, options?: CacheConfGetOptions): T[Key];
48
+ get<Key extends keyof T>(key: Key, defaultValue: Required<T>[Key], options?: CacheConfGetOptions): Required<T>[Key];
49
+ get<Key extends string, Value = unknown>(key: Exclude<Key, keyof T>, defaultValue?: Value, options?: CacheConfGetOptions): Value;
50
+ get(key: string, defaultValue?: unknown, options?: CacheConfGetOptions): unknown;
51
+
52
+ set<Key extends keyof T>(key: Key, value?: T[Key], options?: CacheConfSetOptions): void;
53
+ set(key: string, value: unknown, options: CacheConfSetOptions): void;
54
+ set(object: Partial<T>, options: CacheConfSetOptions): void;
55
+ set<Key extends keyof T>(key: Partial<T> | Key | string, value?: T[Key] | unknown, options?: CacheConfSetOptions): void;
56
+ }
57
+
58
+ /**
59
+ The icon displayed in the result row. Workflows are run from their workflow folder, so you can reference icons stored in your workflow relatively.
60
+
61
+ By omitting the `.type`, Alfred will load the file path itself, for example a PNG.
62
+
63
+ By using `{type: 'fileicon}`, Alfred will get the icon for the specified path.
64
+
65
+ Finally, by using `{type: 'filetype'}`, you can get the icon of a specific file. For example, `{path: 'public.png'}`.
66
+ */
67
+ export interface IconElement {
68
+ readonly path?: string;
69
+ readonly type?: 'fileicon' | 'filetype';
70
+ }
71
+
72
+ /**
73
+ The text element defines the text the user will get when copying the selected result row with `⌘C` or displaying large type with `⌘L`.
74
+
75
+ If these are not defined, you will inherit Alfred's standard behaviour where the argument is copied to the Clipboard or used for Large Type.
76
+ */
77
+ export interface TextElement {
78
+ /**
79
+ User will get when copying the selected result row with `⌘C`.
80
+ */
81
+ readonly copy?: string;
82
+
83
+ /**
84
+ User will get displaying large type with `⌘L`.
85
+ */
86
+ readonly largetype?: string;
87
+ }
88
+
89
+ /**
90
+ Defines what to change when the modifier key is pressed.
91
+
92
+ When you release the modifier key, it returns to the original item.
93
+ */
94
+ export interface ModifierKeyItem {
95
+ readonly valid?: boolean;
96
+ readonly title?: string;
97
+ readonly subtitle?: string;
98
+ readonly arg?: string;
99
+ readonly icon?: string;
100
+ readonly variables?: Record<string, string>;
101
+ }
102
+
103
+ /**
104
+ This element defines the Universal Action items used when actioning the result, and overrides arg being used for actioning.
105
+
106
+ The action key can take a string or array for simple types, and the content type will automatically be derived by Alfred to file, URL or text.
107
+ */
108
+ export interface ActionElement {
109
+ /**
110
+ Forward text to Alfred.
111
+ */
112
+ readonly text?: string | string[];
113
+
114
+ /**
115
+ Forward URL to Alfred.
116
+ */
117
+ readonly url?: string | string[];
118
+
119
+ /**
120
+ Forward file path to Alfred.
121
+ */
122
+ readonly file?: string | string[];
123
+
124
+ /**
125
+ Forward some value and let the value type be infered from Alfred.
126
+ */
127
+ readonly auto?: string | string[];
128
+ }
129
+
130
+ type PossibleModifiers = 'fn' | 'ctrl' | 'opt' | 'cmd' | 'shift';
131
+
132
+ /**
133
+ Each item describes a result row displayed in Alfred.
134
+ */
135
+ export interface ScriptFilterItem {
136
+ /**
137
+ This is a unique identifier for the item which allows help Alfred to learn about this item for subsequent sorting and ordering of the user's actioned results.
138
+
139
+ It is important that you use the same UID throughout subsequent executions of your script to take advantage of Alfred's knowledge and sorting.
140
+
141
+ If you would like Alfred to always show the results in the order you return them from your script, exclude the UID field.
142
+ */
143
+ readonly uid?: string;
144
+
145
+ /**
146
+ The title displayed in the result row. There are no options for this element and it is essential that this element is populated.
147
+
148
+ @example
149
+ ```
150
+ {title: 'Desktop'}
151
+ ```
152
+ */
153
+ readonly title: string;
154
+
155
+ /**
156
+ The subtitle displayed in the result row. This element is optional.
157
+
158
+ @example
159
+ ```
160
+ {subtitle: '~/Desktop'}
161
+ ```
162
+ */
163
+ readonly subtitle?: string;
164
+
165
+ /**
166
+ The argument which is passed through the workflow to the connected output action.
167
+
168
+ While the `arg` attribute is optional, it's highly recommended that you populate this as it's the string which is passed to your connected output actions.
169
+
170
+ If excluded, you won't know which result item the user has selected.
171
+
172
+ @example
173
+ ```
174
+ {arg: '~/Desktop'}
175
+ ```
176
+ */
177
+ readonly arg?: string;
178
+
179
+ /**
180
+ The icon displayed in the result row. Workflows are run from their workflow folder, so you can reference icons stored in your workflow relatively.
181
+
182
+ By omitting the `.type`, Alfred will load the file path itself, for example a png.
183
+
184
+ By using `{type: 'fileicon'}`, Alfred will get the icon for the specified path. Finally, by using `{type: 'filetype'}`, you can get the icon of a specific file. For example, `{path: 'public.png'}`.
185
+
186
+ @example
187
+ ```
188
+ {
189
+ icon: {
190
+ type: 'fileicon',
191
+ path: '~/Desktop'
192
+ }
193
+ }
194
+ ```
195
+ */
196
+ readonly icon?: IconElement | string;
197
+
198
+ /**
199
+ If this item is valid or not. If an item is valid then Alfred will action this item when the user presses return.
200
+
201
+ @default true
202
+ */
203
+ readonly valid?: boolean;
204
+
205
+ /**
206
+ From Alfred 3.5, the match field enables you to define what Alfred matches against when the workflow is set to 'Alfred Filters Results'.
207
+
208
+ If match is present, it fully replaces matching on the title property.
209
+ */
210
+ readonly match?: string;
211
+
212
+ /**
213
+ An optional but recommended string you can provide which is populated into Alfred's search field if the user auto-complete's the selected result (`⇥` by default).
214
+ */
215
+ readonly autocomplete?: string;
216
+
217
+ /**
218
+ By specifying `{type: 'file'}`, it makes Alfred treat your result as a file on your system. This allows the user to perform actions on the file like they can with Alfred's standard file filters.
219
+
220
+ When returning files, Alfred will check if the file exists before presenting that result to the user.
221
+
222
+ This has a very small performance implication but makes the results as predictable as possible.
223
+
224
+ If you would like Alfred to skip this check as you are certain that the files you are returning exist, you can use `{type: 'file:skipcheck'}`.
225
+
226
+ @default 'default'
227
+ */
228
+ readonly type?: 'default' | 'file' | 'file:skipcheck';
229
+
230
+ /**
231
+ Gives you control over how the modifier keys react.
232
+
233
+ You can now define the valid attribute to mark if the result is valid based on the modifier selection and set a different arg to be passed out if actioned with the modifier.
234
+ */
235
+ readonly mods?: Partial<Record<PossibleModifiers, ModifierKeyItem>>;
236
+
237
+ /**
238
+ This element defines the Universal Action items used when actioning the result, and overrides arg being used for actioning.
239
+
240
+ The action key can take a string or array for simple types, and the content type will automatically be derived by Alfred to file, url or text.
241
+
242
+ @example
243
+ ```
244
+ {
245
+ // For Single Item,
246
+ action: 'Alfred is Great'
247
+
248
+ // For Multiple Items,
249
+ action: ['Alfred is Great', 'I use him all day long']
250
+
251
+ // For control over the content type of the action, you can use an object with typed keys as follows:
252
+ action: {
253
+ text: ['one', 'two', 'three'],
254
+ url: 'https://alfredapp.com',
255
+ file: '~/Desktop',
256
+ auto: '~/Pictures'
257
+ }
258
+ }
259
+ ```
260
+ */
261
+ // TODO (jopemachine): Activate attribute below after 'action' is implemented in Alfred.
262
+ // readonly action?: string | string[] | ActionElement;
263
+
264
+ /**
265
+ The text element defines the text the user will get when copying the selected result row with `⌘C` or displaying large type with `⌘L`.
266
+
267
+ @example
268
+ ```
269
+ {
270
+ text: {
271
+ copy: 'https://alfredapp.com (text here to copy)',
272
+ largetype: 'https://alfredapp.com (text here for large type)'
273
+ }
274
+ }
275
+ ```
276
+ */
277
+ readonly text?: TextElement;
278
+
279
+ /**
280
+ A Quick Look URL which will be visible if the user uses the Quick Look feature within Alfred (tapping shift, or `⌘Y`).
281
+
282
+ Note that it can also accept a file path, both absolute and relative to home using `~/`.
283
+
284
+ @example
285
+ ```
286
+ {
287
+ quicklookurl: 'https://alfredapp.com'
288
+ }
289
+ ```
290
+ */
291
+ readonly quicklookurl?: string;
292
+
293
+ /**
294
+ Variables can be passed out of the script filter within a variables object.
295
+ */
296
+ readonly variables?: Record<string, string>;
297
+ }
298
+
299
+ /**
300
+ Create Alfred workflows with ease
301
+
302
+ @example
303
+ ```
304
+ import alfy from 'alfy';
305
+
306
+ const data = await alfy.fetch('https://jsonplaceholder.typicode.com/posts');
307
+
308
+ const items = alfy
309
+ .inputMatches(data, 'title')
310
+ .map(element => ({
311
+ title: element.title,
312
+ subtitle: element.body,
313
+ arg: element.id
314
+ }));
315
+
316
+ alfy.output(items);
317
+ ```
318
+ */
319
+ export interface Alfy {
320
+ /**
321
+ Return output to Alfred.
322
+
323
+ @example
324
+ ```
325
+ import alfy from 'alfy';
326
+
327
+ alfy.output([
328
+ {
329
+ title: 'Unicorn'
330
+ },
331
+ {
332
+ title: 'Rainbow'
333
+ }
334
+ ]);
335
+ ```
336
+ */
337
+ output: (items: ScriptFilterItem[], options?: OutputOptions) => void;
338
+
339
+ /**
340
+ Returns items in list that case-insensitively contains input.
341
+
342
+ @example
343
+ ```
344
+ import alfy from 'alfy';
345
+
346
+ alfy.matches('Corn', ['foo', 'unicorn']);
347
+ //=> ['unicorn']
348
+ ```
349
+ */
350
+ matches: <T extends string[] | ScriptFilterItem[]> (input: string, list: T, target?: string | ((item: string | ScriptFilterItem, input: string) => boolean)) => T;
351
+
352
+ /**
353
+ Same as `matches()`, but with `alfy.input` as input.
354
+
355
+ @returns Items in list that case-insensitively contains `alfy.input`.
356
+
357
+ @example
358
+ ```
359
+ import alfy from 'alfy';
360
+
361
+ // Assume user types 'Corn'.
362
+
363
+ alfy.inputMatches(['foo', 'unicorn']);
364
+ //=> ['unicorn']
365
+ */
366
+ inputMatches: <T extends string[] | ScriptFilterItem[]> (list: T, target?: string | ((item: string | ScriptFilterItem, input: string) => boolean)) => T;
367
+
368
+ /**
369
+ Log value to the Alfred workflow debugger.
370
+
371
+ @param text
372
+ */
373
+ log: (text: string) => void;
374
+
375
+ /**
376
+ Display an error or error message in Alfred.
377
+
378
+ **Note:** You don't need to `.catch()` top-level promises. Alfy handles that for you.
379
+
380
+ @param error
381
+ */
382
+ error: (error: Error | string) => void;
383
+
384
+ /**
385
+ Fetch remote data.
386
+
387
+ @returns Body of the response.
388
+
389
+ @example
390
+ ```
391
+ import alfy from 'alfy';
392
+
393
+ await alfy.fetch('https://api.foo.com', {
394
+ transform: body => {
395
+ body.foo = 'bar';
396
+ return body;
397
+ }
398
+ })
399
+ ```
400
+ */
401
+ fetch: (url: string, options?: FetchOptions) => Promise<unknown>;
402
+
403
+ /**
404
+ @example
405
+ ```
406
+ {
407
+ name: 'Emoj',
408
+ version: '0.2.5',
409
+ uid: 'user.workflow.B0AC54EC-601C-479A-9428-01F9FD732959',
410
+ bundleId: 'com.sindresorhus.emoj'
411
+ }
412
+ ```
413
+ */
414
+ meta: {
415
+ name: string;
416
+ version: string;
417
+ bundleId: string;
418
+ type: string;
419
+ };
420
+
421
+ /**
422
+ Input from Alfred. What the user wrote in the input box.
423
+ */
424
+ input: string;
425
+
426
+ /**
427
+ Persist config data.
428
+
429
+ Exports a [`conf` instance](https://github.com/sindresorhus/conf#instance) with the correct config path set.
430
+
431
+ @example
432
+ ```
433
+ import alfy from 'alfy';
434
+
435
+ alfy.config.set('unicorn', '🦄');
436
+
437
+ alfy.config.get('unicorn');
438
+ //=> '🦄'
439
+ ```
440
+ */
441
+ config: Conf<Record<string, unknown>>;
442
+
443
+ /**
444
+ Persist cache data.
445
+
446
+ Exports a modified [`conf` instance](https://github.com/sindresorhus/conf#instance) with the correct cache path set.
447
+
448
+ @example
449
+ ```
450
+ import alfy from 'alfy';
451
+
452
+ alfy.cache.set('unicorn', '🦄');
453
+
454
+ alfy.cache.get('unicorn');
455
+ //=> '🦄'
456
+ ```
457
+ */
458
+ cache: CacheConf<unknown>;
459
+
460
+ /**
461
+ Get various default system icons.
462
+
463
+ The most useful ones are included as keys. The rest you can get with `icon.get()`. Go to `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources` in Finder to see them all.
464
+
465
+ @example
466
+ ```
467
+ import alfy from 'alfy';
468
+
469
+ console.log(alfy.icon.error);
470
+ //=> '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns'
471
+
472
+ console.log(alfy.icon.get('Clock'));
473
+ //=> '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Clock.icns'
474
+ ```
475
+ */
476
+ icon: {
477
+ /**
478
+ Get various default system icons.
479
+
480
+ You can get icons in `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources`.
481
+ */
482
+ get: (icon: string) => string;
483
+
484
+ /**
485
+ Get info icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo`.
486
+ */
487
+ info: string;
488
+
489
+ /**
490
+ Get warning icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon`.
491
+ */
492
+ warning: string;
493
+
494
+ /**
495
+ Get error icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon`.
496
+ */
497
+ error: string;
498
+
499
+ /**
500
+ Get alert icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Actions`.
501
+ */
502
+ alert: string;
503
+
504
+ /**
505
+ Get like icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarFavoritesIcon`.
506
+ */
507
+ like: string;
508
+
509
+ /**
510
+ Get delete icon which is `/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon`.
511
+ */
512
+ delete: string;
513
+ };
514
+
515
+ /**
516
+ Alfred metadata.
517
+ */
518
+ alfred: {
519
+ version: string;
520
+ theme: string;
521
+ themeBackground: string;
522
+ themeSelectionBackground: string;
523
+ themeSubtext: string;
524
+ data: string;
525
+ cache: string;
526
+ preferences: string;
527
+ preferencesLocalHash: string;
528
+ };
529
+
530
+ /**
531
+ Whether the user currently has the workflow debugger open.
532
+ */
533
+ debug: boolean;
534
+
535
+ /**
536
+ Exports a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) with the user workflow configuration. A workflow configuration allows your users to provide
537
+ configuration information for the workflow. For instance, if you are developing a GitHub workflow, you could let your users provide their own API tokens.
538
+
539
+ See [`alfred-config`](https://github.com/SamVerschueren/alfred-config#workflow-configuration) for more details.
540
+
541
+ @example
542
+ ```
543
+ import alfy from 'alfy';
544
+
545
+ alfy.userConfig.get('apiKey');
546
+ //=> '16811cad1b8547478b3e53eae2e0f083'
547
+ ```
548
+ */
549
+ userConfig: Map<string, string>;
550
+ }
551
+
552
+ declare const alfy: Alfy;
553
+
554
+ export default alfy;
package/index.js CHANGED
@@ -1,16 +1,19 @@
1
- 'use strict';
2
- const os = require('os');
3
- const Conf = require('conf');
4
- const got = require('got');
5
- const hookStd = require('hook-std');
6
- const loudRejection = require('loud-rejection');
7
- const cleanStack = require('clean-stack');
8
- const dotProp = require('dot-prop');
1
+ import os from 'node:os';
2
+ import process from 'node:process';
3
+ import {createRequire} from 'node:module';
4
+ import Conf from 'conf';
5
+ import got from 'got';
6
+ import hookStd from 'hook-std';
7
+ import loudRejection from 'loud-rejection';
8
+ import cleanStack from 'clean-stack';
9
+ import dotProp from 'dot-prop';
10
+ import AlfredConfig from 'alfred-config';
11
+ import updateNotification from './lib/update-notification.js';
12
+
13
+ const require = createRequire(import.meta.url);
9
14
  const CacheConf = require('cache-conf');
10
- const AlfredConfig = require('alfred-config');
11
- const updateNotification = require('./lib/update-notification');
12
15
 
13
- const alfy = module.exports;
16
+ const alfy = {};
14
17
 
15
18
  updateNotification();
16
19
 
@@ -21,7 +24,7 @@ alfy.meta = {
21
24
  name: getEnv('workflow_name'),
22
25
  version: getEnv('workflow_version'),
23
26
  uid: getEnv('workflow_uid'),
24
- bundleId: getEnv('workflow_bundleid')
27
+ bundleId: getEnv('workflow_bundleid'),
25
28
  };
26
29
 
27
30
  alfy.alfred = {
@@ -33,7 +36,7 @@ alfy.alfred = {
33
36
  data: getEnv('workflow_data'),
34
37
  cache: getEnv('workflow_cache'),
35
38
  preferences: getEnv('preferences'),
36
- preferencesLocalHash: getEnv('preferences_localhash')
39
+ preferencesLocalHash: getEnv('preferences_localhash'),
37
40
  };
38
41
 
39
42
  alfy.input = process.argv[2];
@@ -45,20 +48,20 @@ alfy.output = (items, {rerunInterval} = {}) => {
45
48
  alfy.matches = (input, list, item) => {
46
49
  input = input.toLowerCase().normalize();
47
50
 
48
- return list.filter(x => {
51
+ return list.filter(listItem => {
49
52
  if (typeof item === 'string') {
50
- x = dotProp.get(x, item);
53
+ listItem = dotProp.get(listItem, item);
51
54
  }
52
55
 
53
- if (typeof x === 'string') {
54
- x = x.toLowerCase();
56
+ if (typeof listItem === 'string') {
57
+ listItem = listItem.toLowerCase().normalize();
55
58
  }
56
59
 
57
60
  if (typeof item === 'function') {
58
- return item(x, input);
61
+ return item(listItem, input);
59
62
  }
60
63
 
61
- return x.includes(input);
64
+ return listItem.includes(input);
62
65
  });
63
66
  };
64
67
 
@@ -88,16 +91,16 @@ ${process.platform} ${os.release()}
88
91
  valid: false,
89
92
  text: {
90
93
  copy,
91
- largetype: stack
94
+ largetype: stack,
92
95
  },
93
96
  icon: {
94
- path: exports.icon.error
95
- }
97
+ path: alfy.icon.error,
98
+ },
96
99
  }]);
97
100
  };
98
101
 
99
102
  alfy.config = new Conf({
100
- cwd: alfy.alfred.data
103
+ cwd: alfy.alfred.data,
101
104
  });
102
105
 
103
106
  alfy.userConfig = new AlfredConfig();
@@ -105,13 +108,12 @@ alfy.userConfig = new AlfredConfig();
105
108
  alfy.cache = new CacheConf({
106
109
  configName: 'cache',
107
110
  cwd: alfy.alfred.cache,
108
- version: alfy.meta.version
111
+ version: alfy.meta.version,
109
112
  });
110
113
 
111
114
  alfy.fetch = async (url, options) => {
112
115
  options = {
113
- json: true,
114
- ...options
116
+ ...options,
115
117
  };
116
118
 
117
119
  if (typeof url !== 'string') {
@@ -132,7 +134,7 @@ alfy.fetch = async (url, options) => {
132
134
 
133
135
  let response;
134
136
  try {
135
- response = await got(url, options);
137
+ response = await got(url, {searchParams: options.query}).json();
136
138
  } catch (error) {
137
139
  if (cachedResponse) {
138
140
  return cachedResponse;
@@ -141,7 +143,7 @@ alfy.fetch = async (url, options) => {
141
143
  throw error;
142
144
  }
143
145
 
144
- const data = options.transform ? options.transform(response.body) : response.body;
146
+ const data = options.transform ? options.transform(response) : response;
145
147
 
146
148
  if (options.maxAge) {
147
149
  alfy.cache.set(key, data, {maxAge: options.maxAge});
@@ -159,9 +161,11 @@ alfy.icon = {
159
161
  error: getIcon('AlertStopIcon'),
160
162
  alert: getIcon('Actions'),
161
163
  like: getIcon('ToolbarFavoritesIcon'),
162
- delete: getIcon('ToolbarDeleteIcon')
164
+ delete: getIcon('ToolbarDeleteIcon'),
163
165
  };
164
166
 
165
167
  loudRejection(alfy.error);
166
168
  process.on('uncaughtException', alfy.error);
167
169
  hookStd.stderr(alfy.error);
170
+
171
+ export default alfy;
package/init.js CHANGED
@@ -1,17 +1,22 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
- const execa = require('execa');
2
+ import process from 'node:process';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+ import execa from 'execa';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
8
 
5
9
  (async () => {
6
10
  try {
7
11
  await execa('alfred-link', {
8
12
  preferLocal: true,
9
- localDir: __dirname
13
+ localDir: __dirname,
10
14
  });
11
15
 
12
16
  await execa('alfred-config', {
13
17
  preferLocal: true,
14
- localDir: __dirname
18
+ localDir: __dirname,
19
+ stdio: 'inherit',
15
20
  });
16
21
  } catch (error) {
17
22
  console.error(error);
@@ -1,12 +1,11 @@
1
- 'use strict';
2
- const readPkgUp = require('read-pkg-up');
3
- const alfredNotifier = require('alfred-notifier');
1
+ import {readPackageUpAsync} from 'read-pkg-up';
2
+ import alfredNotifier from 'alfred-notifier';
4
3
 
5
- module.exports = async () => {
6
- const {package: pkg} = await readPkgUp();
7
- const alfy = pkg.alfy || {};
4
+ export default async function updateNotification() {
5
+ const {package: pkg} = await readPackageUpAsync();
6
+ const alfy = (pkg || {}).alfy || {};
8
7
 
9
8
  if (alfy.updateNotification !== false) {
10
9
  alfredNotifier();
11
10
  }
12
- };
11
+ }
package/license CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "alfy",
3
- "version": "0.11.0",
3
+ "version": "0.12.2",
4
4
  "description": "Create Alfred workflows with ease",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/alfy",
7
+ "type": "module",
8
+ "exports": "./index.js",
7
9
  "bin": {
8
- "run-node": "run-node.sh",
9
- "alfy-init": "init.js",
10
- "alfy-cleanup": "cleanup.js"
10
+ "run-node": "./run-node.sh",
11
+ "alfy-init": "./init.js",
12
+ "alfy-cleanup": "./cleanup.js"
11
13
  },
12
14
  "engines": {
13
- "node": ">=8"
15
+ "node": ">=14.13.1"
14
16
  },
15
17
  "scripts": {
16
- "test": "xo && ava"
18
+ "test": "xo && ava && tsd"
17
19
  },
18
20
  "files": [
19
21
  "index.js",
22
+ "index.d.ts",
20
23
  "init.js",
21
24
  "cleanup.js",
22
25
  "run-node.sh",
@@ -36,23 +39,24 @@
36
39
  "dependencies": {
37
40
  "alfred-config": "^0.2.2",
38
41
  "alfred-link": "^0.3.1",
39
- "alfred-notifier": "^0.2.0",
42
+ "alfred-notifier": "^0.2.3",
40
43
  "cache-conf": "^0.6.0",
41
- "clean-stack": "^2.2.0",
42
- "conf": "^5.0.0",
43
- "dot-prop": "^5.1.0",
44
- "esm": "^3.2.18",
45
- "execa": "^2.0.4",
46
- "got": "^9.3.2",
44
+ "clean-stack": "^4.1.0",
45
+ "conf": "^10.0.1",
46
+ "dot-prop": "^6.0.1",
47
+ "execa": "^5.1.1",
48
+ "got": "^11.8.2",
47
49
  "hook-std": "^2.0.0",
48
- "loud-rejection": "^2.1.0",
49
- "read-pkg-up": "^6.0.0"
50
+ "loud-rejection": "^2.2.0",
51
+ "read-pkg-up": "^8.0.0"
50
52
  },
51
53
  "devDependencies": {
52
- "ava": "^2.3.0",
53
- "delay": "^4.3.0",
54
- "nock": "^13.1.0",
55
- "tempfile": "^3.0.0",
56
- "xo": "^0.24.0"
54
+ "ava": "^3.15.0",
55
+ "delay": "^5.0.0",
56
+ "nock": "^13.1.1",
57
+ "tempfile": "^4.0.0",
58
+ "tsd": "^0.17.0",
59
+ "typescript": "^4.3.5",
60
+ "xo": "^0.43.0"
57
61
  }
58
62
  }
package/readme.md CHANGED
@@ -12,12 +12,12 @@
12
12
  - Easily [testable workflows](#testing).
13
13
  - [Finds the `node` binary.](run-node.sh)
14
14
  - Support for top-level `await`.
15
- - Presents uncaught exceptions and unhandled Promise rejections to the user.<br>
15
+ - Presents uncaught exceptions and unhandled Promise rejections to the user.\
16
16
  *No need to manually `.catch()` top-level promises.*
17
17
 
18
18
  ## Prerequisites
19
19
 
20
- You need [Node.js 8+](https://nodejs.org) and [Alfred 3 or 4](https://www.alfredapp.com) with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.
20
+ You need [Node.js 14+](https://nodejs.org) and [Alfred 4](https://www.alfredapp.com) with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.
21
21
 
22
22
  ## Install
23
23
 
@@ -27,6 +27,8 @@ $ npm install alfy
27
27
 
28
28
  ## Usage
29
29
 
30
+ **IMPORTANT:** Your script will be run as [ESM](https://nodejs.org/api/esm.html).
31
+
30
32
  1. Create a new blank Alfred workflow.
31
33
 
32
34
  2. Add a `Script Filter` (right-click the canvas → `Inputs` → `Script Filter`), set `Language` to `/bin/bash`, and add the following script:
@@ -45,16 +47,18 @@ $ npm install alfy
45
47
 
46
48
  5. Initialize a repo with `npm init`.
47
49
 
48
- 6. Install Alfy with `npm install alfy`.
50
+ 6. Add `"type": "module"` to package.json.
51
+
52
+ 7. Install Alfy with `npm install alfy`.
49
53
 
50
- 7. In the workflow directory, create a `index.js` file, import `alfy`, and do your thing.
54
+ 8. In the workflow directory, create a `index.js` file, import `alfy`, and do your thing.
51
55
 
52
56
  ## Example
53
57
 
54
58
  Here we fetch some JSON from a placeholder API and present matching items to the user:
55
59
 
56
60
  ```js
57
- const alfy = require('alfy');
61
+ import alfy from 'alfy';
58
62
 
59
63
  const data = await alfy.fetch('https://jsonplaceholder.typicode.com/posts');
60
64
 
@@ -150,6 +154,8 @@ test('main', async t => {
150
154
  When developing your workflow it can be useful to be able to debug it when something is not working. This is when the [workflow debugger](https://www.alfredapp.com/help/workflows/advanced/debugger/) comes in handy. You can find it in your workflow view in Alfred. Press the insect icon to open it. It will show you the plain text output of `alfy.output()` and anything you log with `alfy.log()`:
151
155
 
152
156
  ```js
157
+ import alfy from 'alfy';
158
+
153
159
  const unicorn = getUnicorn();
154
160
  alfy.log(unicorn);
155
161
  ```
@@ -181,6 +187,8 @@ List of `object` with any of the [supported properties](https://www.alfredapp.co
181
187
  Example:
182
188
 
183
189
  ```js
190
+ import alfy from 'alfy';
191
+
184
192
  alfy.output([
185
193
  {
186
194
  title: 'Unicorn'
@@ -205,6 +213,8 @@ A script can be set to re-run automatically after some interval. The script will
205
213
  For example, it could be used to update the progress of a particular task:
206
214
 
207
215
  ```js
216
+ import alfy from 'alfy';
217
+
208
218
  alfy.output(
209
219
  [
210
220
  {
@@ -230,6 +240,8 @@ Log `value` to the [Alfred workflow debugger](https://www.alfredapp.com/help/wor
230
240
  Returns an `string[]` of items in `list` that case-insensitively contains `input`.
231
241
 
232
242
  ```js
243
+ import alfy from 'alfy';
244
+
233
245
  alfy.matches('Corn', ['foo', 'unicorn']);
234
246
  //=> ['unicorn']
235
247
  ```
@@ -255,6 +267,8 @@ By default, it will match against the `list` items.
255
267
  Specify a string to match against an object property:
256
268
 
257
269
  ```js
270
+ import alfy from 'alfy';
271
+
258
272
  const list = [
259
273
  {
260
274
  title: 'foo'
@@ -271,6 +285,8 @@ alfy.matches('Unicorn', list, 'title');
271
285
  Or [nested property](https://github.com/sindresorhus/dot-prop):
272
286
 
273
287
  ```js
288
+ import alfy from 'alfy';
289
+
274
290
  const list = [
275
291
  {
276
292
  name: {
@@ -293,6 +309,8 @@ alfy.matches('sindre', list, 'name.first');
293
309
  Specify a function to handle the matching yourself. The function receives the list item and input, both lowercased, as arguments, and is expected to return a boolean of whether it matches:
294
310
 
295
311
  ```js
312
+ import alfy from 'alfy';
313
+
296
314
  const list = ['foo', 'unicorn'];
297
315
 
298
316
  // Here we do an exact match.
@@ -355,6 +373,8 @@ Type: `Function`
355
373
  Transform the response before it gets cached.
356
374
 
357
375
  ```js
376
+ import alfy from 'alfy';
377
+
358
378
  await alfy.fetch('https://api.foo.com', {
359
379
  transform: body => {
360
380
  body.foo = 'bar';
@@ -366,8 +386,9 @@ await alfy.fetch('https://api.foo.com', {
366
386
  You can also return a Promise.
367
387
 
368
388
  ```js
369
- const xml2js = require('xml2js');
370
- const pify = require('pify');
389
+ import alfy from 'alfy';
390
+ import xml2js from 'xml2js';
391
+ import pify from 'pify';
371
392
 
372
393
  const parseString = pify(xml2js.parseString);
373
394
 
@@ -387,6 +408,8 @@ Exports a [`conf` instance](https://github.com/sindresorhus/conf#instance) with
387
408
  Example:
388
409
 
389
410
  ```js
411
+ import alfy from 'alfy';
412
+
390
413
  alfy.config.set('unicorn', '🦄');
391
414
 
392
415
  alfy.config.get('unicorn');
@@ -404,6 +427,8 @@ See [`alfred-config`](https://github.com/SamVerschueren/alfred-config#workflow-c
404
427
  Example:
405
428
 
406
429
  ```js
430
+ import alfy from 'alfy';
431
+
407
432
  alfy.userConfig.get('apiKey');
408
433
  //=> '16811cad1b8547478b3e53eae2e0f083'
409
434
  ```
@@ -419,6 +444,8 @@ Exports a modified [`conf` instance](https://github.com/sindresorhus/conf#instan
419
444
  Example:
420
445
 
421
446
  ```js
447
+ import alfy from 'alfy';
448
+
422
449
  alfy.cache.set('unicorn', '🦄');
423
450
 
424
451
  alfy.cache.get('unicorn');
@@ -433,7 +460,8 @@ the number of milliseconds the value is valid in the cache.
433
460
  Example:
434
461
 
435
462
  ```js
436
- const delay = require('delay');
463
+ import alfy from 'alfy';
464
+ import delay from 'delay';
437
465
 
438
466
  alfy.cache.set('foo', 'bar', {maxAge: 5000});
439
467
 
@@ -465,6 +493,8 @@ The most useful ones are included as keys. The rest you can get with `icon.get()
465
493
  Example:
466
494
 
467
495
  ```js
496
+ import alfy from 'alfy';
497
+
468
498
  console.log(alfy.icon.error);
469
499
  //=> '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns'
470
500
 
@@ -578,20 +608,16 @@ Non-synced local preferences are stored within `Alfred.alfredpreferences` under
578
608
  - [alfred-asana](https://github.com/adriantoine/alfred-asana) - Search your Asana tasks
579
609
  - [alfred-cacher](https://github.com/CacherApp/alfred-cacher) - Find a code snippet from [Cacher](https://www.cacher.io) and copy it to the clipboard
580
610
  - [alfred-loremipsum](https://github.com/AntonNiklasson/alfred-loremipsum) - Generate placeholder text
581
- - [alfred-kaomoji](https://github.com/vinkla/alfred-kaomoji) - Find relevant kaomoji from text
582
611
  - [alfred-packagist](https://github.com/vinkla/alfred-packagist) - Search for PHP packages with Packagist
583
612
  - [alfred-vpn](https://github.com/stve/alfred-vpn) - Connect/disconnect from VPNs
584
- - [alfred-clap](https://github.com/jacc/alfred-clap) - 👏🏻 Clap 👏🏻 stuff 👏🏻 out 👏🏻 in 👏🏻 Alfred! 👏🏻
585
613
  - [alfred-yandex-translate](https://github.com/mkalygin/alfred-yandex-translate) - Translate words and text with Yandex Translate
586
614
  - [alfred-now](https://github.com/lucaperret/alfred-now) - Use [Now](https://zeit.co/now) commands within Alfred to access deployments and aliases
587
615
  - [alfred-chuck-norris-jokes](https://github.com/jeppestaerk/alfred-chuck-norris-jokes) - Get Chuck Norris jokes
588
616
  - [alfred-show-network-info](https://github.com/jeppestaerk/alfred-show-network-info) - See network info and discover local devices
589
617
  - [alfred-currency-conversion](https://github.com/jeppestaerk/alfred-currency-conversion) - See foreign exchange rates and currency conversion
590
- - [alfred-reference](https://github.com/vinkla/alfred-reference) - Search for HTML elements and CSS properties
591
618
  - [alfred-polyglot](https://github.com/nikersify/alfred-polyglot) - Translate text with Google Translate
592
619
  - [alfred-stock-price](https://github.com/Wei-Xia/alfred-stock-price-workflow) - Show real time stock price in US market
593
620
  - [alfred-jira](https://github.com/colinf/alfred-jira) - Convert clipboard text between Markdown and Jira markup
594
- - [alfred-homebrew](https://github.com/vinkla/alfred-homebrew) - Search for macOS packages with Homebrew
595
621
  - [alfred-network-location-switch](https://github.com/abdul/alfred-network-location-switch) - Switch macOS network location
596
622
  - [alfred-cool](https://github.com/nguyenvanduocit/alfred-cool) - Find cool words
597
623
  - [alfred-google-books](https://github.com/Dameck/alfred-google-books) - Search for Google Books
@@ -601,7 +627,6 @@ Non-synced local preferences are stored within `Alfred.alfredpreferences` under
601
627
  - [alfred-title](https://github.com/Kikobeats/alfred-title) – Capitalize your titles
602
628
  - [alfred-trello](https://github.com/mblode/alfred-trello) - Search your boards, quickly add cards, and view list of cards for Trello
603
629
  - [alfred-npm-versions](https://github.com/mrmartineau/alfred-npm-versions) - Lookup the latest 15 versions for an npm package
604
- - [alfred-travis-ci](https://github.com/adriantombu/alfred-travis-ci) - Check the status of your Travis CI builds
605
630
  - [alfred-github-trending](https://github.com/mikqi/alfred-github-trending) - Search trending repositories on GitHub
606
631
  - [alfred-elm](https://github.com/nicklayb/alfred-elm) - Browse Elm packages documentation
607
632
  - [alfred-imagemin](https://github.com/kawamataryo/alfred-imagemin) - Minify images with Imagemin
@@ -612,6 +637,8 @@ Non-synced local preferences are stored within `Alfred.alfredpreferences` under
612
637
  - [alfred-chrome-workflow](https://github.com/jopemachine/alfred-chrome-workflow) - Search Chrome's bookmarks, history and download logs
613
638
  - [alfred-code](https://github.com/shaodahong/alfred-code) - Quickly open a file in Visual Studio Code
614
639
  - [alfred-amphetamine](https://github.com/demartini/alfred-amphetamine) - Start and end sessions quickly in the Amphetamine app
640
+ - [alfred-ids](https://github.com/rizowski/alfred-ids) - Generate various types of IDs.
641
+ - [alfred-awesome-stars](https://github.com/jopemachine/alfred-awesome-stars) - Search starred GitHub repos through awesome-stars.
615
642
 
616
643
  ## Related
617
644
 
package/run-node.sh CHANGED
@@ -43,7 +43,7 @@ if ! has_node; then
43
43
  fi
44
44
 
45
45
  if has_node; then
46
- ESM_OPTIONS='{"await":true}' node --require esm "$@"
46
+ node "$@"
47
47
  else
48
48
  echo $'{"items":[{"title": "Couldn\'t find the `node` binary", "subtitle": "Symlink it to `/usr/local/bin`"}]}'
49
49
  fi