@ng-doc/keywords-loaders 16.5.0-beta.2
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.
- package/README.md +11 -0
- package/angular/constants/index.d.ts +2 -0
- package/angular/constants/ng-api-page-types.d.ts +1 -0
- package/angular/constants/ng-page-types.d.ts +1 -0
- package/angular/helpers/fetch-docs.d.ts +7 -0
- package/angular/helpers/get-ng-host.d.ts +6 -0
- package/angular/helpers/index.d.ts +3 -0
- package/angular/helpers/ng-to-keyword.d.ts +9 -0
- package/angular/index.d.ts +2 -0
- package/angular/interfaces/index.d.ts +3 -0
- package/angular/interfaces/ng-keyword-loader-options.d.ts +4 -0
- package/angular/interfaces/ng-page.d.ts +6 -0
- package/angular/interfaces/ng-response.d.ts +4 -0
- package/angular/ng-keywords-loader.d.ts +11 -0
- package/angular/types/index.d.ts +2 -0
- package/angular/types/ng-api-page-type.d.ts +2 -0
- package/angular/types/ng-version.d.ts +1 -0
- package/index.cjs +188 -0
- package/index.d.ts +2 -0
- package/ng-doc/helpers/fetch-keywords.d.ts +6 -0
- package/ng-doc/helpers/index.d.ts +1 -0
- package/ng-doc/index.d.ts +2 -0
- package/ng-doc/interfaces/index.d.ts +1 -0
- package/ng-doc/interfaces/keywords-loader-options.d.ts +23 -0
- package/ng-doc/ng-doc-keywords-loader.d.ts +9 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# keywords-loaders
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build keywords-loaders` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test keywords-loaders` to execute the unit tests via [Jest](https://jestjs.io).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ngApiPageTypes: readonly string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ngPageTypes: readonly string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NgDocGlobalKeyword } from '@ng-doc/core';
|
|
2
|
+
import { NgPage } from '../interfaces';
|
|
3
|
+
import { NgVersion } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param page
|
|
7
|
+
* @param version
|
|
8
|
+
*/
|
|
9
|
+
export declare function ngPageToKeyword(page: NgPage, version?: NgVersion): Array<[string, NgDocGlobalKeyword]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NgDocKeywordsLoader } from '@ng-doc/core';
|
|
2
|
+
import { NgKeywordLoaderOptions } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Loads keywords from Angular documentation.
|
|
5
|
+
* This loader will fetch the documentation from the Angular website and
|
|
6
|
+
* extract the keywords from the API pages which will transform them all mentioning
|
|
7
|
+
* of the Angular API into links to the Angular documentation.
|
|
8
|
+
*
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
export declare function ngKeywordsLoader(options?: NgKeywordLoaderOptions): NgDocKeywordsLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type NgVersion = string;
|
package/index.cjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const ngApiPageTypes = ['class', 'interface', 'function', 'type-alias', 'enum', 'const', 'ngmodule', 'directive', 'pipe', 'decorator'];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param version
|
|
10
|
+
*/
|
|
11
|
+
function getNgHost(version) {
|
|
12
|
+
const versionEndpoint = version ? `${version}.` : '';
|
|
13
|
+
return `https://${versionEndpoint}angular.io`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function _async$3(f) {
|
|
17
|
+
return function () {
|
|
18
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
19
|
+
args[i] = arguments[i];
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return Promise.resolve(f.apply(this, args));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return Promise.reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const fetchDocs = _async$3(function (version) {
|
|
29
|
+
return fetch(`${getNgHost(version)}/generated/docs/app/search-data.json`).then(response => response.json());
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param page
|
|
35
|
+
* @param version
|
|
36
|
+
*/
|
|
37
|
+
function ngPageToKeyword(page, version) {
|
|
38
|
+
const path = `${getNgHost(version)}/${page.path}`;
|
|
39
|
+
const isCodeLink = ngApiPageTypes.includes(page.type);
|
|
40
|
+
const key = isCodeLink ? page.title : page.title.replace(/\n/g, '');
|
|
41
|
+
const description = `External link the Angular documentation.`;
|
|
42
|
+
switch (page.type) {
|
|
43
|
+
case 'decorator':
|
|
44
|
+
return [[page.title, {
|
|
45
|
+
title: page.title,
|
|
46
|
+
url: path,
|
|
47
|
+
isCodeLink,
|
|
48
|
+
description
|
|
49
|
+
}], [`@${page.title}`, {
|
|
50
|
+
title: `@${page.title}`,
|
|
51
|
+
url: path,
|
|
52
|
+
isCodeLink,
|
|
53
|
+
description
|
|
54
|
+
}]];
|
|
55
|
+
default:
|
|
56
|
+
return [[key, {
|
|
57
|
+
title: page.title,
|
|
58
|
+
url: path,
|
|
59
|
+
isCodeLink,
|
|
60
|
+
description
|
|
61
|
+
}]];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Loads keywords from Angular documentation.
|
|
67
|
+
* This loader will fetch the documentation from the Angular website and
|
|
68
|
+
* extract the keywords from the API pages which will transform them all mentioning
|
|
69
|
+
* of the Angular API into links to the Angular documentation.
|
|
70
|
+
*
|
|
71
|
+
* @param options
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
function _await$1(value, then, direct) {
|
|
75
|
+
if (direct) {
|
|
76
|
+
return then ? then(value) : value;
|
|
77
|
+
}
|
|
78
|
+
if (!value || !value.then) {
|
|
79
|
+
value = Promise.resolve(value);
|
|
80
|
+
}
|
|
81
|
+
return then ? value.then(then) : value;
|
|
82
|
+
}
|
|
83
|
+
function _async$2(f) {
|
|
84
|
+
return function () {
|
|
85
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
86
|
+
args[i] = arguments[i];
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return Promise.resolve(f.apply(this, args));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return Promise.reject(e);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function ngKeywordsLoader(options) {
|
|
96
|
+
return _async$2(function () {
|
|
97
|
+
return _await$1(fetchDocs(options?.version), function ({
|
|
98
|
+
pages
|
|
99
|
+
}) {
|
|
100
|
+
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]) => {
|
|
101
|
+
keywords[key] = keyword;
|
|
102
|
+
return keywords;
|
|
103
|
+
}, {});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param endpoint
|
|
111
|
+
*/
|
|
112
|
+
function _async$1(f) {
|
|
113
|
+
return function () {
|
|
114
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
115
|
+
args[i] = arguments[i];
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return Promise.resolve(f.apply(this, args));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return Promise.reject(e);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const fetchKeywords = _async$1(function (endpoint) {
|
|
125
|
+
return fetch(`${endpoint}/keywords.json`).then(response => response.json());
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Loads keywords from an external NgDoc documentation.
|
|
130
|
+
* You can use it to integrate your documentation with another NgDoc documentation and use its API or Pages keywords.
|
|
131
|
+
*
|
|
132
|
+
* @param options - The options for the NgDoc keywords loader.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
function _await(value, then, direct) {
|
|
136
|
+
if (direct) {
|
|
137
|
+
return then ? then(value) : value;
|
|
138
|
+
}
|
|
139
|
+
if (!value || !value.then) {
|
|
140
|
+
value = Promise.resolve(value);
|
|
141
|
+
}
|
|
142
|
+
return then ? value.then(then) : value;
|
|
143
|
+
}
|
|
144
|
+
function _async(f) {
|
|
145
|
+
return function () {
|
|
146
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
147
|
+
args[i] = arguments[i];
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
return Promise.resolve(f.apply(this, args));
|
|
151
|
+
} catch (e) {
|
|
152
|
+
return Promise.reject(e);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function ngDocKeywordsLoader(options) {
|
|
157
|
+
return _async(function () {
|
|
158
|
+
const endpoint = options.endpoint.replace(/\/$/, '');
|
|
159
|
+
const assets = options.assetsPath ?? '/assets/ng-doc';
|
|
160
|
+
return _await(fetchKeywords(`${endpoint}${assets}`), function (keywords) {
|
|
161
|
+
return Object.keys(keywords).reduce((acc, key) => {
|
|
162
|
+
const keyword = keywords[key];
|
|
163
|
+
const url = `${endpoint}${keyword.path}`;
|
|
164
|
+
if (keyword.type === 'guide' && options.loadGuides) {
|
|
165
|
+
const prefix = options.guidesPrefix ?? '';
|
|
166
|
+
const newKey = `*${prefix}${key.replace(/^\*/, '')}`;
|
|
167
|
+
acc[newKey] = {
|
|
168
|
+
title: keyword.title ?? key,
|
|
169
|
+
url,
|
|
170
|
+
description: keyword.description,
|
|
171
|
+
isCodeLink: keyword.isCodeLink
|
|
172
|
+
};
|
|
173
|
+
} else if (keyword.type !== 'guide') {
|
|
174
|
+
acc[key] = {
|
|
175
|
+
title: keyword.title ?? key,
|
|
176
|
+
url,
|
|
177
|
+
description: keyword.description,
|
|
178
|
+
isCodeLink: keyword.isCodeLink
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return acc;
|
|
182
|
+
}, {});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
exports.ngDocKeywordsLoader = ngDocKeywordsLoader;
|
|
188
|
+
exports.ngKeywordsLoader = ngKeywordsLoader;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fetch-keywords';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './keywords-loader-options';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of possible options for the NgDoc keywords loader.
|
|
3
|
+
*/
|
|
4
|
+
export interface NgDocKeywordsLoaderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The URL endpoint of the NgDoc documentation. (e.g. https://ng-doc.com)
|
|
7
|
+
*/
|
|
8
|
+
endpoint: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to the assets folder of the NgDoc documentation. (default: `/assets/ng-doc`)
|
|
11
|
+
*/
|
|
12
|
+
assetsPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to load the keywords for the external guides. (default: `false`)
|
|
15
|
+
*/
|
|
16
|
+
loadGuides?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Defines the prefix to use for the external guides.
|
|
19
|
+
* (e.g. if the external guides have keyword `Installation`
|
|
20
|
+
* and you set `guidesPrefix` to `External`, the keyword will be `ExternalInstallation`)
|
|
21
|
+
*/
|
|
22
|
+
guidesPrefix?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NgDocKeywordsLoader } from '@ng-doc/core';
|
|
2
|
+
import { NgDocKeywordsLoaderOptions } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Loads keywords from an external NgDoc documentation.
|
|
5
|
+
* You can use it to integrate your documentation with another NgDoc documentation and use its API or Pages keywords.
|
|
6
|
+
*
|
|
7
|
+
* @param options - The options for the NgDoc keywords loader.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ngDocKeywordsLoader(options: NgDocKeywordsLoaderOptions): NgDocKeywordsLoader;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ng-doc/keywords-loaders",
|
|
3
|
+
"version": "16.5.0-beta.2",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@ng-doc/core": "16.5.0-beta.2"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "./index.cjs",
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"require": "./index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"angular",
|
|
21
|
+
"documentation",
|
|
22
|
+
"generator",
|
|
23
|
+
"builder",
|
|
24
|
+
"guides",
|
|
25
|
+
"api",
|
|
26
|
+
"demo",
|
|
27
|
+
"ng-doc"
|
|
28
|
+
],
|
|
29
|
+
"author": "Skoropad Aleksandr <alex@skoropad.dev>",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ng-doc/ng-doc.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ng-doc/ng-doc/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://ng-doc.com",
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
}
|