Skip to content

Commit

Permalink
add check for outdated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-deloitte committed Jun 13, 2019
1 parent ad889f2 commit 4846920
Show file tree
Hide file tree
Showing 11 changed files with 1,907 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
extends:
- '@frosti/eslint-config-base'

rules:
no-console: 0
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.0

- Add check for outdated packages

## 0.1.3

- Update to use `0.1.x` version of `@frosti/eslint-config-base`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Asguard

Automated check to use as a guard against security risks and unused or missing dependencies.
Automated check to use as a guard against security risks and unused, missing or outdated dependencies.

Can be used standalone, but is highly customized for use by [Frosti Boilerplates](https://github.com/frostijs/cli).

### Scan For Security Vulnerabilities

Utilizes [npm audit](https://docs.npmjs.com/cli/audit) to scan project dependencies for any know vulnerabilities.

### Find Unused or Missing Dependencies
### Find Unused, Missing & OUt Of Date Dependencies

Uses [depcheck](https://www.npmjs.com/package/depcheck) to look for any missing or unused dependencies in your projects `package.json` file.

Expand Down
18 changes: 12 additions & 6 deletions bin/asguard.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#! /usr/bin/env node

// CHECKS
const depcheck = require('./depcheck');
const npm = require('./npm');
const { quit, start } = require('./_logger');
const depcheck = require('./lib/depcheck');
const security = require('./lib/security');
const outdated = require('./lib/outdated');
const { quit, start } = require('./lib/_logger');

const asguard = () => {
start();

// Check for unused depewndencies
depcheck()
// Check for security risks
.then(npm)
.then(() => {
quit(0);
.then(security)
.then(outdated)
.then((result) => {
if (result === 'updates') {
process.exit(0);
} else {
quit(0);
}
})
.catch(() => {
quit(1);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/_logger.js → bin/lib/_logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const quit = (code) => {
} else if (warnOnly) {
code = 0;
biglog(
`${emoji.get('cry')} ${name.bold} found some problems, check logs above for more info.`,
` ${emoji.get('cry')} ${name.bold} found some problems, check logs above for more info`,
'yellow'
);
} else {
Expand Down
24 changes: 12 additions & 12 deletions bin/depcheck.js → bin/lib/depcheck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env node
require('colors');
const depcheck = require('depcheck');
const emoji = require('node-emoji');
Expand All @@ -8,7 +7,7 @@ const config = require('./_config');
module.exports = () => new Promise((resolve, reject) => {
const ROOT_DIR = path.resolve(process.cwd());

const { errorColor, errorEmoji } = config;
const { errorColor, errorEmoji, name } = config;

const ignoreMatches = [
// Used by Asguard
Expand Down Expand Up @@ -38,6 +37,7 @@ module.exports = () => new Promise((resolve, reject) => {
'favicons',
'fs-extra',
'postcss-*',
'rollup',
'rollup-*',
'postcss',
'stylus',
Expand Down Expand Up @@ -110,7 +110,7 @@ module.exports = () => new Promise((resolve, reject) => {
if (missing || unused) {
console.log('\n');
console.warn(
`${errorEmoji} ${config.name.bold} found ${count} ${errorType} dependencies:`.white
`${errorEmoji} ${name.bold} found ${count} ${errorType} dependencies:`.white
);
} else {
console.log('\n');
Expand All @@ -119,28 +119,28 @@ module.exports = () => new Promise((resolve, reject) => {

if (dependencies.missing.length > 0) {
console.log('\n');
console.log(' Missing Dependencies'.red);
console.log(' --------------------'.red);
console.log(' Missing Dependencies'.red);
console.log(' --------------------'.red);
dependencies.missing.map((dependency) => {
console.log(` ${dependency}`.red);
console.log(` ${dependency}`.red);
});
}

if (dependencies.dependencies.length > 0) {
console.log('\n');
console.log(' Unused Dependencies'[errorColor]);
console.log(' -------------------'[errorColor]);
console.log(' Unused Dependencies'[errorColor]);
console.log(' -------------------'[errorColor]);
dependencies.dependencies.map((dependency) => {
console.log(` ${dependency}`[errorColor]);
console.log(` ${dependency}`[errorColor]);
});
}

if (dependencies.devDependencies.length > 0) {
console.log('\n');
console.log(' Unused Dev Dependencies'[errorColor]);
console.log(' -----------------------'[errorColor]);
console.log(' Unused Dev Dependencies'[errorColor]);
console.log(' -----------------------'[errorColor]);
dependencies.devDependencies.map((dependency) => {
console.log(` ${dependency}`[errorColor]);
console.log(` ${dependency}`[errorColor]);
});
}

Expand Down
48 changes: 48 additions & 0 deletions bin/lib/outdated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { exec } = require('child_process');
const emoji = require('node-emoji');
const config = require('./_config');

module.exports = () => new Promise((resolve, reject) => {
const { name } = config;

console.log('\n');
console.info(
`${emoji.get('mag')} ${'Checking for availbable updates...'.white} ${
'(npm outdated)'.grey
}`
);

exec('npm outdated', (err, stdout, stderr) => {
if (err && !stdout) {
console.error(err);
reject();
} else if (stderr) {
console.log(stderr);
reject();
} else if (stdout) {
console.log('\n');
console.log('----------------------------------------------------------------'.yellow);
console.log(
` ${emoji.get('warning')} ${`${
name.bold
} found out of date packages you may want to check ${emoji.get('warning')}`}`.yellow
);
console.log('----------------------------------------------------------------'.yellow);
// const updates = stdout;
stdout = stdout.split('Package').join('Package'.blue.bold);
stdout = stdout.split('Current').join('Current'.blue.bold);
stdout = stdout.split('Wanted').join('Wanted'.blue.bold);
stdout = stdout.split('Latest').join('Latest'.blue.bold);
stdout = stdout.split('Location').join('Location'.blue.bold);
console.log(stdout);
console.log('\n');
console.log(`${emoji.get('thumbsup')} Everything else looks A-OK!`.white);
console.log('\n');
resolve('updates');
} else {
console.log('\n');
console.log(`${emoji.get('sparkles')} All of your packages are up to date!`.blue);
resolve();
}
});
});
File renamed without changes.
Loading

0 comments on commit 4846920

Please sign in to comment.