Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
feat(notify): add notify command
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmeinke committed Sep 24, 2018
1 parent 8594038 commit 3ba145f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
6 changes: 3 additions & 3 deletions commands/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module.exports = team => {
.prompt([
{
type: 'list',
name: 'user',
name: 'name',
message: 'Who the heck are you?',
choices: team.map(({ name }) => name)
}
])
.then(({ user }) => {
.then(({ name }) => {
console.log(
`Yay, it's ${chalk.bold.green(user)}! My favourite team member.`
`Yay, it's ${chalk.bold.green(name)}! My favourite team member.`
)
})
} else {
Expand Down
81 changes: 81 additions & 0 deletions commands/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const chalk = require('chalk')
const inquirer = require('inquirer')
const nodemailer = require('nodemailer')

const notifications = [
{
subject: 'Reminder: production changes',
message: `It is important to remember that changes that have even the slightest chance of causing errors, should not be run directly on a production server (at least without testing somewhere else first).
This includes changes such as:
- updating plugins
- changing config
- etc.`,
}
]

module.exports = (team, email) => {
if (team.length) {
inquirer
.prompt([
{
type: 'list',
name: 'name',
message: 'Who would you like to notify?',
choices: team.map(({ name }) => name),
},
{
type: 'list',
name: 'service',
message: 'How would you like to notify them?',
choices: [ 'Email' ],
},
{
type: 'list',
name: 'subject',
message: 'What nofification would you like to send?',
choices: notifications.map(({ subject }) => subject),
}
])
.then(({ name, service, subject }) => {
console.log(chalk.dim(`Sending notification to ${name}...`))

const mailgun = email[0]
const notification = notifications.filter(n => n.subject === subject)[0]
const to = team.filter(m => m.name === name)[0].email

const transporter = nodemailer.createTransport({
host: mailgun.host,
port: mailgun.ports[0],
secure: false,
auth: {
user: mailgun.user,
pass: mailgun.password,
},
})

const options = {
from: '"S8 bot 🤖" <[email protected]>',
to,
subject: notification.subject,
text: `Hi ${name}!
${notification.message}
-
❤️
S8 bot 🤖`,
}

transporter.sendMail(options, (err, info) => {
if (err) {
return console.error(err)
}

console.log(chalk.bold.green(`Notification sent!`))
})
})
} else {
console.log(`${chalk.bold.red('No team members to notify.')}`)
}
}
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const chalk = require('chalk')
const helloCmd = require('./commands/hello')
const helpCmd = require('./commands/help')
const installCmd = require('./commands/install')
const notifyCmd = require('./commands/notify')
const setupCmd = require('./commands/setup')
const teamCmd = require('./commands/team')
const upgradeCmd = require('./commands/upgrade')
Expand All @@ -18,8 +19,10 @@ try {
config = require('@serieseight/config')
hasSetup = true
} catch (err) {
console.log(`${chalk.yellow(`You still need to run ${chalk.bold('s8 setup')} to complete installation.
if (cmd !== setup) {
console.log(`${chalk.yellow(`You still need to run ${chalk.bold('s8 setup')} to complete installation.
Currently ${chalk.bold('s8')} does not have all the data it requires to function.`)}\n`)
}
}

switch(cmd) {
Expand All @@ -42,6 +45,10 @@ switch(cmd) {
installCmd(args)
break

case 'notify':
notifyCmd(config.team, config.email)
break

case 'setup':
setupCmd(hasSetup)
break
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"dependencies": {
"chalk": "^2.4.1",
"inquirer": "^6.2.0"
"inquirer": "^6.2.0",
"nodemailer": "^4.6.8"
},
"description": "A pointless CLI",
"devDependencies": {
Expand Down

0 comments on commit 3ba145f

Please sign in to comment.