-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from snyk-tech-services/feat/introduce-handlebars
feat: introduce handlebars & views
- Loading branch information
Showing
29 changed files
with
521 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
12 | ||
14 | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as debugLib from 'debug'; | ||
import * as pathLib from 'path'; | ||
import { getApiToken } from '../lib/get-api-token'; | ||
import { | ||
LicenseReportData, | ||
generateLicenseData, | ||
} from '../lib/generate-org-license-report'; | ||
import { | ||
generateHtmlReport, | ||
generatePdfReport, | ||
SupportedViews, | ||
} from '../lib/generate-output'; | ||
import { writeContentsToFile } from '../lib/write-contents-to-file'; | ||
const debug = debugLib('snyk-licenses:generate'); | ||
|
||
const outputHandlers = { | ||
[OutputFormat.HTML]: generateHtmlReport, | ||
// [OutputFormat.PDF]: generatePdfReport | ||
}; | ||
const enum OutputFormat { | ||
HTML = 'html', | ||
// TODO: support later | ||
// PDF = 'pdf', | ||
} | ||
|
||
export const desc = | ||
'Generate org licenses & dependencies report in HTML format'; | ||
export const builder = { | ||
orgPublicId: { | ||
required: true, | ||
default: undefined, | ||
desc: | ||
'Public id of the organization in Snyk (available on organization settings)', | ||
}, | ||
template: { | ||
default: undefined, | ||
desc: 'Path to custom Handelbars.js template file (*.hbs)', | ||
}, | ||
outputFormat: { | ||
default: OutputFormat.HTML, | ||
desc: 'Report format', | ||
// TODO: add also PDF when ready | ||
options: [OutputFormat.HTML], | ||
}, | ||
view: { | ||
// TODO: add also dependency based view when ready | ||
default: SupportedViews.ORG_LICENSES, | ||
desc: | ||
'How should the data be represented. Defaults to a license based view.', | ||
}, | ||
}; | ||
export const aliases = ['g']; | ||
|
||
export async function handler(argv: { | ||
orgPublicId: string; | ||
outputFormat: OutputFormat; | ||
template: string; | ||
view: SupportedViews; | ||
}) { | ||
try { | ||
const { orgPublicId, outputFormat, template, view } = argv; | ||
debug( | ||
'ℹ️ Options: ' + | ||
JSON.stringify({ orgPublicId, outputFormat, template, view }), | ||
); | ||
getApiToken(); | ||
const licenseData: LicenseReportData = await generateLicenseData( | ||
orgPublicId, | ||
); | ||
const generateReportFunc = outputHandlers[outputFormat]; | ||
const res = await generateReportFunc(licenseData, template, view); | ||
if (res) { | ||
const outputFileName = `${orgPublicId}-${view}.html`; | ||
const outputFile = pathLib.resolve(__dirname, outputFileName); | ||
debug(`ℹ️ Saving generated report to ${outputFile}`); | ||
writeContentsToFile(res, outputFile); | ||
console.log('License report saved at ' + outputFile); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.