Skip to content

Commit

Permalink
Merge pull request #27 from accurat/outdated-warning
Browse files Browse the repository at this point in the history
Warn if any of the accurapp packages is outdated
  • Loading branch information
caesarsol authored Aug 8, 2017
2 parents 397477b + 5777af2 commit 866b407
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/accurapp-scripts/bin/scripts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
#!/usr/bin/env node
if (parseFloat(process.versions.node) < 6.5) throw new Error('Sorry, Node 6.5+ is required! Tip: use `nvm` for painless upgrades.')

// warn if any accurapp package is outdated
const latestVersion = require('latest-version')
const semver = require('semver')
const { createOutdatedMessage, yellowBox } = require('../scripts/_utils')

const currentDeps = [
require('../package.json'),
require('../../eslint-config-accurapp/package.json'),
require('../../webpack-preset-accurapp/package.json'),
]

Promise.all(currentDeps.map((dep) => latestVersion(dep.name)))
.then((npmVersions) => {
const updatedDeps = npmVersions.map((version, i) => Object.assign({}, currentDeps[i], { version }))
const outdatedDeps = currentDeps.filter((dep, i) => semver.lt(dep.version, updatedDeps[i].version))

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

// start the designated script
const script = process.argv[2]
try {
require('../scripts/' + script)
Expand Down
5 changes: 4 additions & 1 deletion packages/accurapp-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
"accurapp-scripts": "./bin/scripts.js"
},
"dependencies": {
"chalk": "^1.1.3",
"boxen": "^1.1.0",
"chalk": "^2.0.1",
"cross-spawn": "^5.1.0",
"detect-port": "^1.2.0",
"dotenv": "^4.0.0",
"figlet": "^1.2.0",
"fs-extra": "^3.0.1",
"latest-version": "^3.1.0",
"path": "^0.12.7",
"react-dev-utils": "^3.0.2",
"semver": "^5.3.0",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.5"
},
Expand Down
25 changes: 25 additions & 0 deletions packages/accurapp-scripts/scripts/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const webpack = require('webpack')
const chalk = require('chalk')
const figlet = require('figlet')
const boxen = require('boxen')
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')

const log = {
Expand All @@ -21,6 +22,28 @@ function coloredBanner(text, colors = ['blue', 'red']) {
return `\n${colored}`
}

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)}`
)

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')}
`
}

function indent(text, prepend = ' ', firstLinePrepend = prepend) {
return text
.split(`\n`)
Expand Down Expand Up @@ -88,6 +111,8 @@ module.exports = {
log,
noop,
coloredBanner,
yellowBox,
createOutdatedMessage,
indent,
listLine,
readWebpackConfig,
Expand Down

0 comments on commit 866b407

Please sign in to comment.