Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for HTML output (resolves #20) #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ var yargs = require('yargs')
baseDir: {
alias: 'b',
default: process.cwd(),
},
outputFormat: {
alias: 'f',
default: 'txt',
choices: ['txt', 'html']
}
})
.array('baseDir')
.example('$0 -o ./tpn', 'run the tool and output text and backing json to ${projectRoot}/tpn directory.')
.example('$0 -o ./tpn -f html', 'run the tool and output html and backing json to ${projectRoot}/tpn directory.')
.example('$0 -b ./some/path/to/projectDir', 'run the tool for Bower/NPM projects in another directory.')
.example('$0 -o tpn -b ./some/path/to/projectDir', 'run the tool in some other directory and dump the output in a directory called "tpn" there.');

Expand Down Expand Up @@ -309,7 +315,8 @@ function getBowerLicenses() {
// sanitize inputs
var options = {
baseDir: [],
outputDir: path.resolve(yargs.argv.outputDir)
outputDir: path.resolve(yargs.argv.outputDir),
outputFormat: ['txt', 'html'].includes(yargs.argv.outputFormat) ? yargs.argv.outputFormat : 'txt'
};

for (var i = 0; i < yargs.argv.baseDir.length; i++) {
Expand Down Expand Up @@ -353,11 +360,36 @@ taim('Total Processing', bluebird.all([
}).sortBy(licenseInfo => {
return licenseInfo.name.toLowerCase();
}).map(licenseInfo => {
if (options.outputFormat === 'html') {
return `
<tr>
<td>${licenseInfo.name}</td>
<td>${licenseInfo.version}</td>
<td>${licenseInfo.url}</td>
<td>${licenseInfo.license}</td>
<td>${licenseInfo.licenseText}</td>
</tr>
`;
}
return [licenseInfo.name,`${licenseInfo.version} <${licenseInfo.url}>`,
licenseInfo.licenseText || `license: ${licenseInfo.license}${os.EOL}authors: ${licenseInfo.authors}`].join(os.EOL);
}).value();

var attribution = attributionSequence.join(`${os.EOL}${os.EOL}******************************${os.EOL}${os.EOL}`);

if (options.outputFormat === 'html') {
var tableHeader =
`
<tr>
<th>Name</th>
<th>Version</th>
<th>URL</th>
<th>License</th>
<th>LicenseText</th>
</tr>
`
var attribution = `<table>${tableHeader}${attributionSequence.join("")}</table>`;
} else {
var attribution = attributionSequence.join(`${os.EOL}${os.EOL}******************************${os.EOL}${os.EOL}`);
}

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

Expand All @@ -369,7 +401,7 @@ taim('Total Processing', bluebird.all([

jetpack.write(path.join(options.outputDir, 'licenseInfos.json'), JSON.stringify(licenseInfos));

return jetpack.write(path.join(options.outputDir, 'attribution.txt'), attribution);
return jetpack.write(path.join(options.outputDir, `attribution.${options.outputFormat}`), attribution);
})
.catch(e => {
console.error('ERROR writing attribution file', e);
Expand Down