Skip to content

Commit

Permalink
Add support for user configurable workflows - fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Sep 16, 2019
1 parent c39ea0f commit 3c327a3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const loudRejection = require('loud-rejection');
const cleanStack = require('clean-stack');
const dotProp = require('dot-prop');
const CacheConf = require('cache-conf');
const AlfredConfig = require('alfred-config');
const updateNotification = require('./lib/update-notification');

const alfy = module.exports;
Expand Down Expand Up @@ -99,6 +100,10 @@ alfy.config = new Conf({
cwd: alfy.alfred.data
});

alfy.userConfig = new AlfredConfig({
cwd: alfy.alfred.data
});

alfy.cache = new CacheConf({
configName: 'cache',
cwd: alfy.alfred.cache,
Expand Down
5 changes: 5 additions & 0 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const execa = require('execa');
preferLocal: true,
localDir: __dirname
});

await execa('alfred-config', {
preferLocal: true,
localDir: __dirname
});
} catch (error) {
console.error(error);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"mac"
],
"dependencies": {
"alfred-config": "^0.2.1",
"alfred-link": "^0.3.1",
"alfred-notifier": "^0.2.0",
"cache-conf": "^0.6.0",
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ alfy.config.get('unicorn');
//=> 'πŸ¦„'
```

#### userConfig

Type: `object`

If the workflow supports user configuration, it will export a readable [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) with the user workflow configuration.

Example:

```js
alfy.userConfig.get('apiKey');
//=> '16811cad1b8547478b3e53eae2e0f083'
```

#### cache

Type: `object`
Expand Down
1 change: 1 addition & 0 deletions test/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const tempfile = require('tempfile');
exports.alfy = (options = {}) => {
delete require.cache[path.resolve(__dirname, '../index.js')];

process.env.alfred_workflow_data = options.data || tempfile();
process.env.alfred_workflow_cache = options.cache || tempfile();
process.env.alfred_workflow_version = options.version || '1.0.0';
return require('..');
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/config/user-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// πŸ¦„ Unicorns πŸ¦„
"unicorn": "πŸ¦„",

// 🌈 Rainbows 🌈
"rainbow": "🌈"
}
14 changes: 14 additions & 0 deletions test/user-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from 'path';
import test from 'ava';
import {alfy as createAlfy} from './_utils';

test('read user config', t => {
const alfy = createAlfy({
data: path.join(__dirname, 'fixtures/config')
});

t.is(alfy.userConfig.size, 2);
t.is(alfy.userConfig.get('unicorn'), 'πŸ¦„');
t.is(alfy.userConfig.get('rainbow'), '🌈');
t.is(alfy.userConfig.has('foo'), false);
});

0 comments on commit 3c327a3

Please sign in to comment.