Skip to content

Commit 8924561

Browse files
authored
feat(): generate experimental web-components.json (#1256)
1 parent a7d5e3a commit 8924561

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/compiler/docs/docs.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BuildContext } from '../build/build-ctx';
33
import { catchError, hasError } from '../util';
44
import { cleanDiagnostics } from '../../util/logger/logger-util';
55
import { generateDocData } from './generate-doc-data';
6+
import { generateWebComponentsJson } from './generate-web-components-json';
67
import { generateJsonDocs } from './generate-json-docs';
78
import { generateReadmeDocs } from './generate-readme-docs';
89
import { generateCustomDocs } from './generate-custom-docs';
@@ -55,31 +56,34 @@ export async function generateDocs(config: d.Config, compilerCtx: d.CompilerCtx,
5556
if (!config.buildDocs) {
5657
return;
5758
}
59+
const distOutputTargets = config.outputTargets.filter(o => o.type === 'dist') as d.OutputTargetDist[];
5860
const docsOutputTargets = config.outputTargets.filter(o => {
5961
return o.type === 'docs' || o.type === 'docs-json' || o.type === 'docs-custom';
6062
});
6163

62-
if (docsOutputTargets.length === 0) {
63-
return;
64-
}
65-
6664
const docsData = await generateDocData(config, compilerCtx, buildCtx.diagnostics);
6765

6866
const strictCheck = (docsOutputTargets as d.OutputTargetDocsReadme[]).some(o => !!o.strict);
6967
if (strictCheck) {
7068
strickCheckDocs(config, docsData);
7169
}
7270

71+
// generate web-components.json
72+
await generateWebComponentsJson(config, compilerCtx, distOutputTargets, docsData);
73+
74+
// generate READMEs docs
7375
const readmeTargets = docsOutputTargets.filter(o => o.type === 'docs') as d.OutputTargetDocsReadme[];
7476
if (readmeTargets.length > 0) {
7577
await generateReadmeDocs(config, compilerCtx, readmeTargets, docsData);
7678
}
7779

80+
// generate json docs
7881
const jsonTargets = docsOutputTargets.filter(o => o.type === 'docs-json') as d.OutputTargetDocsJson[];
7982
if (jsonTargets.length > 0) {
8083
await generateJsonDocs(compilerCtx, jsonTargets, docsData);
8184
}
8285

86+
// generate custom docs
8387
const customTargets = docsOutputTargets.filter(o => o.type === 'docs-custom') as d.OutputTargetDocsCustom[];
8488
if (customTargets.length > 0) {
8589
await generateCustomDocs(config, customTargets, docsData);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as d from '../../declarations';
2+
import { WEB_COMPONENTS_JSON_FILE_NAME } from '../../util/constants';
3+
import { normalizePath } from '../util';
4+
5+
export async function generateWebComponentsJson(config: d.Config, compilerCtx: d.CompilerCtx, distOutputs: d.OutputTargetDist[], docsData: d.JsonDocs) {
6+
const json = {
7+
'tags': docsData.components.map(cmp => ({
8+
'label': cmp.tag,
9+
'description': cmp.readme,
10+
'attributes': cmp.props.filter(p => p.attr).map(p => ({
11+
'label': p.attr,
12+
'description': p.docs,
13+
'required': p.required
14+
}))
15+
}))
16+
};
17+
const jsonContent = JSON.stringify(json, null, 2);
18+
await Promise.all(distOutputs.map(async distOutput => {
19+
const filePath = normalizePath(config.sys.path.join(distOutput.buildDir, WEB_COMPONENTS_JSON_FILE_NAME));
20+
await compilerCtx.fs.writeFile(filePath, jsonContent);
21+
}));
22+
}

src/util/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const XML_NS = 'http://www.w3.org/XML/1998/namespace';
116116
*/
117117
export const BANNER = `Built with http://stenciljs.com`;
118118
export const COLLECTION_MANIFEST_FILE_NAME = 'collection-manifest.json';
119+
export const WEB_COMPONENTS_JSON_FILE_NAME = 'web-components.json';
119120
export const APP_NAMESPACE_REGEX = /["']__APP__['"]/g;
120121

121122

0 commit comments

Comments
 (0)