@edx/frontend-platform 4.6.2 → 4.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/package.json +1 -1
  2. package/.env.development +0 -30
  3. package/.env.test +0 -30
  4. package/.eslintignore +0 -6
  5. package/.eslintrc.js +0 -28
  6. package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  7. package/.github/workflows/add-depr-ticket-to-depr-board.yml +0 -19
  8. package/.github/workflows/add-remove-label-on-comment.yml +0 -20
  9. package/.github/workflows/ci.yml +0 -42
  10. package/.github/workflows/commitlint.yml +0 -10
  11. package/.github/workflows/lockfileversion-check.yml +0 -13
  12. package/.github/workflows/manual-publish.yml +0 -43
  13. package/.github/workflows/npm-deprecate.yml +0 -22
  14. package/.github/workflows/release.yml +0 -45
  15. package/.github/workflows/self-assign-issue.yml +0 -12
  16. package/.github/workflows/update-browserslist-db.yml +0 -12
  17. package/.nvmrc +0 -1
  18. package/.releaserc +0 -32
  19. package/catalog-info.yaml +0 -21
  20. package/dist/LICENSE +0 -661
  21. package/dist/README.md +0 -155
  22. package/dist/package.json +0 -86
  23. package/docs/addTagsPlugin.js +0 -10
  24. package/docs/auth-API.md +0 -114
  25. package/docs/decisions/0001-record-architecture-decisions.rst +0 -32
  26. package/docs/decisions/0002-frontend-base-design-goals.rst +0 -222
  27. package/docs/decisions/0003-consolidation-into-frontend-platform.rst +0 -71
  28. package/docs/decisions/0004-axios-caching-implementation.rst +0 -88
  29. package/docs/decisions/0005-token-null-after-successful-refresh.rst +0 -69
  30. package/docs/decisions/0006-middleware-support-for-http-clients.rst +0 -44
  31. package/docs/decisions/0007-javascript-file-configuration.rst +0 -143
  32. package/docs/how_tos/automatic-case-conversion.rst +0 -58
  33. package/docs/how_tos/caching.rst +0 -93
  34. package/docs/how_tos/i18n.rst +0 -305
  35. package/docs/removeExport.js +0 -24
  36. package/docs/template/edx/README.md +0 -12
  37. package/docs/template/edx/publish.js +0 -713
  38. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.eot +0 -0
  39. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.svg +0 -1830
  40. package/docs/template/edx/static/fonts/OpenSans-Bold-webfont.woff +0 -0
  41. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  42. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  43. package/docs/template/edx/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  44. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.eot +0 -0
  45. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.svg +0 -1830
  46. package/docs/template/edx/static/fonts/OpenSans-Italic-webfont.woff +0 -0
  47. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.eot +0 -0
  48. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.svg +0 -1831
  49. package/docs/template/edx/static/fonts/OpenSans-Light-webfont.woff +0 -0
  50. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  51. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  52. package/docs/template/edx/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  53. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.eot +0 -0
  54. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.svg +0 -1831
  55. package/docs/template/edx/static/fonts/OpenSans-Regular-webfont.woff +0 -0
  56. package/docs/template/edx/static/scripts/linenumber.js +0 -25
  57. package/docs/template/edx/static/scripts/prettify/Apache-License-2.0.txt +0 -202
  58. package/docs/template/edx/static/scripts/prettify/lang-css.js +0 -2
  59. package/docs/template/edx/static/scripts/prettify/prettify.js +0 -28
  60. package/docs/template/edx/static/styles/jsdoc-default.css +0 -356
  61. package/docs/template/edx/static/styles/prettify-jsdoc.css +0 -111
  62. package/docs/template/edx/static/styles/prettify-tomorrow.css +0 -132
  63. package/docs/template/edx/tmpl/augments.tmpl +0 -10
  64. package/docs/template/edx/tmpl/container.tmpl +0 -196
  65. package/docs/template/edx/tmpl/details.tmpl +0 -143
  66. package/docs/template/edx/tmpl/example.tmpl +0 -2
  67. package/docs/template/edx/tmpl/examples.tmpl +0 -13
  68. package/docs/template/edx/tmpl/exceptions.tmpl +0 -32
  69. package/docs/template/edx/tmpl/layout.tmpl +0 -39
  70. package/docs/template/edx/tmpl/mainpage.tmpl +0 -10
  71. package/docs/template/edx/tmpl/members.tmpl +0 -38
  72. package/docs/template/edx/tmpl/method.tmpl +0 -131
  73. package/docs/template/edx/tmpl/modifies.tmpl +0 -14
  74. package/docs/template/edx/tmpl/params.tmpl +0 -131
  75. package/docs/template/edx/tmpl/properties.tmpl +0 -108
  76. package/docs/template/edx/tmpl/returns.tmpl +0 -19
  77. package/docs/template/edx/tmpl/source.tmpl +0 -8
  78. package/docs/template/edx/tmpl/tutorial.tmpl +0 -19
  79. package/docs/template/edx/tmpl/type.tmpl +0 -7
  80. package/env.config.js +0 -8
  81. package/jsdoc.json +0 -36
  82. package/openedx.yaml +0 -12
  83. package/service-interface.png +0 -0
  84. package/src/analytics/MockAnalyticsService.js +0 -71
  85. package/src/analytics/SegmentAnalyticsService.js +0 -243
  86. package/src/analytics/index.js +0 -12
  87. package/src/analytics/interface.js +0 -142
  88. package/src/auth/AxiosCsrfTokenService.js +0 -60
  89. package/src/auth/AxiosJwtAuthService.js +0 -364
  90. package/src/auth/AxiosJwtTokenService.js +0 -134
  91. package/src/auth/LocalForageCache.js +0 -78
  92. package/src/auth/MockAuthService.js +0 -285
  93. package/src/auth/index.js +0 -19
  94. package/src/auth/interceptors/createCsrfTokenProviderInterceptor.js +0 -37
  95. package/src/auth/interceptors/createJwtTokenProviderInterceptor.js +0 -38
  96. package/src/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js +0 -20
  97. package/src/auth/interceptors/createRetryInterceptor.js +0 -72
  98. package/src/auth/interface.js +0 -309
  99. package/src/auth/utils.js +0 -105
  100. package/src/config.js +0 -327
  101. package/src/constants.js +0 -66
  102. package/src/i18n/countries.js +0 -57
  103. package/src/i18n/index.js +0 -123
  104. package/src/i18n/injectIntlWithShim.jsx +0 -45
  105. package/src/i18n/languages.js +0 -60
  106. package/src/i18n/lib.js +0 -282
  107. package/src/i18n/scripts/README.md +0 -29
  108. package/src/i18n/scripts/intl-imports.js +0 -259
  109. package/src/i18n/scripts/transifex-utils.js +0 -75
  110. package/src/index.js +0 -42
  111. package/src/initialize.js +0 -357
  112. package/src/logging/MockLoggingService.js +0 -31
  113. package/src/logging/NewRelicLoggingService.js +0 -181
  114. package/src/logging/index.js +0 -9
  115. package/src/logging/interface.js +0 -110
  116. package/src/pubSub.js +0 -47
  117. package/src/react/AppContext.jsx +0 -24
  118. package/src/react/AppProvider.jsx +0 -93
  119. package/src/react/AuthenticatedPageRoute.jsx +0 -60
  120. package/src/react/ErrorBoundary.jsx +0 -44
  121. package/src/react/ErrorPage.jsx +0 -76
  122. package/src/react/LoginRedirect.jsx +0 -16
  123. package/src/react/OptionalReduxProvider.jsx +0 -28
  124. package/src/react/PageRoute.jsx +0 -31
  125. package/src/react/hooks.js +0 -50
  126. package/src/react/index.js +0 -16
  127. package/src/scripts/GoogleAnalyticsLoader.js +0 -53
  128. package/src/scripts/index.js +0 -2
  129. package/src/testing/index.js +0 -9
  130. package/src/testing/initializeMockApp.js +0 -77
  131. package/src/testing/mockMessages.js +0 -21
  132. package/src/utils.js +0 -167
  133. /package/{dist/analytics → analytics}/MockAnalyticsService.js +0 -0
  134. /package/{dist/analytics → analytics}/MockAnalyticsService.js.map +0 -0
  135. /package/{dist/analytics → analytics}/SegmentAnalyticsService.js +0 -0
  136. /package/{dist/analytics → analytics}/SegmentAnalyticsService.js.map +0 -0
  137. /package/{dist/analytics → analytics}/index.js +0 -0
  138. /package/{dist/analytics → analytics}/index.js.map +0 -0
  139. /package/{dist/analytics → analytics}/interface.js +0 -0
  140. /package/{dist/analytics → analytics}/interface.js.map +0 -0
  141. /package/{dist/auth → auth}/AxiosCsrfTokenService.js +0 -0
  142. /package/{dist/auth → auth}/AxiosCsrfTokenService.js.map +0 -0
  143. /package/{dist/auth → auth}/AxiosJwtAuthService.js +0 -0
  144. /package/{dist/auth → auth}/AxiosJwtAuthService.js.map +0 -0
  145. /package/{dist/auth → auth}/AxiosJwtTokenService.js +0 -0
  146. /package/{dist/auth → auth}/AxiosJwtTokenService.js.map +0 -0
  147. /package/{dist/auth → auth}/LocalForageCache.js +0 -0
  148. /package/{dist/auth → auth}/LocalForageCache.js.map +0 -0
  149. /package/{dist/auth → auth}/MockAuthService.js +0 -0
  150. /package/{dist/auth → auth}/MockAuthService.js.map +0 -0
  151. /package/{dist/auth → auth}/index.js +0 -0
  152. /package/{dist/auth → auth}/index.js.map +0 -0
  153. /package/{dist/auth → auth}/interceptors/createCsrfTokenProviderInterceptor.js +0 -0
  154. /package/{dist/auth → auth}/interceptors/createCsrfTokenProviderInterceptor.js.map +0 -0
  155. /package/{dist/auth → auth}/interceptors/createJwtTokenProviderInterceptor.js +0 -0
  156. /package/{dist/auth → auth}/interceptors/createJwtTokenProviderInterceptor.js.map +0 -0
  157. /package/{dist/auth → auth}/interceptors/createProcessAxiosRequestErrorInterceptor.js +0 -0
  158. /package/{dist/auth → auth}/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +0 -0
  159. /package/{dist/auth → auth}/interceptors/createRetryInterceptor.js +0 -0
  160. /package/{dist/auth → auth}/interceptors/createRetryInterceptor.js.map +0 -0
  161. /package/{dist/auth → auth}/interface.js +0 -0
  162. /package/{dist/auth → auth}/interface.js.map +0 -0
  163. /package/{dist/auth → auth}/utils.js +0 -0
  164. /package/{dist/auth → auth}/utils.js.map +0 -0
  165. /package/{dist/config.js → config.js} +0 -0
  166. /package/{dist/config.js.map → config.js.map} +0 -0
  167. /package/{dist/constants.js → constants.js} +0 -0
  168. /package/{dist/constants.js.map → constants.js.map} +0 -0
  169. /package/{dist/i18n → i18n}/countries.js +0 -0
  170. /package/{dist/i18n → i18n}/countries.js.map +0 -0
  171. /package/{dist/i18n → i18n}/index.js +0 -0
  172. /package/{dist/i18n → i18n}/index.js.map +0 -0
  173. /package/{dist/i18n → i18n}/injectIntlWithShim.js +0 -0
  174. /package/{dist/i18n → i18n}/injectIntlWithShim.js.map +0 -0
  175. /package/{dist/i18n → i18n}/languages.js +0 -0
  176. /package/{dist/i18n → i18n}/languages.js.map +0 -0
  177. /package/{dist/i18n → i18n}/lib.js +0 -0
  178. /package/{dist/i18n → i18n}/lib.js.map +0 -0
  179. /package/{dist/i18n → i18n}/scripts/README.md +0 -0
  180. /package/{dist/i18n → i18n}/scripts/intl-imports.js +0 -0
  181. /package/{dist/i18n → i18n}/scripts/intl-imports.js.map +0 -0
  182. /package/{dist/i18n → i18n}/scripts/transifex-utils.js +0 -0
  183. /package/{dist/i18n → i18n}/scripts/transifex-utils.js.map +0 -0
  184. /package/{dist/index.js → index.js} +0 -0
  185. /package/{dist/index.js.map → index.js.map} +0 -0
  186. /package/{dist/initialize.js → initialize.js} +0 -0
  187. /package/{dist/initialize.js.map → initialize.js.map} +0 -0
  188. /package/{dist/logging → logging}/MockLoggingService.js +0 -0
  189. /package/{dist/logging → logging}/MockLoggingService.js.map +0 -0
  190. /package/{dist/logging → logging}/NewRelicLoggingService.js +0 -0
  191. /package/{dist/logging → logging}/NewRelicLoggingService.js.map +0 -0
  192. /package/{dist/logging → logging}/index.js +0 -0
  193. /package/{dist/logging → logging}/index.js.map +0 -0
  194. /package/{dist/logging → logging}/interface.js +0 -0
  195. /package/{dist/logging → logging}/interface.js.map +0 -0
  196. /package/{dist/pubSub.js → pubSub.js} +0 -0
  197. /package/{dist/pubSub.js.map → pubSub.js.map} +0 -0
  198. /package/{dist/react → react}/AppContext.js +0 -0
  199. /package/{dist/react → react}/AppContext.js.map +0 -0
  200. /package/{dist/react → react}/AppProvider.js +0 -0
  201. /package/{dist/react → react}/AppProvider.js.map +0 -0
  202. /package/{dist/react → react}/AuthenticatedPageRoute.js +0 -0
  203. /package/{dist/react → react}/AuthenticatedPageRoute.js.map +0 -0
  204. /package/{dist/react → react}/ErrorBoundary.js +0 -0
  205. /package/{dist/react → react}/ErrorBoundary.js.map +0 -0
  206. /package/{dist/react → react}/ErrorPage.js +0 -0
  207. /package/{dist/react → react}/ErrorPage.js.map +0 -0
  208. /package/{dist/react → react}/LoginRedirect.js +0 -0
  209. /package/{dist/react → react}/LoginRedirect.js.map +0 -0
  210. /package/{dist/react → react}/OptionalReduxProvider.js +0 -0
  211. /package/{dist/react → react}/OptionalReduxProvider.js.map +0 -0
  212. /package/{dist/react → react}/PageRoute.js +0 -0
  213. /package/{dist/react → react}/PageRoute.js.map +0 -0
  214. /package/{dist/react → react}/hooks.js +0 -0
  215. /package/{dist/react → react}/hooks.js.map +0 -0
  216. /package/{dist/react → react}/index.js +0 -0
  217. /package/{dist/react → react}/index.js.map +0 -0
  218. /package/{dist/scripts → scripts}/GoogleAnalyticsLoader.js +0 -0
  219. /package/{dist/scripts → scripts}/GoogleAnalyticsLoader.js.map +0 -0
  220. /package/{dist/scripts → scripts}/index.js +0 -0
  221. /package/{dist/scripts → scripts}/index.js.map +0 -0
  222. /package/{dist/testing → testing}/index.js +0 -0
  223. /package/{dist/testing → testing}/index.js.map +0 -0
  224. /package/{dist/testing → testing}/initializeMockApp.js +0 -0
  225. /package/{dist/testing → testing}/initializeMockApp.js.map +0 -0
  226. /package/{dist/testing → testing}/mockMessages.js +0 -0
  227. /package/{dist/testing → testing}/mockMessages.js.map +0 -0
  228. /package/{dist/utils.js → utils.js} +0 -0
  229. /package/{dist/utils.js.map → utils.js.map} +0 -0
@@ -1,713 +0,0 @@
1
- const doop = require('jsdoc/util/doop');
2
- const env = require('jsdoc/env');
3
- const fs = require('jsdoc/fs');
4
- const helper = require('jsdoc/util/templateHelper');
5
- const logger = require('jsdoc/util/logger');
6
- const path = require('jsdoc/path');
7
- const template = require('jsdoc/template');
8
- const util = require('util');
9
-
10
- const htmlsafe = helper.htmlsafe;
11
- const linkto = helper.linkto;
12
- const resolveAuthorLinks = helper.resolveAuthorLinks;
13
- const hasOwnProp = Object.prototype.hasOwnProperty;
14
-
15
- let data;
16
- let view;
17
-
18
- let outdir = path.normalize(env.opts.destination);
19
-
20
- function find(spec) {
21
- return helper.find(data, spec);
22
- }
23
-
24
- function tutoriallink(tutorial) {
25
- return helper.toTutorial(tutorial, null, {
26
- tag: 'em',
27
- classname: 'disabled',
28
- prefix: 'Tutorial: '
29
- });
30
- }
31
-
32
- function getAncestorLinks(doclet) {
33
- return helper.getAncestorLinks(data, doclet);
34
- }
35
-
36
- function hashToLink(doclet, hash) {
37
- let url;
38
-
39
- if ( !/^(#.+)/.test(hash) ) {
40
- return hash;
41
- }
42
-
43
- url = helper.createLink(doclet);
44
- url = url.replace(/(#.+|$)/, hash);
45
-
46
- return `<a href="${url}">${hash}</a>`;
47
- }
48
-
49
- function needsSignature({kind, type, meta}) {
50
- let needsSig = false;
51
-
52
- // function and class definitions always get a signature
53
- if (kind === 'function' || kind === 'class') {
54
- needsSig = true;
55
- }
56
- // typedefs that contain functions get a signature, too
57
- else if (kind === 'typedef' && type && type.names &&
58
- type.names.length) {
59
- for (let i = 0, l = type.names.length; i < l; i++) {
60
- if (type.names[i].toLowerCase() === 'function') {
61
- needsSig = true;
62
- break;
63
- }
64
- }
65
- }
66
- // and namespaces that are functions get a signature (but finding them is a
67
- // bit messy)
68
- else if (kind === 'namespace' && meta && meta.code &&
69
- meta.code.type && meta.code.type.match(/[Ff]unction/)) {
70
- needsSig = true;
71
- }
72
-
73
- return needsSig;
74
- }
75
-
76
- function getSignatureAttributes({optional, nullable}) {
77
- const attributes = [];
78
-
79
- if (optional) {
80
- attributes.push('opt');
81
- }
82
-
83
- if (nullable === true) {
84
- attributes.push('nullable');
85
- }
86
- else if (nullable === false) {
87
- attributes.push('non-null');
88
- }
89
-
90
- return attributes;
91
- }
92
-
93
- function updateItemName(item) {
94
- const attributes = getSignatureAttributes(item);
95
- let itemName = item.name || '';
96
-
97
- if (item.variable) {
98
- itemName = `&hellip;${itemName}`;
99
- }
100
-
101
- if (attributes && attributes.length) {
102
- itemName = util.format( '%s<span class="signature-attributes">%s</span>', itemName,
103
- attributes.join(', ') );
104
- }
105
-
106
- return itemName;
107
- }
108
-
109
- function addParamAttributes(params) {
110
- return params.filter(({name}) => name && !name.includes('.')).map(updateItemName);
111
- }
112
-
113
- function buildItemTypeStrings(item) {
114
- const types = [];
115
-
116
- if (item && item.type && item.type.names) {
117
- item.type.names.forEach(name => {
118
- types.push( linkto(name, htmlsafe(name)) );
119
- });
120
- }
121
-
122
- return types;
123
- }
124
-
125
- function buildAttribsString(attribs) {
126
- let attribsString = '';
127
-
128
- if (attribs && attribs.length) {
129
- attribsString = htmlsafe( util.format('(%s) ', attribs.join(', ')) );
130
- }
131
-
132
- return attribsString;
133
- }
134
-
135
- function addNonParamAttributes(items) {
136
- let types = [];
137
-
138
- items.forEach(item => {
139
- types = types.concat( buildItemTypeStrings(item) );
140
- });
141
-
142
- return types;
143
- }
144
-
145
- function addSignatureParams(f) {
146
- const params = f.params ? addParamAttributes(f.params) : [];
147
-
148
- f.signature = util.format( '%s(%s)', (f.signature || ''), params.join(', ') );
149
- }
150
-
151
- function addSignatureReturns(f) {
152
- const attribs = [];
153
- let attribsString = '';
154
- let returnTypes = [];
155
- let returnTypesString = '';
156
- const source = f.yields || f.returns;
157
-
158
- // jam all the return-type attributes into an array. this could create odd results (for example,
159
- // if there are both nullable and non-nullable return types), but let's assume that most people
160
- // who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
161
- if (source) {
162
- source.forEach(item => {
163
- helper.getAttribs(item).forEach(attrib => {
164
- if (!attribs.includes(attrib)) {
165
- attribs.push(attrib);
166
- }
167
- });
168
- });
169
-
170
- attribsString = buildAttribsString(attribs);
171
- }
172
-
173
- if (source) {
174
- returnTypes = addNonParamAttributes(source);
175
- }
176
- if (returnTypes.length) {
177
- returnTypesString = util.format( ' &rarr; %s{%s}', attribsString, returnTypes.join('|') );
178
- }
179
-
180
- f.signature = `<span class="signature">${f.signature || ''}</span><span class="type-signature">${returnTypesString}</span>`;
181
- }
182
-
183
- function addSignatureTypes(f) {
184
- const types = f.type ? buildItemTypeStrings(f) : [];
185
-
186
- f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` :${types.join('|')}` : ''}</span>`;
187
- }
188
-
189
- function addAttribs(f) {
190
- const attribs = helper.getAttribs(f);
191
- const attribsString = buildAttribsString(attribs);
192
-
193
- f.attribs = util.format('<span class="type-signature">%s</span>', attribsString);
194
- }
195
-
196
- function shortenPaths(files, commonPrefix) {
197
- Object.keys(files).forEach(file => {
198
- files[file].shortened = files[file].resolved.replace(commonPrefix, '')
199
- // always use forward slashes
200
- .replace(/\\/g, '/');
201
- });
202
-
203
- return files;
204
- }
205
-
206
- function getPathFromDoclet({meta}) {
207
- if (!meta) {
208
- return null;
209
- }
210
-
211
- return meta.path && meta.path !== 'null' ?
212
- path.join(meta.path, meta.filename) :
213
- meta.filename;
214
- }
215
-
216
- function generate(title, docs, filename, { resolveLinks = false, moduleName = '' } = {}) {
217
- let docData;
218
- let html;
219
- let outpath;
220
- resolveLinks = resolveLinks !== false;
221
-
222
- docData = {
223
- env: env,
224
- title: title,
225
- docs: docs,
226
- moduleName,
227
- };
228
-
229
- outpath = path.join(outdir, filename);
230
- html = view.render('container.tmpl', docData);
231
-
232
- if (resolveLinks) {
233
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
234
- }
235
-
236
- fs.writeFileSync(outpath, html, 'utf8');
237
- }
238
-
239
- function generateSourceFiles(sourceFiles, encoding = 'utf8') {
240
- Object.keys(sourceFiles).forEach(file => {
241
- let source;
242
- // links are keyed to the shortened path in each doclet's `meta.shortpath` property
243
- const sourceOutfile = helper.getUniqueFilename(sourceFiles[file].shortened);
244
-
245
- helper.registerLink(sourceFiles[file].shortened, sourceOutfile);
246
-
247
- try {
248
- source = {
249
- kind: 'source',
250
- code: helper.htmlsafe( fs.readFileSync(sourceFiles[file].resolved, encoding) )
251
- };
252
- }
253
- catch (e) {
254
- logger.error('Error while generating source file %s: %s', file, e.message);
255
- }
256
-
257
- generate(`Source: ${sourceFiles[file].shortened}`, [source], sourceOutfile);
258
- });
259
- }
260
-
261
- /**
262
- * Look for classes or functions with the same name as modules (which indicates that the module
263
- * exports only that class or function), then attach the classes or functions to the `module`
264
- * property of the appropriate module doclets. The name of each class or function is also updated
265
- * for display purposes. This function mutates the original arrays.
266
- *
267
- * @private
268
- * @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
269
- * check.
270
- * @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
271
- */
272
- function attachModuleSymbols(doclets, modules) {
273
- const symbols = {};
274
-
275
- // build a lookup table
276
- doclets.forEach(symbol => {
277
- symbols[symbol.longname] = symbols[symbol.longname] || [];
278
- symbols[symbol.longname].push(symbol);
279
- });
280
-
281
- modules.forEach(module => {
282
- if (symbols[module.longname]) {
283
- module.modules = symbols[module.longname]
284
- // Only show symbols that have a description. Make an exception for classes, because
285
- // we want to show the constructor-signature heading no matter what.
286
- .filter(({description, kind}) => description || kind === 'class')
287
- .map(symbol => {
288
- symbol = doop(symbol);
289
-
290
- if (symbol.kind === 'class' || symbol.kind === 'function') {
291
- symbol.name = `${symbol.name.replace('module:', '(require("')}"))`;
292
- }
293
-
294
- return symbol;
295
- });
296
- }
297
- });
298
- }
299
-
300
- function buildMemberNav(items, itemHeading, itemsSeen, linktoFn) {
301
- let nav = '';
302
-
303
- const renderSubNav = (doclets => {
304
- if (!doclets || !doclets.length) return '';
305
-
306
- const renderChild = (doclet) => {
307
- return `<li>${linktoFn(doclet.longname, doclet.name)}</li>`;
308
- }
309
-
310
- return `
311
- <ul class="list-unstyled px-3 pb-4 bg-light">
312
- ${doclets.map(renderChild).join('')}
313
- </ul>
314
- `;
315
- });
316
-
317
- if (items.length) {
318
- let itemsNav = '';
319
-
320
- items.forEach(item => {
321
- let displayName;
322
-
323
- if ( !hasOwnProp.call(item, 'longname') ) {
324
- itemsNav += `<li class="nav-item">${linktoFn('', item.name, 'nav-link')}</li>`;
325
- }
326
- else if ( !hasOwnProp.call(itemsSeen, item.longname) ) {
327
- if (env.conf.templates.default.useLongnameInNav) {
328
- displayName = item.longname;
329
- } else {
330
- displayName = item.name;
331
- }
332
-
333
- itemsNav += `<li class="module-section nav-item ${displayName}">
334
- ${linktoFn(item.longname, displayName.replace(/\b(module|event):/g), 'nav-link font-weight-bold')}
335
- ${renderSubNav(item.children)}
336
- </li>`;
337
-
338
- itemsSeen[item.longname] = true;
339
- }
340
- });
341
-
342
- if (itemsNav !== '') {
343
- nav += `<ul class="list-unstyled nav flex-column">${itemsNav}</ul>`;
344
- }
345
- }
346
-
347
- return nav;
348
- }
349
-
350
- function linktoTutorial(longName, name) {
351
- return tutoriallink(name);
352
- }
353
-
354
- function linktoExternal(longName, name) {
355
- return linkto(longName, name.replace(/(^"|"$)/g, ''));
356
- }
357
-
358
- /**
359
- * Create the navigation sidebar.
360
- * @param {object} members The members that will be used to create the sidebar.
361
- * @param {array<object>} members.classes
362
- * @param {array<object>} members.externals
363
- * @param {array<object>} members.globals
364
- * @param {array<object>} members.mixins
365
- * @param {array<object>} members.modules
366
- * @param {array<object>} members.namespaces
367
- * @param {array<object>} members.tutorials
368
- * @param {array<object>} members.events
369
- * @param {array<object>} members.interfaces
370
- * @return {string} The HTML for the navigation sidebar.
371
- */
372
- function buildNav(members) {
373
- let globalNav;
374
- let nav = '<h2><a href="index.html">Home</a></h2>';
375
- const seen = {};
376
- const seenTutorials = {};
377
-
378
- nav += buildMemberNav(members.modules, 'Modules', {}, linkto);
379
- // nav += buildMemberNav(members.externals, 'Externals', seen, linktoExternal);
380
- // nav += buildMemberNav(members.namespaces, 'Namespaces', seen, linkto);
381
- // nav += buildMemberNav(members.classes, 'Classes', seen, linkto);
382
- // nav += buildMemberNav(members.interfaces, 'Interfaces', seen, linkto);
383
- // nav += buildMemberNav(members.events, 'Events', seen, linkto);
384
- // nav += buildMemberNav(members.mixins, 'Mixins', seen, linkto);
385
- // nav += buildMemberNav(members.tutorials, 'Tutorials', seenTutorials, linktoTutorial);
386
-
387
- // if (members.globals.length) {
388
- // globalNav = '';
389
-
390
- // members.globals.forEach(({kind, longname, name}) => {
391
- // if ( kind !== 'typedef' && !hasOwnProp.call(seen, longname) ) {
392
- // globalNav += `<li>${linkto(longname, name)}</li>`;
393
- // }
394
- // seen[longname] = true;
395
- // });
396
-
397
- // if (!globalNav) {
398
- // // turn the heading into a link so you can actually get to the global page
399
- // nav += `<h3>${linkto('global', 'Global')}</h3>`;
400
- // }
401
- // else {
402
- // nav += `<h3>Global</h3><ul>${globalNav}</ul>`;
403
- // }
404
- // }
405
-
406
- return nav;
407
- }
408
-
409
- /**
410
- @param {object} memberData
411
- @param {object} opts
412
- @param {Tutorial} tutorials
413
- */
414
- exports.publish = (memberData, opts, tutorials) => {
415
- let classes;
416
- let conf;
417
- let externals;
418
- let files;
419
- let fromDir;
420
- let globalUrl;
421
- let indexUrl;
422
- let interfaces;
423
- let members;
424
- let mixins;
425
- let modules;
426
- let namespaces;
427
- let outputSourceFiles;
428
- let packageInfo;
429
- let packages;
430
- const sourceFilePaths = [];
431
- let sourceFiles = {};
432
- let staticFileFilter;
433
- let staticFilePaths;
434
- let staticFiles;
435
- let staticFileScanner;
436
- let templatePath;
437
-
438
- data = memberData;
439
-
440
- conf = env.conf.templates || {};
441
- conf.default = conf.default || {};
442
-
443
- templatePath = path.normalize(opts.template);
444
- view = new template.Template( path.join(templatePath, 'tmpl') );
445
-
446
- // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
447
- // doesn't try to hand them out later
448
- indexUrl = helper.getUniqueFilename('index');
449
- // don't call registerLink() on this one! 'index' is also a valid longname
450
-
451
- globalUrl = helper.getUniqueFilename('global');
452
- helper.registerLink('global', globalUrl);
453
-
454
- // set up templating
455
- view.layout = conf.default.layoutFile ?
456
- path.getResourcePath(path.dirname(conf.default.layoutFile),
457
- path.basename(conf.default.layoutFile) ) :
458
- 'layout.tmpl';
459
-
460
- // set up tutorials for helper
461
- helper.setTutorials(tutorials);
462
-
463
- data = helper.prune(data);
464
- data.sort('longname, version, since');
465
- helper.addEventListeners(data);
466
-
467
- data().each(doclet => {
468
- let sourcePath;
469
-
470
- doclet.attribs = '';
471
-
472
- if (doclet.examples) {
473
- doclet.examples = doclet.examples.map(example => {
474
- let caption;
475
- let code;
476
-
477
- if (example.match(/^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i)) {
478
- caption = RegExp.$1;
479
- code = RegExp.$3;
480
- }
481
-
482
- return {
483
- caption: caption || '',
484
- code: code || example
485
- };
486
- });
487
- }
488
- if (doclet.see) {
489
- doclet.see.forEach((seeItem, i) => {
490
- doclet.see[i] = hashToLink(doclet, seeItem);
491
- });
492
- }
493
-
494
- // build a list of source files
495
- if (doclet.meta) {
496
- sourcePath = getPathFromDoclet(doclet);
497
- sourceFiles[sourcePath] = {
498
- resolved: sourcePath,
499
- shortened: null
500
- };
501
- if (!sourceFilePaths.includes(sourcePath)) {
502
- sourceFilePaths.push(sourcePath);
503
- }
504
- }
505
- });
506
-
507
- // update outdir if necessary, then create outdir
508
- packageInfo = ( find({kind: 'package'}) || [] )[0];
509
- if (packageInfo && packageInfo.name) {
510
- outdir = path.join( outdir, packageInfo.name, (packageInfo.version || '') );
511
- }
512
- fs.mkPath(outdir);
513
-
514
- // copy the template's static files to outdir
515
- fromDir = path.join(templatePath, 'static');
516
- staticFiles = fs.ls(fromDir, 3);
517
-
518
- staticFiles.forEach(fileName => {
519
- const toDir = fs.toDir( fileName.replace(fromDir, outdir) );
520
-
521
- fs.mkPath(toDir);
522
- fs.copyFileSync(fileName, toDir);
523
- });
524
-
525
- // copy user-specified static files to outdir
526
- if (conf.default.staticFiles) {
527
- // The canonical property name is `include`. We accept `paths` for backwards compatibility
528
- // with a bug in JSDoc 3.2.x.
529
- staticFilePaths = conf.default.staticFiles.include ||
530
- conf.default.staticFiles.paths ||
531
- [];
532
- staticFileFilter = new (require('jsdoc/src/filter').Filter)(conf.default.staticFiles);
533
- staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
534
-
535
- staticFilePaths.forEach(filePath => {
536
- let extraStaticFiles;
537
-
538
- filePath = path.resolve(env.pwd, filePath);
539
- extraStaticFiles = staticFileScanner.scan([filePath], 10, staticFileFilter);
540
-
541
- extraStaticFiles.forEach(fileName => {
542
- const sourcePath = fs.toDir(filePath);
543
- const toDir = fs.toDir( fileName.replace(sourcePath, outdir) );
544
-
545
- fs.mkPath(toDir);
546
- fs.copyFileSync(fileName, toDir);
547
- });
548
- });
549
- }
550
-
551
- if (sourceFilePaths.length) {
552
- sourceFiles = shortenPaths( sourceFiles, path.commonPrefix(sourceFilePaths) );
553
- }
554
- data().each(doclet => {
555
- let docletPath;
556
- const url = helper.createLink(doclet);
557
-
558
- helper.registerLink(doclet.longname, url);
559
-
560
- // add a shortened version of the full path
561
- if (doclet.meta) {
562
- docletPath = getPathFromDoclet(doclet);
563
- docletPath = sourceFiles[docletPath].shortened;
564
- if (docletPath) {
565
- doclet.meta.shortpath = docletPath;
566
- }
567
- }
568
- });
569
-
570
- data().each(doclet => {
571
- const url = helper.longnameToUrl[doclet.longname];
572
-
573
- if (url.includes('#')) {
574
- doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
575
- }
576
- else {
577
- doclet.id = doclet.name;
578
- }
579
-
580
- if ( needsSignature(doclet) ) {
581
- addSignatureParams(doclet);
582
- addSignatureReturns(doclet);
583
- addAttribs(doclet);
584
- }
585
- });
586
-
587
- // do this after the urls have all been generated
588
- data().each(doclet => {
589
- doclet.ancestors = getAncestorLinks(doclet);
590
-
591
- if (doclet.kind === 'member') {
592
- addSignatureTypes(doclet);
593
- addAttribs(doclet);
594
- }
595
-
596
- if (doclet.kind === 'constant') {
597
- addSignatureTypes(doclet);
598
- addAttribs(doclet);
599
- doclet.kind = 'member';
600
- }
601
- });
602
-
603
- members = helper.getMembers(data);
604
-
605
- members.modules = members.modules.map(module => {
606
- module.children = data({ memberof: `module:${module.name}`}).get();
607
- return module;
608
- })
609
-
610
- members.tutorials = tutorials.children;
611
-
612
- // output pretty-printed source files by default
613
- outputSourceFiles = conf.default && conf.default.outputSourceFiles !== false;
614
-
615
- // add template helpers
616
- view.find = find;
617
- view.linkto = linkto;
618
- view.resolveAuthorLinks = resolveAuthorLinks;
619
- view.tutoriallink = tutoriallink;
620
- view.htmlsafe = htmlsafe;
621
- view.outputSourceFiles = outputSourceFiles;
622
-
623
- // once for all
624
- view.nav = buildNav(members);
625
- attachModuleSymbols( find({ longname: {left: 'module:'} }), members.modules );
626
-
627
- // generate the pretty-printed source files first so other pages can link to them
628
- if (outputSourceFiles) {
629
- generateSourceFiles(sourceFiles, opts.encoding);
630
- }
631
-
632
- // if (members.globals.length) { generate('Global', [{kind: 'globalobj'}], globalUrl); }
633
-
634
- // index page displays information from package.json and lists files
635
- files = find({kind: 'file'});
636
- packages = find({kind: 'package'});
637
-
638
- generate('Open edX frontend-platform API Documentation',
639
- packages.concat(
640
- [{
641
- kind: 'mainpage',
642
- readme: opts.readme,
643
- longname: (opts.mainpagetitle) ? opts.mainpagetitle : 'Main Page'
644
- }]
645
- ).concat(files), indexUrl);
646
-
647
- Object.keys(helper.longnameToUrl).forEach(longname => {
648
- const myClasses = members.classes.filter(obj => obj.longname === longname);
649
- const myExternals = members.externals.filter(obj => obj.longname === longname);
650
- const myInterfaces = members.interfaces.filter(obj => obj.longname === longname);
651
- const myMixins = members.mixins.filter(obj => obj.longname === longname);
652
- const myModules = members.modules.filter(obj => obj.longname === longname);
653
- const myNamespaces = members.namespaces.filter(obj => obj.longname === longname);
654
-
655
- const trimModuleName = (moduleName) => {
656
- if (moduleName.includes('module:')) {
657
- return moduleName.split(':')[1];
658
- }
659
- return moduleName;
660
- }
661
-
662
- if (myModules.length) {
663
- generate(`${myModules[0].name}`, myModules, helper.longnameToUrl[longname], { moduleName: myModules[0].name });
664
- }
665
-
666
- if (myClasses.length) {
667
- generate(`Class: ${myClasses[0].name}`, myClasses, helper.longnameToUrl[longname], { moduleName: trimModuleName(myClasses[0].memberof) });
668
- }
669
-
670
- if (myNamespaces.length) {
671
- generate(`Namespace: ${myNamespaces[0].name}`, myNamespaces, helper.longnameToUrl[longname], { moduleName: trimModuleName(myNamespaces[0].memberof) });
672
- }
673
-
674
- if (myMixins.length) {
675
- generate(`Mixin: ${myMixins[0].name}`, myMixins, helper.longnameToUrl[longname], { moduleName: trimModuleName(myMixins[0].memberof) });
676
- }
677
-
678
- if (myExternals.length) {
679
- generate(`External: ${myExternals[0].name}`, myExternals, helper.longnameToUrl[longname], { moduleName: trimModuleName(myExternals[0].memberof) });
680
- }
681
-
682
- if (myInterfaces.length) {
683
- generate(`Interface: ${myInterfaces[0].name}`, myInterfaces, helper.longnameToUrl[longname], { moduleName: trimModuleName(myInterfaces[0].memberof) });
684
- }
685
- });
686
-
687
- // TODO: move the tutorial functions to templateHelper.js
688
- function generateTutorial(title, tutorial, filename) {
689
- const tutorialData = {
690
- title: title,
691
- header: tutorial.title,
692
- content: tutorial.parse(),
693
- children: tutorial.children
694
- };
695
- const tutorialPath = path.join(outdir, filename);
696
- let html = view.render('tutorial.tmpl', tutorialData);
697
-
698
- // yes, you can use {@link} in tutorials too!
699
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
700
-
701
- fs.writeFileSync(tutorialPath, html, 'utf8');
702
- }
703
-
704
- // tutorials can have only one parent so there is no risk for loops
705
- function saveChildren({children}) {
706
- children.forEach(child => {
707
- generateTutorial(`Tutorial: ${child.title}`, child, helper.tutorialToUrl(child.name));
708
- saveChildren(child);
709
- });
710
- }
711
-
712
- saveChildren(tutorials);
713
- };