Skip to content

Commit

Permalink
Changed Variable from "var" to "let" & reduced amount of spaghetti code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chickenbreadlp committed Jul 25, 2019
1 parent 76974e4 commit 00e8020
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else {
runPath = process.argv[process.argv.indexOf('-p') + 1]
}

var allPackages;
let allPackages;

if (array) {
allPackages = []
Expand All @@ -43,15 +43,17 @@ else {

// Returns the contents of the package.json
function readPackageData(modulePath) {
var rawdata = fs.readFileSync(path.resolve(runPath, 'node_modules', modulePath, 'package.json'));
var package = JSON.parse(rawdata);
let pathToPackage = path.resolve(runPath, 'node_modules', modulePath, 'package.json');
let rawdata = fs.readFileSync(pathToPackage);
let package = JSON.parse(rawdata);

return package;
}
// Returns the contents of the license file
function readLicenseFile(modulePath) {
if (fs.existsSync(path.resolve(runPath, 'node_modules', modulePath, 'LICENSE'))) {
var licenseText = fs.readFileSync(path.resolve(runPath, 'node_modules', modulePath, 'LICENSE'), { encoding: 'utf8'});
let pathToLicense = path.resolve(runPath, 'node_modules', modulePath, 'LICENSE');
if (fs.existsSync(pathToLicense)) {
let licenseText = fs.readFileSync(pathToLicense, { encoding: 'utf8'});
return licenseText
}
else {
Expand All @@ -62,8 +64,8 @@ else {
// Adds a package with it's license to the allPackages object
function addPackage(modulePath) {
// Gets the package.json and the license
var package = readPackageData(modulePath);
var license = readLicenseFile(modulePath);
let package = readPackageData(modulePath);
let license = readLicenseFile(modulePath);

if (typeof package.author !== 'object') {
package.author = {
Expand Down Expand Up @@ -98,14 +100,15 @@ else {

if (fs.existsSync(path.resolve(runPath, 'node_modules'))) {
// Gets an Array of all node_modules
var allDirs = getDirectories(path.resolve(runPath, 'node_modules'));
let nodeModuleFolder = path.resolve(runPath, 'node_modules');
let allDirs = getDirectories(nodeModuleFolder);

for (var i = 0; i < allDirs.length; i++) {
// Only if the folder isn't a "hidden" one, check if it's a module collection or not
if (allDirs[i].indexOf('.') !== 0) {
if (allDirs[i].indexOf('@') === 0) {
// go through all the modules within a module collection
var tmpDirs = getDirectories(path.resolve(runPath, 'node_modules', allDirs[i]))
let tmpDirs = getDirectories(path.resolve(nodeModuleFolder, allDirs[i]))
for (var j = 0; j < tmpDirs.length; j++) {
if (tmpDirs[j].indexOf('.') !== 0 && tmpDirs[j].indexOf('@') !== 0) {
addPackage(allDirs[i] + '/' + tmpDirs[j]);
Expand All @@ -123,7 +126,7 @@ else {
// Checks wether the OutputFile Arg is given
if (process.argv.indexOf('-o') >= 0 && process.argv.indexOf('-o') + 1 < process.argv.length) {
// Writes Packagedata to specified file
var outputFile = process.argv[process.argv.indexOf('-o') + 1];
let outputFile = process.argv[process.argv.indexOf('-o') + 1];
fs.writeFileSync(outputFile, JSON.stringify(allPackages), { encoding: 'utf8' });
console.log('File written: ' + path.resolve(outputFile));
}
Expand Down

0 comments on commit 00e8020

Please sign in to comment.