Skip to content

Commit

Permalink
Refactored Code to avoid licenses getting from readMe (#13)
Browse files Browse the repository at this point in the history
* refactored code and removed bluebird and added time measure

* Refactored Code. Removed bluebird in NPM. Modified Search Process

* Removed ReadMe reading

* Removed ReadMe reading

* Formatted Code

* Added Time  Measure

* Added filter while outputting text
  • Loading branch information
rohithjidagam authored and Daniel Zumwalt committed Feb 22, 2018
1 parent 25aa471 commit 3c27d5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
27 changes: 17 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var path = require('path');
var jetpack = require('fs-jetpack');
var cp = require('child_process');
var os = require('os');
var taim = require('taim');

// const
var licenseCheckerCustomFormat = {
Expand Down Expand Up @@ -108,6 +109,7 @@ function getNpmLicenses() {
}
return merged;
}).then((result) => {

// we want to exclude the top-level project from being included
var dir = result[Object.keys(result)[0]]['dir'];
var topLevelProjectInfo = jetpack.read(path.join(dir, 'package.json'), 'json');
Expand All @@ -117,6 +119,7 @@ function getNpmLicenses() {

return bluebird.map(keys, (key) => {
console.log('processing', key);

var package = result[key];
var defaultPackagePath = `${package['dir']}/node_modules/${package.name}/package.json`
return jetpack.existsAsync(defaultPackagePath)
Expand Down Expand Up @@ -149,7 +152,13 @@ function getNpmLicenses() {
return getAttributionForAuthor(m);
}).join(', '));

props.licenseText = package.licenseFile && jetpack.exists(package.licenseFile) ? jetpack.read(package.licenseFile) : '';
var licenseFile = package.licenseFile;
if (licenseFile && jetpack.exists(licenseFile) && path.basename(licenseFile).match(/license/i)) {
props.licenseText = jetpack.read(licenseFile);
} else {
props.licenseText = '';
}

return props;
})
.catch(e => {
Expand Down Expand Up @@ -292,10 +301,10 @@ for (var i = 0; i < yargs.argv.baseDir.length; i++) {
}


bluebird.all([
getNpmLicenses(),
taim('Total Processing', bluebird.all([
taim('Npm Licenses', getNpmLicenses()),
getBowerLicenses()
])
]))
.catch((err) => {
console.log(err);
process.exit(1);
Expand Down Expand Up @@ -324,16 +333,14 @@ bluebird.all([
})
.then((licenseInfos) => {
var attribution = _.filter(licenseInfos, licenseInfo => {
return !licenseInfo.ignore;
return !licenseInfo.ignore && licenseInfo.name != undefined;
}).map(licenseInfo => {
return [
licenseInfo.name,
`${licenseInfo.version} <${licenseInfo.url}>`,
licenseInfo.licenseText || `license: ${licenseInfo.license}${os.EOL}authors: ${licenseInfo.authors}`
].join(os.EOL);
return [licenseInfo.name,`${licenseInfo.version} <${licenseInfo.url}>`,
licenseInfo.licenseText || `license: ${licenseInfo.license}${os.EOL}authors: ${licenseInfo.authors}`].join(os.EOL);
}).join(`${os.EOL}${os.EOL}******************************${os.EOL}${os.EOL}`);

var headerPath = path.join(options.outputDir, 'header.txt');

if (jetpack.exists(headerPath)) {
var template = jetpack.read(headerPath);
console.log('using template', template);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license-checker": "^13.0.3",
"lodash": "^4.17.4",
"spdx-licenses": "^0.0.3",
"yargs": "^7.0.2"
"yargs": "^7.0.2",
"taim": "^1.0.2"
},
"name": "oss-attribution-generator",
"description": "utility to parse bower and npm packages used in a project and generate an attribution file to include in your product",
Expand Down

0 comments on commit 3c27d5f

Please sign in to comment.