Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
feat: added notify()
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 26, 2018
1 parent 2c5b377 commit 0bdc77a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"chalk": "^2.3.0",
"fs-extra": "^5.0.0",
"lodash": "^4.17.4",
"node-notifier": "^5.2.1",
"password-prompt": "^1.0.4",
"semver": "^5.5.0",
"strip-ansi": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import deps from './deps'
import Errors, {CLIError, Options as ErrorOptions} from './errors'
import {ExitError} from './exit'
import * as Logger from './logger'
import notify from './notify'
import Output from './output'
import {IPromptOptions} from './prompt'
import * as Table from './styled/table'
Expand All @@ -31,6 +32,7 @@ export const scope = (_scope?: string) => {
fatal: errors('fatal', _scope),

exit(code = 1, error?: Error) { throw new ExitError(code, error) },
notify,

get prompt() { return deps.prompt.prompt },
get confirm() { return deps.prompt.confirm },
Expand Down
21 changes: 21 additions & 0 deletions src/notify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Notifier = require('node-notifier')

export default (opts: Notifier.Notification, cb?: Notifier.NotificationCallback) => {
const notifier: typeof Notifier = require('node-notifier')
return notifier.notify({
// title: `heroku ${process.argv[2]}`,
// icon: path.join('Terminal Icon'),
// icon: path.join(__dirname, '../assets/heroku.png'),
// contentImage: path.join(__dirname, '../assets/heroku.png'),
// open: // URL to open on Click
// wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds

// New in latest version. See `example/macInput.js` for usage
// timeout: 5, // Takes precedence over wait if both are defined.
// closeLabel: void 0, // String. Label for cancel button
// actions: void 0, // String | Array<String>. Action label or list of labels in case of dropdown
// dropdownLabel: void 0, // String. Label to be used if multiple actions
// reply: false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
...opts
}, cb)
}
28 changes: 28 additions & 0 deletions test/fancy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import chalk from 'chalk'
import {expect, fancy as base, FancyTypes, NockScope} from 'fancy-test'
import * as fs from 'fs-extra'
import * as path from 'path'

import cli from '../src'

export {
expect,
FancyTypes,
NockScope,
}

let count = 0
const logLevel = cli.config.logLevel

export const fancy = base
.do(async (ctx: {count: number, base: string}) => {
ctx.count = count++
ctx.base = path.join(__dirname, '../tmp', `test-${ctx.count}`)
await fs.remove(ctx.base)
cli.config.errlog = path.join(ctx.base, 'error.log')
chalk.enabled = false
})
.finally(async () => {
cli.config.logLevel = logLevel
await cli.done()
})
11 changes: 11 additions & 0 deletions test/notify.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import cli from '../src'

import {fancy} from './fancy'

describe('notify', () => {
fancy
.stderr()
.it('shows notification', (_, done) => {
cli.notify({message: 'example notification'}, done)
})
})

0 comments on commit 0bdc77a

Please sign in to comment.