@ng-doc/keywords-loaders 17.6.15 → 18.0.0-beta.1

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.
@@ -0,0 +1,8 @@
1
+ import { NgVersion } from '../types';
2
+ /**
3
+ *
4
+ * @param packageName
5
+ * @param pageName
6
+ * @param version
7
+ */
8
+ export declare function getApiUrl(packageName: string, pageName: string, version?: NgVersion): string;
@@ -3,7 +3,8 @@ import { NgPage } from '../interfaces';
3
3
  import { NgVersion } from '../types';
4
4
  /**
5
5
  *
6
+ * @param packageName
6
7
  * @param page
7
8
  * @param version
8
9
  */
9
- export declare function ngPageToKeyword(page: NgPage, version?: NgVersion): Array<[string, NgDocGlobalKeyword]>;
10
+ export declare function ngPageToKeyword(packageName: string, page: NgPage, version?: NgVersion): Array<[string, NgDocGlobalKeyword]>;
@@ -1,6 +1,6 @@
1
1
  import { NgApiPageType } from '../types';
2
2
  export interface NgPage {
3
- title: string;
4
- path: string;
3
+ name: string;
5
4
  type: NgApiPageType;
5
+ isDeprecated?: boolean;
6
6
  }
@@ -1,4 +1,4 @@
1
1
  import { NgPage } from './ng-page';
2
2
  export interface NgResponse {
3
- pages: NgPage[];
3
+ [packageName: string]: NgPage[];
4
4
  }
@@ -1,2 +1 @@
1
- import { ngApiPageTypes, ngPageTypes } from '../constants';
2
- export type NgApiPageType = typeof ngPageTypes[number] | typeof ngApiPageTypes[number];
1
+ export type NgApiPageType = 'block' | 'undecorated_class' | 'constant' | 'decorator' | 'directive' | 'element' | 'enum' | 'function' | 'interface' | 'pipe' | 'ng_module' | 'type_alias' | 'initializer_api_function';
package/index.cjs.js CHANGED
@@ -2,15 +2,13 @@
2
2
 
3
3
  var fetch = require('node-fetch');
4
4
 
5
- const ngApiPageTypes = ['class', 'interface', 'function', 'type-alias', 'enum', 'const', 'ngmodule', 'directive', 'pipe', 'decorator'];
6
-
7
5
  /**
8
6
  *
9
7
  * @param version
10
8
  */
11
9
  function getNgHost(version) {
12
10
  const versionEndpoint = version ? `${version}.` : '';
13
- return `https://${versionEndpoint}angular.io`;
11
+ return `https://${versionEndpoint}angular.dev`;
14
12
  }
15
13
 
16
14
  /**
@@ -18,40 +16,43 @@ function getNgHost(version) {
18
16
  * @param version
19
17
  */
20
18
  async function fetchDocs(version) {
21
- return await fetch(`${getNgHost(version)}/generated/docs/app/search-data.json`).then(response => response.json());
19
+ const manifestUrl = `${getNgHost(version)}/assets/api/manifest.json`;
20
+ return fetch(manifestUrl).then(response => response.json());
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param packageName
26
+ * @param pageName
27
+ * @param version
28
+ */
29
+ function getApiUrl(packageName, pageName, version) {
30
+ const packageNameWithoutPrefix = packageName.replace('@angular/', '');
31
+ return `${getNgHost(version)}/api/${packageNameWithoutPrefix}/${pageName}`;
22
32
  }
23
33
 
24
34
  /**
25
35
  *
36
+ * @param packageName
26
37
  * @param page
27
38
  * @param version
28
39
  */
29
- function ngPageToKeyword(page, version) {
30
- const path = `${getNgHost(version)}/${page.path}`;
31
- const isCodeLink = ngApiPageTypes.includes(page.type);
32
- const key = isCodeLink ? page.title : page.title.replace(/\n/g, '');
40
+ function ngPageToKeyword(packageName, page, version) {
41
+ const url = getApiUrl(packageName, page.name, version);
33
42
  const description = `External link the Angular documentation.`;
34
- switch (page.type) {
35
- case 'decorator':
36
- return [[page.title, {
37
- title: page.title,
38
- url: path,
39
- isCodeLink,
40
- description
41
- }], [`@${page.title}`, {
42
- title: `@${page.title}`,
43
- url: path,
44
- isCodeLink,
45
- description
46
- }]];
47
- default:
48
- return [[key, {
49
- title: page.title,
50
- url: path,
51
- isCodeLink,
52
- description
53
- }]];
43
+ const keywords = [[page.name, {
44
+ title: page.name,
45
+ url,
46
+ description
47
+ }]];
48
+ if (page.type === 'decorator') {
49
+ keywords.push([`@${page.name}`, {
50
+ title: `@${page.name}`,
51
+ url,
52
+ description
53
+ }]);
54
54
  }
55
+ return keywords;
55
56
  }
56
57
 
57
58
  /**
@@ -63,13 +64,14 @@ function ngPageToKeyword(page, version) {
63
64
  */
64
65
  function ngKeywordsLoader(options) {
65
66
  return async () => {
66
- const {
67
- pages
68
- } = await fetchDocs(options?.version);
69
- return pages.filter(page => page.path.startsWith('api')).filter(page => ngApiPageTypes.includes(page.type)).map(page => ngPageToKeyword(page, options?.version)).flat().reduce((keywords, [key, keyword]) => {
70
- keywords[key] = keyword;
71
- return keywords;
72
- }, {});
67
+ try {
68
+ const packages = await fetchDocs(options?.version);
69
+ const keywords = Object.entries(packages).flatMap(([packageName, pages]) => pages.flatMap(page => ngPageToKeyword(packageName, page, options?.version)));
70
+ return Object.fromEntries(keywords);
71
+ } catch (error) {
72
+ console.error(`Failed to load Angular keywords: ${error}`);
73
+ return {};
74
+ }
73
75
  };
74
76
  }
75
77
 
@@ -92,23 +94,29 @@ function ngDocKeywordsLoader(options) {
92
94
  const assets = options.assetsPath ?? '/assets/ng-doc';
93
95
  const keywords = await fetchKeywords(`${endpoint}${assets}`);
94
96
  return Object.keys(keywords).reduce((acc, key) => {
95
- const keyword = keywords[key];
96
- const url = `${endpoint}${keyword.path}`;
97
- if (keyword.type === 'guide' && options.loadGuides) {
97
+ const {
98
+ title,
99
+ path,
100
+ description,
101
+ type
102
+ } = keywords[key];
103
+ const url = `${endpoint}${path}`;
104
+ const isGuideKeyword = key.startsWith('*');
105
+ if (isGuideKeyword && options.loadGuides) {
98
106
  const prefix = options.guidesPrefix ?? '';
99
107
  const newKey = `*${prefix}${key.replace(/^\*/, '')}`;
100
108
  acc[newKey] = {
101
- title: keyword.title ?? key,
109
+ title: title ?? key,
102
110
  url,
103
- description: keyword.description,
104
- isCodeLink: keyword.isCodeLink
111
+ description,
112
+ type
105
113
  };
106
- } else if (keyword.type !== 'guide') {
114
+ } else {
107
115
  acc[key] = {
108
- title: keyword.title ?? key,
116
+ title: title ?? key,
109
117
  url,
110
- description: keyword.description,
111
- isCodeLink: keyword.isCodeLink
118
+ description,
119
+ type
112
120
  };
113
121
  }
114
122
  return acc;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ng-doc/keywords-loaders",
3
- "version": "17.6.15",
3
+ "version": "18.0.0-beta.1",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
- "@ng-doc/core": "17.6.15",
6
+ "@ng-doc/core": "18.0.0-beta.1",
7
7
  "node-fetch": "2.6.11"
8
8
  },
9
9
  "publishConfig": {
@@ -1,2 +0,0 @@
1
- export * from './ng-api-page-types';
2
- export * from './ng-page-types';
@@ -1 +0,0 @@
1
- export declare const ngApiPageTypes: readonly string[];
@@ -1 +0,0 @@
1
- export declare const ngPageTypes: readonly string[];