-
Notifications
You must be signed in to change notification settings - Fork 795
/
index.ts
70 lines (65 loc) · 1.98 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { isOutputTargetDocsJson } from '@utils';
import { join } from 'path';
import type * as d from '../../../declarations';
export const generateJsonDocs = async (
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
docsData: d.JsonDocs,
outputTargets: d.OutputTarget[],
) => {
const jsonOutputTargets = outputTargets.filter(isOutputTargetDocsJson);
if (jsonOutputTargets.length === 0) {
return;
}
const docsDtsPath = join(config.sys.getCompilerExecutingPath(), '..', '..', 'internal', 'stencil-public-docs.d.ts');
const docsDts = await compilerCtx.fs.readFile(docsDtsPath);
const typesContent = `
/**
* This is an autogenerated file created by the Stencil compiler.
* DO NOT MODIFY IT MANUALLY
*/
${docsDts}
declare const _default: JsonDocs;
export default _default;
`;
const json = {
...docsData,
components: docsData.components.map((cmp) => ({
filePath: cmp.filePath,
encapsulation: cmp.encapsulation,
tag: cmp.tag,
readme: cmp.readme,
docs: cmp.docs,
docsTags: cmp.docsTags,
usage: cmp.usage,
props: cmp.props,
methods: cmp.methods,
events: cmp.events,
listeners: cmp.listeners,
styles: cmp.styles,
slots: cmp.slots,
parts: cmp.parts,
dependents: cmp.dependents,
dependencies: cmp.dependencies,
dependencyGraph: cmp.dependencyGraph,
deprecation: cmp.deprecation,
})),
};
const jsonContent = JSON.stringify(json, null, 2);
await Promise.all(
jsonOutputTargets.map((jsonOutput) => {
return writeDocsOutput(compilerCtx, jsonOutput, jsonContent, typesContent);
}),
);
};
export const writeDocsOutput = async (
compilerCtx: d.CompilerCtx,
jsonOutput: d.OutputTargetDocsJson,
jsonContent: string,
typesContent: string,
) => {
return Promise.all([
compilerCtx.fs.writeFile(jsonOutput.file, jsonContent),
jsonOutput.typesFile ? compilerCtx.fs.writeFile(jsonOutput.typesFile, typesContent) : (Promise.resolve() as any),
]);
};