diff --git a/packages/accurapp-scripts/bin/scripts.js b/packages/accurapp-scripts/bin/scripts.js index 889e3bb4..258c4f7d 100755 --- a/packages/accurapp-scripts/bin/scripts.js +++ b/packages/accurapp-scripts/bin/scripts.js @@ -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) diff --git a/packages/accurapp-scripts/package.json b/packages/accurapp-scripts/package.json index d22ff254..4bdcdad7 100644 --- a/packages/accurapp-scripts/package.json +++ b/packages/accurapp-scripts/package.json @@ -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" }, diff --git a/packages/accurapp-scripts/scripts/_utils.js b/packages/accurapp-scripts/scripts/_utils.js index 519ffee1..2a628d0f 100644 --- a/packages/accurapp-scripts/scripts/_utils.js +++ b/packages/accurapp-scripts/scripts/_utils.js @@ -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 = { @@ -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`) @@ -88,6 +111,8 @@ module.exports = { log, noop, coloredBanner, + yellowBox, + createOutdatedMessage, indent, listLine, readWebpackConfig,