Skip to content

Commit

Permalink
Beautiful notification when running
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Feb 4, 2017
1 parent 7724742 commit 75a8d6a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/listening.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const {copy} = require('copy-paste')
const ip = require('ip')
const pathType = require('path-type')
const {red, grey} = require('chalk')
const chalk = require('chalk')

const copyToClipboard = async text => {
try {
Expand All @@ -24,18 +24,26 @@ module.exports = async (server, current) => {
})

if (!await pathType.dir(current)) {
console.error(red('Specified directory doesn\'t exist!'))
console.error(chalk.red('Specified directory doesn\'t exist!'))
process.exit(1)
}

if (!process.env.NOW) {
let message = `Running on ${url}`
let message = chalk.green('Serving!')
message += '\n\n'

const localURL = `http://localhost:${details.port}`

message += `• ${chalk.bold('Locally: ')} ${localURL}\n`
message += `• ${chalk.bold('On the Network: ')} ${url}\n\n`

const copied = await copyToClipboard(url)

if (copied) {
message = `${message} ${grey('[copied to clipboard]')}`
message += `${chalk.grey('Copied local address to clipboard!')}\n\n`
}

console.log(message)
process.stdout.write('\x1Bc')
process.stdout.write(message)
}
}

0 comments on commit 75a8d6a

Please sign in to comment.