|
| 1 | +/* |
| 2 | + * Software Name: OUDS Android |
| 3 | + * SPDX-FileCopyrightText: Copyright (c) Orange SA |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + * This software is distributed under the MIT license, |
| 7 | + * the text of which is available at https://opensource.org/license/MIT/ |
| 8 | + * or see the "LICENSE" file for more details. |
| 9 | + * |
| 10 | + * Software description: Android library of reusable graphical components |
| 11 | + */ |
| 12 | + |
| 13 | +import com.github.mustachejava.DefaultMustacheFactory |
| 14 | +import java.io.FileOutputStream |
| 15 | +import java.io.PrintWriter |
| 16 | +import kotlin.reflect.full.declaredMemberProperties |
| 17 | + |
| 18 | +tasks.register<DefaultTask>("prepareDocumentation") { |
| 19 | + doLast { |
| 20 | + val mustacheFactory = DefaultMustacheFactory() |
| 21 | + |
| 22 | + // Retrieve OudsVersion.Component object and fill the table in core/Module.md with the component design versions |
| 23 | + val coreModuleDocumentationWriter = PrintWriter(FileOutputStream("core/Module.md")) |
| 24 | + // Build a map in order to loop through all component versions in core Module.mustache |
| 25 | + val componentVersions = Class.forName("com.orange.ouds.theme.OudsVersion${'$'}Component") |
| 26 | + .kotlin |
| 27 | + .declaredMemberProperties |
| 28 | + .map { property -> |
| 29 | + val name = property.name |
| 30 | + .split("(?=\\p{Upper})".toRegex()) |
| 31 | + .filter { it.isNotEmpty() } |
| 32 | + .mapIndexed { index, word -> if (index == 0) word else word.lowercase() } |
| 33 | + .joinToString(" ") |
| 34 | + val value = property.getter.call() as String |
| 35 | + mapOf("name" to name, "value" to value) |
| 36 | + } |
| 37 | + mustacheFactory.compile("core/Module.mustache") |
| 38 | + .execute(coreModuleDocumentationWriter, mapOf("versions" to componentVersions)) |
| 39 | + .flush() |
| 40 | + |
| 41 | + // Retrieve OudsVersion.Tokens object and fill the tokens versions in various Module.md files |
| 42 | + val moduleDocumentationDirectories = listOf( |
| 43 | + "global-raw-tokens", |
| 44 | + "theme-contract", |
| 45 | + "theme-orange", |
| 46 | + "theme-sosh" |
| 47 | + ) |
| 48 | + // Use OudsVersion.Tokens directly in various Module.mustache files |
| 49 | + val tokensVersions = Class.forName("com.orange.ouds.theme.OudsVersion${'$'}Tokens").kotlin.objectInstance |
| 50 | + moduleDocumentationDirectories.forEach { moduleDocumentationDirectory -> |
| 51 | + val moduleDocumentationWriter = PrintWriter(FileOutputStream("$moduleDocumentationDirectory/Module.md")) |
| 52 | + mustacheFactory.compile("$moduleDocumentationDirectory/Module.mustache") |
| 53 | + .execute(moduleDocumentationWriter, tokensVersions) |
| 54 | + .flush() |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments