Skip to content

Commit

Permalink
🔪 Split the outdatedBox function in two
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Jul 13, 2017
1 parent f48fcac commit 5777af2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions packages/accurapp-scripts/bin/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (parseFloat(process.versions.node) < 6.5) throw new Error('Sorry, Node 6.5+ i
// warn if any accurapp package is outdated
const latestVersion = require('latest-version')
const semver = require('semver')
const { outdatedDepsBox } = require('../scripts/_utils')
const { createOutdatedMessage, yellowBox } = require('../scripts/_utils')

const currentDeps = [
require('../package.json'),
Expand All @@ -18,7 +18,8 @@ Promise.all(currentDeps.map((dep) => latestVersion(dep.name)))
const outdatedDeps = currentDeps.filter((dep, i) => semver.lt(dep.version, updatedDeps[i].version))

if (outdatedDeps.length > 0) {
console.log(outdatedDepsBox(outdatedDeps, updatedDeps))
const message = createOutdatedMessage(outdatedDeps, updatedDeps)
console.log(yellowBox(message))
}
})

Expand Down
24 changes: 14 additions & 10 deletions packages/accurapp-scripts/scripts/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ function coloredBanner(text, colors = ['blue', 'red']) {
return `\n${colored}`
}

function outdatedDepsBox(outdatedDeps, updatedDeps) {
function yellowBox(message) {
const boxenOptions = {
padding: 1,
align: 'center',
borderColor: 'yellow',
}

return boxen(message, boxenOptions)
}

function createOutdatedMessage(outdatedDeps, updatedDeps) {
const outdatedMessages = outdatedDeps.map((dep, i) =>
`${chalk.blue(dep.name)} ${chalk.gray(dep.version)}${chalk.green(updatedDeps[i].version)}`
)

const message = `
return `
${chalk.yellow('Hey, an update for accurapp is available!')}
${outdatedMessages.join('\n')}
${chalk.yellow('Run')} ${chalk.cyan('yarn upgrade-interactive')} ${chalk.yellow('to update')}
`
const boxenOptions = {
padding: 1,
align: 'center',
borderColor: 'yellow',
}

return boxen(message, boxenOptions)
}

function indent(text, prepend = ' ', firstLinePrepend = prepend) {
Expand Down Expand Up @@ -108,7 +111,8 @@ module.exports = {
log,
noop,
coloredBanner,
outdatedDepsBox,
yellowBox,
createOutdatedMessage,
indent,
listLine,
readWebpackConfig,
Expand Down

0 comments on commit 5777af2

Please sign in to comment.