Skip to content

Commit

Permalink
Finished commenting code
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychoSnake committed Jul 14, 2018
1 parent 2281ef3 commit 52935f6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 54 deletions.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a

const logger = _bunyan2.default.createLogger({ name: 'Index' });

/**
* Creates a request for the report
* @param {Object} body body of the request
*/
const getRequest = body => {
return new Request('http://35.234.151.254/report', {
headers: {
Expand Down Expand Up @@ -73,7 +77,7 @@ function generateReport(policyData, pkg, dependencies, error) {
const report = new _report_model.Report(reportOptions);
report.insertDependencies(dependencies);

_fileManager2.default.writeBuildFile('report.json', JSON.stringify(report));
(0, _fileManager2.default)('report.json', JSON.stringify(report));
logger.info('Generated report');

return report;
Expand Down
47 changes: 20 additions & 27 deletions lib/utils/file-manager.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
'use strict';

const fs = require('fs');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = writeBuildFile;

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Writes into a file asynchronously
* @param {String} fileName the name of the file to write to
* @param {String} fileData the data to be written
*/
function writeBuildFile(fileName, fileData) {
fs.stat('./build', (err, stats) => {
_fs2.default.stat('./build', (err, stats) => {
if (err) {
fs.mkdir('./build', err => {
_fs2.default.mkdir('./build', err => {
if (err) {
throw new Error(err);
}
fs.writeFileSync(`./build/${fileName}`, fileData);
_fs2.default.writeFileSync(`./build/${fileName}`, fileData);
});
} else {
fs.writeFileSync(`./build/${fileName}`, fileData);
}
});
}

function readFile(filePath, cb) {
fs.stat(filePath, (err, stats) => {
if (err) {
return cb(err);
}
if (stats.isFile) {
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
return cb(err);
}
return cb(null, data);
});
_fs2.default.writeFileSync(`./build/${fileName}`, fileData);
}
});
}

module.exports = {
writeBuildFile,
readFile
};
}
5 changes: 5 additions & 0 deletions lib/utils/vulnerabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a

const logger = _bunyan2.default.createLogger({ name: 'Fetch-Vulnerabilities' });

/**
* Creates a request to fetch vulnerabilites
* @param {Object} body body of the request
* @param {Number} cacheTime time for the cache in the proxy
*/
const getRequest = (body, cacheTime) => {
return new Request('http://35.234.151.254/npm/dependency/vulnerabilities', {
headers: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"debug": "node ./bin/npm-dependency-analyzer | bunyan",
"clean": "rimraf build/ && rimraf lib/",
"prebuild": "npm install && npm run clean",
"build": "npm run lint && babel src -d lib",
"build": "npm run lint && babel src -d lib && npm test",
"lint": "standard src/ --fix",
"test": "jest | bunyan"
},
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import getVulnerabilities from './utils/vulnerabilities'
import getDependencies from './utils/dependencies'
import getLicenses from './utils/licenses'
import {Report} from './report_model'
import fileManager from './utils/file-manager'
import writeFile from './utils/file-manager'
import {catchifyPromise} from './utils/utility-functions'

const logger = bunyan.createLogger({name: 'Index'})

/**
* Creates a request for the report
* @param {Object} body body of the request
*/
const getRequest = body => {
return new Request('http://35.234.151.254/report', {
headers: {
Expand Down Expand Up @@ -47,7 +51,7 @@ function generateReport (policyData, pkg, dependencies, error) {
const report = new Report(reportOptions)
report.insertDependencies(dependencies)

fileManager.writeBuildFile('report.json', JSON.stringify(report))
writeFile('report.json', JSON.stringify(report))
logger.info('Generated report')

return report
Expand Down
30 changes: 7 additions & 23 deletions src/utils/file-manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict'

const fs = require('fs')
import fs from 'fs'

function writeBuildFile (fileName, fileData) {
/**
* Writes into a file asynchronously
* @param {String} fileName the name of the file to write to
* @param {String} fileData the data to be written
*/
export default function writeBuildFile (fileName, fileData) {
fs.stat('./build', (err, stats) => {
if (err) {
fs.mkdir('./build', err => {
Expand All @@ -16,24 +21,3 @@ function writeBuildFile (fileName, fileData) {
}
})
}

function readFile (filePath, cb) {
fs.stat(filePath, (err, stats) => {
if (err) {
return cb(err)
}
if (stats.isFile) {
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
return cb(err)
}
return cb(null, data)
})
}
})
}

module.exports = {
writeBuildFile,
readFile
}
5 changes: 5 additions & 0 deletions src/utils/vulnerabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import RequestBody from '../oss-fetch-body'

const logger = bunyan.createLogger({name: 'Fetch-Vulnerabilities'})

/**
* Creates a request to fetch vulnerabilites
* @param {Object} body body of the request
* @param {Number} cacheTime time for the cache in the proxy
*/
const getRequest = (body, cacheTime) => {
return new Request('http://35.234.151.254/npm/dependency/vulnerabilities', {
headers: {
Expand Down

0 comments on commit 52935f6

Please sign in to comment.