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

Commit 0bdc77a

Browse files
committed
feat: added notify()
1 parent 2c5b377 commit 0bdc77a

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"chalk": "^2.3.0",
1313
"fs-extra": "^5.0.0",
1414
"lodash": "^4.17.4",
15+
"node-notifier": "^5.2.1",
1516
"password-prompt": "^1.0.4",
1617
"semver": "^5.5.0",
1718
"strip-ansi": "^4.0.0",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import deps from './deps'
55
import Errors, {CLIError, Options as ErrorOptions} from './errors'
66
import {ExitError} from './exit'
77
import * as Logger from './logger'
8+
import notify from './notify'
89
import Output from './output'
910
import {IPromptOptions} from './prompt'
1011
import * as Table from './styled/table'
@@ -31,6 +32,7 @@ export const scope = (_scope?: string) => {
3132
fatal: errors('fatal', _scope),
3233

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

3537
get prompt() { return deps.prompt.prompt },
3638
get confirm() { return deps.prompt.confirm },

src/notify.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Notifier = require('node-notifier')
2+
3+
export default (opts: Notifier.Notification, cb?: Notifier.NotificationCallback) => {
4+
const notifier: typeof Notifier = require('node-notifier')
5+
return notifier.notify({
6+
// title: `heroku ${process.argv[2]}`,
7+
// icon: path.join('Terminal Icon'),
8+
// icon: path.join(__dirname, '../assets/heroku.png'),
9+
// contentImage: path.join(__dirname, '../assets/heroku.png'),
10+
// open: // URL to open on Click
11+
// wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds
12+
13+
// New in latest version. See `example/macInput.js` for usage
14+
// timeout: 5, // Takes precedence over wait if both are defined.
15+
// closeLabel: void 0, // String. Label for cancel button
16+
// actions: void 0, // String | Array<String>. Action label or list of labels in case of dropdown
17+
// dropdownLabel: void 0, // String. Label to be used if multiple actions
18+
// reply: false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
19+
...opts
20+
}, cb)
21+
}

test/fancy.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import chalk from 'chalk'
2+
import {expect, fancy as base, FancyTypes, NockScope} from 'fancy-test'
3+
import * as fs from 'fs-extra'
4+
import * as path from 'path'
5+
6+
import cli from '../src'
7+
8+
export {
9+
expect,
10+
FancyTypes,
11+
NockScope,
12+
}
13+
14+
let count = 0
15+
const logLevel = cli.config.logLevel
16+
17+
export const fancy = base
18+
.do(async (ctx: {count: number, base: string}) => {
19+
ctx.count = count++
20+
ctx.base = path.join(__dirname, '../tmp', `test-${ctx.count}`)
21+
await fs.remove(ctx.base)
22+
cli.config.errlog = path.join(ctx.base, 'error.log')
23+
chalk.enabled = false
24+
})
25+
.finally(async () => {
26+
cli.config.logLevel = logLevel
27+
await cli.done()
28+
})

test/notify.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import cli from '../src'
2+
3+
import {fancy} from './fancy'
4+
5+
describe('notify', () => {
6+
fancy
7+
.stderr()
8+
.it('shows notification', (_, done) => {
9+
cli.notify({message: 'example notification'}, done)
10+
})
11+
})

0 commit comments

Comments
 (0)