|
1 | 1 | /** |
2 | | - * This is a JavaScript file which loads `license-report` md-files from the external repositories. |
| 2 | + * This is a JavaScript file which loads Markdown content from the dependency report files |
| 3 | + * via Spine public repositories. |
3 | 4 | * |
4 | | - * Please see `/oss-licenses/index.html` for usage. |
| 5 | + * See `/oss-licenses/index.html` for usage. |
5 | 6 | */ |
6 | 7 | 'use strict'; |
7 | 8 |
|
|
12 | 13 | const repoAttr = 'repo'; |
13 | 14 | const repoName = 'repo-name'; |
14 | 15 |
|
| 16 | + // Spine repositories are migrated being migrated to listing their deps in this file. |
| 17 | + const reportFilePath = '/master/dependencies.md'; |
| 18 | + |
| 19 | + // Previously used report file path, as a fallback for non-migrated repos. |
| 20 | + const legacyFilePath = '/master/license-report.md'; |
| 21 | + |
15 | 22 | /** |
16 | | - * Loads `license-report` file from the repository. |
| 23 | + * Loads the dependency report file from the repository. |
| 24 | + * |
| 25 | + * <p>There may be one of two report files present in the repo: |
| 26 | + * `license-report.md` or `dependencies.md`. |
| 27 | + * The latter is a newer version of the report, so it is loaded |
| 28 | + * as a priority. In case it is missing, `license-report.md` is loaded, as a fallback. |
| 29 | + * Eventually, all Spine repositories will migrate to having `dependencies.md`. |
| 30 | + * |
| 31 | + * <p>The report sections describing the terms of use for dual-licensed dependencies, |
| 32 | + * and another one with the credits paid to the author of Gradle plugin |
| 33 | + * we use for reporting, are removed from DOM, as they are now moved |
| 34 | + * to the static part of the page (see `/oss-licenses.index.html`). |
17 | 35 | * |
18 | 36 | * <p>Executes by clicking on the corresponding link. The destination `div` element |
19 | 37 | * should have the `id` like `md-destination-REPO_NAME`. |
|
26 | 44 |
|
27 | 45 | if (loaded === 'false') { |
28 | 46 | const repositoryUrl = clickedElement.attr(repoAttr); |
29 | | - $.get( |
30 | | - repositoryUrl + '/master/license-report.md', |
31 | | - function (data) { |
32 | | - const html = converter.makeHtml(data); |
33 | | - mdDestinationEl.html(html); |
34 | | - clickedElement.attr(loadedAttr, 'true'); |
35 | | - makeCollapsibleTitle(mdDestinationEl, clickedElRepoName); |
36 | | - } |
37 | | - ); |
| 47 | + let processLoadedContent = function (data) { |
| 48 | + const html = converter.makeHtml(data); |
| 49 | + mdDestinationEl.html(html); |
| 50 | + clickedElement.attr(loadedAttr, 'true'); |
| 51 | + makeCollapsibleTitle(mdDestinationEl, clickedElRepoName); |
| 52 | + }; |
| 53 | + |
| 54 | + let reportUrl = repositoryUrl + reportFilePath; |
| 55 | + let legacyReportUrl = repositoryUrl + legacyFilePath; |
| 56 | + |
| 57 | + $.get(reportUrl, processLoadedContent) |
| 58 | + .fail(function () { |
| 59 | + $.get(legacyReportUrl, processLoadedContent) |
| 60 | + }); |
38 | 61 | } |
39 | 62 | }); |
40 | 63 |
|
41 | 64 | /** |
42 | | - * Makes a `license-report` content collapsible. |
| 65 | + * Makes the report content collapsible. |
43 | 66 | * |
44 | 67 | * @param mdDestinationEl `div` with the markdown content |
45 | 68 | * @param clickedElRepoName repository name from the link attribute |
|
68 | 91 | }); |
69 | 92 |
|
70 | 93 | /** |
71 | | - * Makes all markdown links external. |
| 94 | + * Makes all Markdown links external. |
72 | 95 | */ |
73 | 96 | linkElements.addClass('external'); |
74 | 97 | linkElements.attr('target', '_blank'); |
|
81 | 104 | const titleID = clickedElRepoName + '-' + this.id + '-md'; |
82 | 105 | const collapsibleContent = $(element).next('ol'); |
83 | 106 | const reportInfoContent = collapsibleContent.next('p'); |
| 107 | + const whenGeneratedContent = reportInfoContent.next('p'); |
84 | 108 |
|
85 | 109 | $(element).addClass('collapse-link collapsed'); |
86 | 110 | $(element).attr('href', '#' + titleID); |
|
89 | 113 | collapsibleContent.addClass('dependencies-container collapse'); |
90 | 114 | collapsibleContent.attr('id', titleID); |
91 | 115 |
|
92 | | - reportInfoContent.addClass('report-info collapse'); |
93 | | - reportInfoContent.attr('id', titleID + '-p'); |
94 | | - }); |
95 | | - |
96 | | - makeReportInfoCollapsible(mdDestinationEl); |
97 | | - } |
98 | | - |
99 | | - /** |
100 | | - * Makes report information content collapsible. |
101 | | - * |
102 | | - * <p>Report information contains a generation date and the name of the plugin. |
103 | | - * |
104 | | - * @param mdDestinationEl it is a `div` with a markdown content |
105 | | - */ |
106 | | - function makeReportInfoCollapsible(mdDestinationEl) { |
107 | | - const reportInfoContent = mdDestinationEl.find('.report-info'); |
108 | | - |
109 | | - /** |
110 | | - * Inserts a new collapsible title for the paragraph with a report information. |
111 | | - */ |
112 | | - const reportInfoTitleEl = "<h2 class='report-info-title collapse-link collapsed'>Report info</h2>"; |
113 | | - $(reportInfoTitleEl).insertBefore(reportInfoContent); |
114 | | - |
115 | | - reportInfoContent.each(function (index, element) { |
116 | | - const reportInfoID = this.id; |
117 | | - const reportInfoTitle = $(element).prev('.report-info-title'); |
118 | | - |
119 | | - reportInfoTitle.attr('href', '#' + reportInfoID); |
120 | | - reportInfoTitle.attr('data-toggle', 'collapse'); |
| 116 | + reportInfoContent.remove(); |
| 117 | + whenGeneratedContent.remove(); |
121 | 118 | }); |
122 | 119 | } |
123 | 120 | } |
|
0 commit comments