mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 09:17:50 +08:00
generate_descriptor_pages.main.kts: Support multiple pages generation
This commit is contained in:
parent
c0f277d6f6
commit
a13bb3f689
@ -24,29 +24,6 @@ The proper solution is to create a snippet file in topics/_generated,
|
|||||||
but we can't use this approach until WRS-1009 is fixed.
|
but we can't use this approach until WRS-1009 is fixed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
val PLUGIN_DESCRIPTOR_DATA_URL = "https://jb.gg/sdk-docs/plugin-descriptor.yaml"
|
|
||||||
val PLUGIN_CONFIGURATION_FILE_PATH = "topics/basics/plugin_structure/plugin_configuration_file.md"
|
|
||||||
|
|
||||||
val content = URL(PLUGIN_DESCRIPTOR_DATA_URL).readText()
|
|
||||||
.run {
|
|
||||||
val loaderOptions = LoaderOptions().apply {
|
|
||||||
isEnumCaseSensitive = false
|
|
||||||
}
|
|
||||||
val representer = Representer(DumperOptions()).apply {
|
|
||||||
propertyUtils.isSkipMissingProperties = true
|
|
||||||
}
|
|
||||||
val constructor = Constructor(DocumentationContent::class.java, loaderOptions)
|
|
||||||
Yaml(constructor, representer).load<DocumentationContent>(this)
|
|
||||||
}
|
|
||||||
.takeIf { it?.elements != null }
|
|
||||||
?: throw RuntimeException("Failed to parse $PLUGIN_DESCRIPTOR_DATA_URL")
|
|
||||||
|
|
||||||
val renderedElementPaths = mutableListOf<String>()
|
|
||||||
|
|
||||||
val newFileContent = StringBuilder()
|
|
||||||
val patternToInsertAfter = "[//]: # (GENERATED CONTENT START)"
|
|
||||||
val patternToSkipUntil = "[//]: # (GENERATED CONTENT END)"
|
|
||||||
|
|
||||||
// delete it when WRS-6339 is done
|
// delete it when WRS-6339 is done
|
||||||
val renderedPageNameToTopicNames = mutableMapOf<String, String>().apply {
|
val renderedPageNameToTopicNames = mutableMapOf<String, String>().apply {
|
||||||
// init map once:
|
// init map once:
|
||||||
@ -64,7 +41,36 @@ val renderedPageNameToTopicNames = mutableMapOf<String, String>().apply {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file(PLUGIN_CONFIGURATION_FILE_PATH).useLines { lines ->
|
val renderedElementPaths = mutableListOf<String>()
|
||||||
|
|
||||||
|
val descriptors = listOf(
|
||||||
|
DescriptorInfo("https://jb.gg/sdk-docs/plugin-descriptor.yaml", "topics/basics/plugin_structure/plugin_configuration_file.md")
|
||||||
|
)
|
||||||
|
|
||||||
|
descriptors.forEach { descriptor ->
|
||||||
|
processDescriptor(descriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun processDescriptor(descriptor: DescriptorInfo) {
|
||||||
|
val content = URL(descriptor.dataUrl).readText()
|
||||||
|
.run {
|
||||||
|
val loaderOptions = LoaderOptions().apply {
|
||||||
|
isEnumCaseSensitive = false
|
||||||
|
}
|
||||||
|
val representer = Representer(DumperOptions()).apply {
|
||||||
|
propertyUtils.isSkipMissingProperties = true
|
||||||
|
}
|
||||||
|
val constructor = Constructor(DocumentationContent::class.java, loaderOptions)
|
||||||
|
Yaml(constructor, representer).load<DocumentationContent>(this)
|
||||||
|
}
|
||||||
|
.takeIf { it?.elements != null }
|
||||||
|
?: throw RuntimeException("Failed to parse ${descriptor.dataUrl}")
|
||||||
|
|
||||||
|
val newFileContent = StringBuilder()
|
||||||
|
val patternToInsertAfter = "[//]: # (GENERATED CONTENT START)"
|
||||||
|
val patternToSkipUntil = "[//]: # (GENERATED CONTENT END)"
|
||||||
|
|
||||||
|
file(descriptor.filePath).useLines { lines ->
|
||||||
var insideGeneratedContent = false
|
var insideGeneratedContent = false
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
if (line.trim() == patternToInsertAfter) {
|
if (line.trim() == patternToInsertAfter) {
|
||||||
@ -78,9 +84,10 @@ file(PLUGIN_CONFIGURATION_FILE_PATH).useLines { lines ->
|
|||||||
newFileContent.appendLine(line)
|
newFileContent.appendLine(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file(PLUGIN_CONFIGURATION_FILE_PATH).writeText(newFileContent.toString())
|
file(descriptor.filePath).writeText(newFileContent.toString())
|
||||||
|
}
|
||||||
|
|
||||||
fun renderContent(content: DocumentationContent): String {
|
fun renderContent(content: DocumentationContent): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
@ -405,6 +412,8 @@ fun getInternalLink(url: String): String? {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DescriptorInfo(val dataUrl: String, val filePath: String)
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
// content data classes (synchronize this with org.jetbrains.idea.devkit.documentation.DocumentationContent):
|
// content data classes (synchronize this with org.jetbrains.idea.devkit.documentation.DocumentationContent):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user