UNPKG

967 BJavaScriptView Raw
1'use strict';
2const path = require('path');
3const fs = require('fs');
4const userHome = require('user-home');
5const pathExists = require('path-exists');
6const pkgUp = require('pkg-up');
7const pify = require('pify');
8const del = require('del');
9const plistTransform = require('./lib/plist-transform');
10
11const fsP = pify(fs);
12const workflowDir = path.join(userHome, 'Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows');
13
14module.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};