├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── check.js ├── index.js ├── lib └── notify.js ├── license ├── package.json ├── readme.md └── screenshot.png /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /check.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const readPkg = require('read-pkg'); 4 | const latestVersion = require('latest-version'); 5 | const semver = require('semver'); 6 | const execa = require('execa'); 7 | const CacheConf = require('cache-conf'); 8 | const notify = require('./lib/notify'); 9 | const pkg = require('./package.json'); 10 | 11 | const ONE_DAY = 86400000; 12 | 13 | const workflowPath = process.cwd(); 14 | const conf = new CacheConf({projectName: pkg.name}); 15 | 16 | const checkNpm = pkg => latestVersion(pkg.name).then(version => ({ 17 | latest: version, 18 | current: pkg.version, 19 | name: pkg.name 20 | })); 21 | 22 | readPkg(workflowPath) 23 | .then(pkg => { 24 | if (conf.has(pkg.name)) { 25 | // Skip checking if a valid entry exists 26 | return; 27 | } 28 | 29 | return checkNpm(pkg).then(res => { 30 | // Store the latest version in the cache for one day 31 | conf.set(res.name, res.latest, {maxAge: ONE_DAY}); 32 | 33 | if (!semver.eq(res.latest, res.current)) { 34 | // Overwrite `info.plist` and reload the workflows 35 | return notify(workflowPath, `Update available: ${res.current} → ${res.latest}. Run \`npm install -g ${res.name}\``) 36 | .then(() => execa('open', ['-n', '-a', 'Alfred 3'])); 37 | } 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const cp = require('child_process'); 4 | 5 | module.exports = () => { 6 | const subProcess = cp.spawn(path.join(__dirname, 'check.js'), [], { 7 | detached: true, 8 | stdio: 'ignore' 9 | }); 10 | subProcess.unref(); 11 | }; 12 | -------------------------------------------------------------------------------- /lib/notify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const fs = require('fs'); 4 | const plist = require('plist'); 5 | const pify = require('pify'); 6 | 7 | const fsP = pify(fs); 8 | 9 | // Fixes some inconsistencies when running `plist.parse` 10 | // https://github.com/TooTallNate/plist.js/issues/75 11 | const fix = obj => { 12 | for (const key of Object.keys(obj)) { 13 | const val = obj[key]; 14 | 15 | if (val === null || val === undefined) { 16 | obj[key] = ''; 17 | } else if (Array.isArray(val)) { 18 | obj[key] = val.map(fix); 19 | } else if (typeof val === 'object') { 20 | obj[key] = fix(val); 21 | } 22 | } 23 | 24 | return obj; 25 | }; 26 | 27 | module.exports = (dir, message) => { 28 | const file = path.join(dir, 'info.plist'); 29 | 30 | return fsP.readFile(file, 'utf8') 31 | .then(content => { 32 | const data = fix(plist.parse(content)); 33 | 34 | for (const obj of data.objects) { 35 | if (obj.config.subtext !== undefined) { 36 | obj.config.subtext = message; 37 | } 38 | } 39 | 40 | return fsP.writeFile(file, plist.build(data)); 41 | }); 42 | }; 43 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sam Verschueren (github.com/SamVerschueren) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alfred-notifier", 3 | "version": "0.2.3", 4 | "description": "Update notifications for your Alfred workflow", 5 | "license": "MIT", 6 | "repository": "SamVerschueren/alfred-notifier", 7 | "author": { 8 | "name": "Sam Verschueren", 9 | "email": "sam.verschueren@gmail.com", 10 | "url": "github.com/SamVerschueren" 11 | }, 12 | "maintainers": [ 13 | { 14 | "name": "Sindre Sorhus", 15 | "email": "sindresorhus@gmail.com", 16 | "url": "sindresorhus.com" 17 | } 18 | ], 19 | "engines": { 20 | "node": ">=4" 21 | }, 22 | "scripts": { 23 | "test": "xo" 24 | }, 25 | "files": [ 26 | "index.js", 27 | "check.js", 28 | "lib" 29 | ], 30 | "keywords": [ 31 | "alfred", 32 | "alfy", 33 | "workflow", 34 | "update", 35 | "updater", 36 | "notify", 37 | "notifier", 38 | "module", 39 | "version" 40 | ], 41 | "dependencies": { 42 | "cache-conf": "^0.5.0", 43 | "execa": "^0.8.0", 44 | "latest-version": "^3.1.0", 45 | "pify": "^3.0.0", 46 | "plist": "^2.0.1", 47 | "read-pkg": "^2.0.0", 48 | "semver": "^5.3.0" 49 | }, 50 | "devDependencies": { 51 | "xo": "*" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # alfred-notifier [![Build Status](https://travis-ci.org/SamVerschueren/alfred-notifier.svg?branch=master)](https://travis-ci.org/SamVerschueren/alfred-notifier) 2 | 3 | > Update notifications for your [Alfred](https://www.alfredapp.com/) workflow 4 | 5 | 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install --save alfred-notifier 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ### Simple example 18 | 19 | ```js 20 | const alfredNotifier = require('alfred-notifier'); 21 | 22 | alfredNotifier(); 23 | ``` 24 | 25 | ### Comprehensive example 26 | 27 | ```js 28 | const alfy = require('alfy'); 29 | const alfredNotifier = require('alfred-notifier'); 30 | 31 | // Checks for available update and updates the `info.plist` 32 | alfredNotifier(); 33 | 34 | alfy.output([ 35 | {title: '🦄'}, 36 | {title: '🌈'} 37 | ]); 38 | ``` 39 | 40 | 41 | ## API 42 | 43 | ### alfredNotifier() 44 | 45 | Checks if there is an available update. If an update is available, it will add a message as subtext of your workflow. 46 | 47 | 48 | ## License 49 | 50 | MIT © [Sam Verschueren](https://github.com/SamVerschueren) 51 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamVerschueren/alfred-notifier/1655892dbf56402bf13ad777cb8f59434cad668a/screenshot.png --------------------------------------------------------------------------------