-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cli update #227
Merged
Merged
Cli update #227
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a9c198f
Updating to new actions for CLI
9663a8c
Extending cli and adding some tests
11f40ef
Adding content to readme
3a08c81
Fixing eslint errors
bdbaad4
Disable CLI tests on old node
d42619f
Wrap test for 0.10
6b28d5e
Tested on 0.10
afafe59
Fixing for node 4
bd5f6dc
Fixing review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
coverage/ | ||
node_modules/ | ||
wires | ||
test/output/ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,24 @@ registration.pushManager.subscribe({ | |
}); | ||
``` | ||
|
||
## Command Line | ||
|
||
You can install `web-push` globally and use it for send notifications and / or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: sending |
||
generating VAPID keys. | ||
|
||
Install like so: | ||
|
||
npm install web-push -g | ||
|
||
Then you can run the following commands: | ||
|
||
Usage: | ||
|
||
web-push send-notification --endpoint=<url> [--key=<browser key>] [--auth=<auth secret>] [--payload=<message>] [--ttl=<seconds>] [--vapid-subject=<vapid subject>] [--vapid-pubkey=<public key url base64>] [--vapid-pvtkey=<private key url base64>] [--gcm-api-key=<api key>] | ||
|
||
web-push generate-vapid-keys [--json] | ||
|
||
|
||
# API Reference | ||
|
||
## sendNotification(pushSubscription, payload, options) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#! /usr/bin/env node | ||
/* eslint consistent-return:0*/ | ||
'use strict'; | ||
|
||
const webPush = require('../src/index.js'); | ||
|
||
const printUsageDetails = () => { | ||
const actions = [ | ||
{ | ||
name: 'send-notification', | ||
options: [ | ||
'--endpoint=<url>', | ||
'[--key=<browser key>]', | ||
'[--auth=<auth secret>]', | ||
'[--payload=<message>]', | ||
'[--ttl=<seconds>]', | ||
'[--vapid-subject=<vapid subject>]', | ||
'[--vapid-pubkey=<public key url base64>]', | ||
'[--vapid-pvtkey=<private key url base64>]', | ||
'[--gcm-api-key=<api key>]' | ||
] | ||
}, { | ||
name: 'generate-vapid-keys', | ||
options: [ | ||
'[--json]' | ||
] | ||
} | ||
]; | ||
|
||
let usage = '\nUsage: \n\n'; | ||
actions.forEach(action => { | ||
usage += ' web-push ' + action.name; | ||
usage += ' ' + action.options.join(' '); | ||
usage += '\n\n'; | ||
}); | ||
|
||
console.log(usage); | ||
process.exit(1); | ||
}; | ||
|
||
const generateVapidKeys = returnJson => { | ||
const vapidKeys = webPush.generateVAPIDKeys(); | ||
|
||
let outputText; | ||
if (returnJson) { | ||
outputText = JSON.stringify(vapidKeys); | ||
} else { | ||
const outputLine = '\n=======================================\n'; | ||
outputText = outputLine + '\n' + | ||
'Public Key:\n' + vapidKeys.publicKey + '\n\n' + | ||
'Private Key:\n' + vapidKeys.privateKey + '\n' + | ||
outputLine; | ||
} | ||
|
||
console.log(outputText); | ||
process.exit(0); | ||
}; | ||
|
||
const sendNotification = args => { | ||
if (process.env.GCM_API_KEY) { | ||
webPush.setGCMAPIKey(process.env.GCM_API_KEY); | ||
} | ||
|
||
const subscription = { | ||
endpoint: args.endpoint, | ||
keys: { | ||
p256dh: args.key || null, | ||
auth: args.auth || null | ||
} | ||
}; | ||
|
||
const payload = args.payload || null; | ||
|
||
const options = {}; | ||
|
||
if (args.ttl) { | ||
options.TTL = args.ttl; | ||
} | ||
|
||
if (argv['vapid-subject'] || argv['vapid-pubkey'] || argv['vapid-pvtkey']) { | ||
options.vapidDetails = { | ||
subject: args['vapid-subject'] || null, | ||
publicKey: args['vapid-pubkey'] || null, | ||
privateKey: args['vapid-pvtkey'] || null | ||
}; | ||
} | ||
|
||
if (args['gcm-api-key']) { | ||
options.gcmAPIKey = args['gcm-api-key']; | ||
} | ||
|
||
webPush.sendNotification(subscription, payload, options) | ||
.then(() => { | ||
console.log('Push message sent.'); | ||
}, err => { | ||
console.log('Error sending push message: '); | ||
console.log(err); | ||
}) | ||
.then(() => { | ||
process.exit(0); | ||
}); | ||
}; | ||
|
||
const action = process.argv[2]; | ||
const argv = require('minimist')(process.argv.slice(3)); | ||
switch (action) { | ||
case 'send-notification': | ||
if (!argv.endpoint) { | ||
return printUsageDetails(); | ||
} | ||
|
||
sendNotification(argv); | ||
break; | ||
case 'generate-vapid-keys': | ||
generateVapidKeys(argv.json || false); | ||
break; | ||
default: | ||
printUsageDetails(); | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wires isn't generated by anything in this project.
We used to download and name a file wires for selenium, then selenium looked for 'geckodriver' which we did but saved somewhere else and now we just use the geckodriver module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. I still have the
wires
executable in my folder 😄