Skip to content

Commit

Permalink
Add support for user-configurable workflows (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
SamVerschueren and sindresorhus authored Jun 5, 2021
1 parent cff9883 commit c73c325
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
3 changes: 3 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,8 @@ alfy.config = new Conf({
cwd: alfy.alfred.data
});

alfy.userConfig = new AlfredConfig();

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.2",
"alfred-link": "^0.3.1",
"alfred-notifier": "^0.2.0",
"cache-conf": "^0.6.0",
Expand Down
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ alfy.config.get('unicorn');
//=> 'πŸ¦„'
```

#### userConfig

Type: `Map`

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 configuration information for the workflow. For instance, if you are developing a GitHub workflow, you could let your users provide their own API tokens.

See [`alfred-config`](https://github.com/SamVerschueren/alfred-config#workflow-configuration) for more details.

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.false(alfy.userConfig.has('foo'));
});

0 comments on commit c73c325

Please sign in to comment.