Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-deloitte committed Jun 12, 2019
0 parents commit 258987a
Show file tree
Hide file tree
Showing 16 changed files with 2,793 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
quote_type = single

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extends:
- '@frosti/eslint-config-base'
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# * Files
*.log
npm-debug.log*
node_modules

# . Files
.DS_Store
*.cache
*.pem

# ENV Files
.env
.env.development
.env.development.local
.env.local
.env.test.local
.env.test
.env.production
.env.production.local

# Build Files
.dist
coverage


# HOSTING
.firebase
**/.firebaserc
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.log
index.js
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.15
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
semi: true
singleQuote: true
trailingComma: none
bracketSpacing: true
arrowParens: always
overrides:
- files:
- '.eslintrc'
- '.prettierrc'
options:
parser: 'yaml'
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0

- Initial release
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT LICENSE

Copyright (c) 2019, Jesse Weed http://jesseweed.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Asguard

Automated check to use as a guard against security risks and unused or missing 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

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

## Usage

### Install

###### As a Module

```
$ npm install @frosti/asguard
```

###### Globally

```
$ npm install @frosti/asguard -g
```

### Automated scanning

The recommended usage is as an npm script in conjunction with something like [Husky](https://www.npmjs.com/package/husky) to automatically run before pushing any code into source control:

```
{
"scripts": {
"check": "asguard"
},
"husky": {
"hooks": {
"pre-push": "npm run check"
}
},
}
```

### Manual scanning

If you prefer to just run your checks manually, you can also simply run Asguard directly:

###### Installed globally

```
$ asguard
```

###### Installed as a module

```
$ npx asguard
```

## Options

### Warn Only

By default Asguard will throw an error and exit with [process.exit(1)](https://nodejs.org/api/process.html#process_event_exit) if it encounters any problems.

If you would prefer to just show a warning instead of throwing an error, you can use the `--warn` flag.

```
$ asguard --warn
```
21 changes: 21 additions & 0 deletions bin/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const argv = require('minimist')(process.argv.slice(2));
const emoji = require('node-emoji');

let warnOnly = false;
let errorColor = 'red';
let errorEmoji = emoji.get('x');

if (argv.v || argv.V || argv.warn) warnOnly = true;

if (warnOnly) {
errorColor = 'yellow';
errorEmoji = emoji.get('warning');
}

module.exports = {
warnOnly,
errorColor,
errorEmoji,
name: 'Asguard',
script: '@frosti/asguard'
};
64 changes: 64 additions & 0 deletions bin/_logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const emoji = require('node-emoji');
const figlet = require('figlet');
const config = require('./_config');

const { name, warnOnly } = config;

const biglog = (msg, color) => {
console.log('\n');
console.log('----------------------------------------------------------------'[color]);
console.log(`${msg}`[color]);
console.log('----------------------------------------------------------------'[color]);
console.log('\n');
};

const start = () => {
console.log('\n');
console.log('----------------------------------------------------------------');
console.log('\n');
console.log(
figlet.textSync(` ${name}`, {
horizontalLayout: 'full',
font: 'ANSI Shadow'
}).white
);
console.log(
` ${emoji.get('shield')} Guard against security risks and unused dependencies ${emoji.get(
'shield'
)}`
);
console.log('\n');
console.log('----------------------------------------------------------------');
console.log('\n');
};

const quit = (code) => {
if (code === 0) {
biglog(
` ${emoji.get('tada')} You're all good! ${name.bold} found no issues! ${emoji.get(
'tada'
)}`,
'green'
);
} else if (warnOnly) {
code = 0;
biglog(
`${emoji.get('cry')} ${name.bold} found some problems, check logs above for more info.`,
'yellow'
);
} else {
code = 0;
console.log('\n');
console.log(
`${emoji.get('broken_heart')} ${
name.bold
} found some problems, check logs above for more info.!`.red
);
console.log('\n');
}
process.exit(code);
};

module.exports.biglog = biglog;
module.exports.quit = quit;
module.exports.start = start;
23 changes: 23 additions & 0 deletions bin/asguard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env node

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

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

// Check for unused depewndencies
depcheck()
// Check for security risks
.then(npm)
.then(() => {
quit(0);
})
.catch(() => {
quit(1);
});
};

asguard();
Loading

0 comments on commit 258987a

Please sign in to comment.