Skip to content

Commit

Permalink
Release v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeboer committed Mar 21, 2020
2 parents fb97581 + 9c037ef commit 2f89f1d
Show file tree
Hide file tree
Showing 40 changed files with 1,629 additions and 1,055 deletions.
28 changes: 21 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
version: 2

shared: &shared
steps:
- checkout
- run: yarn
- run: yarn test:ci

jobs:
test:
test-node-10:
docker:
- image: node:8
steps:
- checkout
- image: node:10
<<: *shared

- run: yarn
- run: yarn test:ci
test-node-12:
docker:
- image: node:12
<<: *shared

test-node-13:
docker:
- image: node:13
<<: *shared

workflows:
version: 2
test:
jobs:
- test
- test-node-10
- test-node-12
- test-node-13
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
/build
/coverage
/dist
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Hugo is a [script filter](https://www.alfredapp.com/help/workflows/inputs/script
* Built-in cache and configuration storage
* Advanced filtering of items using [Fuse.js](http://fusejs.io) :mag:
* Fetch (JSON) from REST API's using [Axios](https://github.com/axios/axios) :earth_americas:
* Update notifications (for both NPM and Packal workflows) :mailbox:
* Update notifications :mailbox:

## Getting started

### Prerequisites

* NodeJS 8 or higher
* NodeJS 10 or higher
* Alfred 4 with [paid powerpack addon](https://www.alfredapp.com/powerpack/buy/)

### Installing
Expand Down
76 changes: 64 additions & 12 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,84 @@

Actions are an easy way to structure your workflow in-code without having to drag all kinds of nodes in to launch different script for each action. Now you can run one script and have it handle all your actions.

Best way to understand is to look at the examples below!
You can use them to do anything like run programs, manipulate files, whatever. You can also use them in [script filter inputs](https://www.alfredapp.com/help/workflows/inputs/script-filter/) for example to list the latest tweets for a hashtag you enter. Also see [./items.md] for more info and examples.

### Examples

##### Simple action

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Hello action
hugo.action("hello", (query) => {
hugo.action('hello', (query) => {
console.log(`Hello ${query}!`);
});

// Run matching actions
hugo.run();
```

```sh
node index.js hello world
# Hello world!
```

##### Simple action with aliases

```js
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Hello action
hugo.action(['hi', 'hello'], (query) => {
console.log(`Hello ${query}!`);
});

// Run matching actions
hugo.run();
```

```sh
node index.js hello world
# Hello world!

node index.js hi world
# Hello world!
```

##### Action with nested sub-actions

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// List action
const listAction = hugo.action("list", (query) => {
console.log("Usage: list <bikes|cars> <brand>");
const listAction = hugo.action('list', (query) => {
console.log('Usage: list <bikes|cars> <brand>');
});

// List bikes sub-action
listAction.action("bikes", (query) => {
const brand = query[0] || "";
listAction.action('bikes', (query) => {
const brand = query[0] || '';

console.log(`Here be a list of ${brand} bikes.`);
});

// List cars sub-action
const listCarsAction = listAction.action("cars", (query) => {
const brand = query[0] || "";
const listCarsAction = listAction.action('cars', (query) => {
const brand = query[0] || '';

console.log(`Here be a list of ${brand} cars.`);
});

// Sub-action of the list cars sub-action.
listCarsAction.action("Porsche", (query) => {
console.log("Porsche, ahh very fancy cars!");
listCarsAction.action('Porsche', (query) => {
console.log('Porsche, ahh very fancy cars!');
});

// Run matching actions
Expand All @@ -75,3 +100,30 @@ node index.js list cars Porsche
# Porsche, ahh very fancy cars!
```

##### Simple script filter action

```js
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// List action
const listAction = hugo.action('list', (query) => {
// Add items
hugo.items.push({
title: 'Foo',
subtitle: 'Bar',
arg: 'foobar'
}, {
title: 'Hello',
subtitle: 'World',
arg: 'helloworld'
});

// Flush output buffer
hugo.feedback();
});

// Run matching actions
hugo.run();
```
18 changes: 9 additions & 9 deletions docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ For more details about [Cache](https://www.npmjs.com/package/@cloudstek/cache),
### Example

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Store "foo" with value "bar" for 1 hour
hugo.cache.set("foo", "bar");
// Store 'foo' with value 'bar' for 1 hour
hugo.cache.set('foo', 'bar');

// Store "pie" with value "apple" for 5 seconds
hugo.cache.set("pie", "apple", 5);
// Store 'pie' with value 'apple' for 5 seconds
hugo.cache.set('pie', 'apple', 5);

hugo.cache.has("pie"); // true
hugo.cache.get("pie"); // apple
hugo.cache.has('pie'); // true
hugo.cache.get('pie'); // apple

// Wait 5 seconds. ZzzZzZzZZz
// sleep(5000);

hugo.cache.has("pie"); // false
hugo.cache.get("pie"); // undefined
hugo.cache.has('pie'); // false
hugo.cache.get('pie'); // undefined
```

10 changes: 5 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ You *can* let a configuration item expire but that is entirely optional and I'm
### Example

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// No need to load anything, just use it!

// Store "foo" with value "bar"
hugo.config.set("foo", "bar");
// Store 'foo' with value 'bar'
hugo.config.set('foo', 'bar');

// Get "foo"
console.log(hugo.config.get("foo")); // bar
// Get 'foo'
console.log(hugo.config.get('foo')); // bar
```

8 changes: 4 additions & 4 deletions docs/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ Behind the scenes [Axios](https://github.com/axios/axios) is used to make the re
### Example

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Fetch single todo item without caching
hugo
.fetch("https://jsonplaceholder.typicode.com/todos/1")
.fetch('https://jsonplaceholder.typicode.com/todos/1')
.then((data) => {
console.log(`#${data.id} ${data.title}`);
});

// Fetch todo list and cache it for 1 hour
hugo
.fetch("https://jsonplaceholder.typicode.com/todos", {/* Axios options */}, 3600)
.fetch('https://jsonplaceholder.typicode.com/todos', {/* Axios options */}, 3600)
.then((data) => {
console.log(`${data.length} todo items fetched.`);
});

// Fetch the todo list again, this time it's cached!
hugo
.fetch("https://jsonplaceholder.typicode.com/todos", {/* Axios options */}, 3600)
.fetch('https://jsonplaceholder.typicode.com/todos', {/* Axios options */}, 3600)
.then((data) => {
console.log(`${data.length} todo items loaded from cache.`);
});
Expand Down
10 changes: 5 additions & 5 deletions docs/file-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ By default the TTL (cache lifetime) is set to `false`, which means the results a
### Example

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Create the file cache
const fc = hugo.cacheFile('/path/to/file.to.process');

// Define the change handler for processing your file
fc.on("change", (cache, fileContents) => {
fc.on('change', (cache, fileContents) => {
// Process the file contents
const foo = processFoo(fileContents);
const bar = processBar(fileContents);

// Set the results
cache.set("foo", foo);
cache.set("bar", bar);
cache.set('foo', foo);
cache.set('bar', bar);
});

// Get the results
Expand All @@ -37,7 +37,7 @@ console.log(results.bar); // Will output processed bar data
#### With a 1-hour TTL

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

Expand Down
43 changes: 22 additions & 21 deletions docs/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,53 @@ To learn more about items, variables and the rerun parameter, please see the Alf
#### Items

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Add single item
hugo.items.push({
title: "Foo",
subtitle: "Bar",
arg: "foobar"
title: 'Foo',
subtitle: 'Bar',
arg: 'foobar'
});

// Add multiple items
const items = [
{
title: "Foo",
subtitle: "Bar",
arg: "foobar"
},
{
title: "Apple",
subtitle: "Pie",
arg: "omnomnom"
}
{
title: 'Foo',
subtitle: 'Bar',
arg: 'foobar'
},
{
title: 'Apple',
subtitle: 'Pie',
arg: 'omnomnom'
}
];

hugo.items = hugo.items.concat(items);

// Flush output buffer
hugo.feedback();
```

#### Variables

Besides item variables you can also set global/session variables (please see the [documentation](https://www.alfredapp.com/help/workflows/inputs/script-filter/json/#variables)). Much like items, the variables are directly exposed as an object.

```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Set a variable
hugo.variables.foo = "bar";
hugo.variables.foo = 'bar';

// Set (override) multiple
hugo.variables = {
foo: "bar",
apple: "pie"
foo: 'bar',
apple: 'pie'
};
```

Expand All @@ -61,13 +64,11 @@ hugo.variables = {
> Scripts can be set to re-run automatically after an interval using the 'rerun' key with a value of 0.1 to 5.0 seconds. 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.
```js
import { Hugo } from "alfred-hugo";
import { Hugo } from 'alfred-hugo';

const hugo = new Hugo();

// Will re-run the script each 650ms after output
hugo.rerun = 0.65;

hugo.
```

Loading

0 comments on commit 2f89f1d

Please sign in to comment.