Snyk Licenses Attribution Report
+Org: {{orgData.name}}
+ {{#each licenses}} ++ {{id}} +
+ Severity: {{severity}} + {{#if instructions}} + Legal Instructions: {{instructions}} + {{/if}} ++ {{/each}} +
diff --git a/src/cmds/generate.ts b/src/cmds/generate.ts index 8b54a54..d893d6c 100644 --- a/src/cmds/generate.ts +++ b/src/cmds/generate.ts @@ -41,7 +41,7 @@ export const builder = { choices: [OutputFormat.HTML, OutputFormat.PDF], }, view: { - // TODO: add also dependency based view when ready + choices: [SupportedViews.ORG_LICENSES, SupportedViews.PROJECT_DEPENDENCIES], default: SupportedViews.ORG_LICENSES, desc: 'How should the data be represented. Defaults to a license based view.', diff --git a/src/cmds/json.ts b/src/cmds/json.ts index 53b5de5..cb01982 100644 --- a/src/cmds/json.ts +++ b/src/cmds/json.ts @@ -12,13 +12,7 @@ export const builder = { orgPublicId: { required: true, default: undefined, - }, - 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 = ['j']; diff --git a/src/lib/generate-org-license-report.ts b/src/lib/generate-org-license-report.ts index 0bfe51a..3ccaa61 100644 --- a/src/lib/generate-org-license-report.ts +++ b/src/lib/generate-org-license-report.ts @@ -5,7 +5,7 @@ export * from './license-text'; export * from './get-api-token'; import { getLicenseDataForOrg, getDependenciesDataForOrg } from './api/org'; import { fetchSpdxLicenseTextAndUrl, fetchNonSpdxLicenseTextAndUrl } from './license-text'; -import { LicenseReportDataEntry, EnrichedDependency, Dependency } from './types'; +import { LicenseReportDataEntry, EnrichedDependency, Dependency, DependencyData } from './types'; const debug = debugLib('snyk-licenses:generateOrgLicensesReport'); @@ -29,7 +29,11 @@ export async function generateLicenseData( debug(`✅ Got dependencies API data for Org:${orgPublicId}`); const licenseReportData: LicenseReportData = {}; const dependenciesData = _.groupBy(dependenciesDataRaw.results, 'id'); - // TODO: what if 0? + + if (!licenseData.total) { + debug(`ℹ️ Detected 0 licenses`); + return licenseReportData; + } debug(`⏳ Processing ${licenseData.total} licenses`); const dependenciesAll = []; @@ -69,9 +73,9 @@ function enrichDependencies( dependencies: Dependency[], dependenciesData, ): EnrichedDependency[] { - const enrichDependencies = []; + const enrichDependencies: EnrichedDependency [] = []; for (const dependency of dependencies) { - const dep = dependenciesData[dependency.id]; + const dep: DependencyData[] = dependenciesData[dependency.id]; if (dep && dep[0]) { enrichDependencies.push({ ...dependency, diff --git a/src/lib/generate-report/index.ts b/src/lib/generate-report/index.ts index 7f7f6af..b9959eb 100644 --- a/src/lib/generate-report/index.ts +++ b/src/lib/generate-report/index.ts @@ -5,16 +5,15 @@ import * as debugLib from 'debug'; import { LicenseReportData } from '../generate-org-license-report'; import { OrgData } from '../get-org-data'; -import { generateReportName } from '../generate-report-name'; import { SupportedViews } from '../types'; +import _ = require('lodash'); const debug = debugLib('snyk-licenses:generateHtmlReport'); const DEFAULT_TEMPLATE = './templates/licenses-view.hbs'; const transformDataFunc = { [SupportedViews.ORG_LICENSES]: transformDataForLicenseView, - // TODO: support later - // [SupportedViews.PROJECT_DEPENDENCIES]: transformDataForDependencyView, + [SupportedViews.PROJECT_DEPENDENCIES]: transformDataForDependencyView, }; export async function generateHtmlReport( @@ -50,18 +49,38 @@ function transformDataForLicenseView( return { licenses: data, orgPublicId, orgData }; } -// TODO: support later -// function transformDataForDependencyView(data: LicenseReportData) { -// return data; -// } +interface ProjectsReportData { + [projectId: string]: LicenseReportData; +} + +function transformDataForDependencyView( + orgPublicId: string, + data: LicenseReportData, + orgData: OrgData, + ): { + projects: ProjectsReportData; + orgPublicId: string; + orgData: OrgData; + } { + + const projectData: ProjectsReportData = {}; + + for (const licenseId in Object.keys(data)) { + console.log('*** licenseId=', licenseId); + const licenseData = data[licenseId]; + + } + + + return { projects: projectData, orgPublicId, orgData }; +} function selectTemplate(view: SupportedViews, templateOverride?): string { switch (view) { case SupportedViews.ORG_LICENSES: return templateOverride || DEFAULT_TEMPLATE; - // TODO: support later - // case SupportedViews.PROJECT_DEPENDENCIES: - // return templateOverride || '../templates/project-dependencies-view.hbs'; + case SupportedViews.PROJECT_DEPENDENCIES: + return templateOverride || './templates/project-dependencies-view.hbs'; default: return DEFAULT_TEMPLATE; } diff --git a/src/lib/generate-report/templates/project-dependencies-view.hbs b/src/lib/generate-report/templates/project-dependencies-view.hbs index e69de29..7fb7f3f 100644 --- a/src/lib/generate-report/templates/project-dependencies-view.hbs +++ b/src/lib/generate-report/templates/project-dependencies-view.hbs @@ -0,0 +1,211 @@ + + + +
+ + + + +