forked from ionic-team/stencil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): provide docs-custom-elements output targets
Follows the draft outlined in webcomponents/custom-elements-manifest#8 Closes: ionic-team#2048
- Loading branch information
R煤nar Berg
authored and
R煤nar Berg
committed
Apr 11, 2020
1 parent
5b9b89e
commit c22e08b
Showing
6 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as d from '../../../declarations'; | ||
import { isOutputTargetDocsCustomElements } from '../../output-targets/output-utils'; | ||
|
||
export const generateCustomElementsDocs = async (compilerCtx: d.CompilerCtx, docsData: d.JsonDocs, outputTargets: d.OutputTarget[]) => { | ||
const customElementsOutputTargets = outputTargets.filter(isOutputTargetDocsCustomElements); | ||
|
||
if (customElementsOutputTargets.length === 0) { | ||
return; | ||
} | ||
|
||
const jsonContent = JSON.stringify(customElementsJson(docsData), null, 2); | ||
|
||
await Promise.all( | ||
customElementsOutputTargets.map(outputTarget => compilerCtx.fs.writeFile(outputTarget.file, jsonContent)), | ||
); | ||
}; | ||
|
||
function customElementsJson(docsData: d.JsonDocs) { | ||
// https://github.com/webcomponents/custom-elements-json/pull/8 | ||
return { | ||
version: 1.2, | ||
tags: docsData.components.map((component) => ({ | ||
name: component.tag, | ||
path: `./${component.filePath}`, | ||
description: component.docs, | ||
|
||
attributes: component.props | ||
.filter((prop) => prop.attr) | ||
.map((prop) => ({ | ||
name: prop.attr, | ||
type: prop.type, | ||
description: prop.docs, | ||
defaultValue: prop.default, | ||
required: prop.required, | ||
})), | ||
|
||
properties: component.props.map((prop) => ({ | ||
name: prop.name, | ||
type: prop.type, | ||
description: prop.docs, | ||
defaultValue: prop.default, | ||
required: prop.required, | ||
})), | ||
|
||
events: component.events.map((event) => ({ | ||
name: event.event, | ||
description: event.docs, | ||
})), | ||
|
||
methods: component.methods.map((method) => ({ | ||
name: method.name, | ||
description: method.docs, | ||
signature: method.signature, | ||
})), | ||
|
||
slots: component.slots.map((slot) => ({ | ||
name: slot.name, | ||
description: slot.docs, | ||
})), | ||
|
||
cssCustomProperties: component.styles | ||
.filter((style) => style.annotation === 'prop') | ||
.map((style) => ({ | ||
name: style.name, | ||
description: style.docs, | ||
})), | ||
})), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters