1 | 'use strict';
|
2 | const path = require('path');
|
3 | const fs = require('fs');
|
4 | const userHome = require('user-home');
|
5 | const pathExists = require('path-exists');
|
6 | const pkgUp = require('pkg-up');
|
7 | const pify = require('pify');
|
8 | const del = require('del');
|
9 | const plistTransform = require('./lib/plist-transform');
|
10 |
|
11 | const fsP = pify(fs);
|
12 | const workflowDir = path.join(userHome, 'Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows');
|
13 |
|
14 | module.exports = () => {
|
15 | const cwd = process.cwd();
|
16 |
|
17 | return pathExists(workflowDir)
|
18 | .then(exists => {
|
19 | if (!exists) {
|
20 | throw new Error(`Workflow directory \`${workflowDir}\` does not exist`);
|
21 | }
|
22 |
|
23 | return pkgUp(cwd);
|
24 | })
|
25 | .then(filePath => {
|
26 | const pkg = require(filePath);
|
27 |
|
28 | const src = path.dirname(filePath);
|
29 | const dest = path.join(workflowDir, pkg.name);
|
30 |
|
31 | return plistTransform(path.dirname(filePath), pkg)
|
32 | .then(() => del(dest, {force: true}))
|
33 | .then(() => fsP.symlink(src, dest));
|
34 | });
|
35 | };
|