Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat applied hydrated directives #500

Merged
merged 1 commit into from
Jan 18, 2024
Merged

Reformat applied hydrated directives #500

merged 1 commit into from
Jan 18, 2024

Conversation

gnawf
Copy link
Collaborator

@gnawf gnawf commented Dec 19, 2023

Based on #499

@gnawf
Copy link
Collaborator Author

gnawf commented Dec 19, 2023

Done using this script

fun main() {
    val fixturesDir = File("nadel/test/src/test/resources/fixtures")
    fixturesDir
        .walkTopDown()
        .filter {
            it.extension == "yml" || it.extension == "yaml"
        }
        .forEach { file ->
            val newText = file
                .useLines { lines ->
                    lines
                        .map {
                            val atHydrated = "@hydrated"
                            val line = it.trimEnd()
                            if (line.contains(atHydrated) && line.endsWith(")")) {
                                val indent = line
                                    .asSequence()
                                    .takeWhile { char ->
                                        char.isWhitespace()
                                    }
                                    .joinToString("")

                                val newArgs = line
                                    .substringAfter(atHydrated)
                                    .trimStart()
                                    .removePrefix("(")
                                    .removeSuffix(")")
                                    .replace("service\\s*:".toRegex(), "\nservice:")
                                    .replace("field\\s*:".toRegex(), "\nfield:")
                                    .replace("identifiedBy\\s*:".toRegex(), "\nidentifiedBy:")
                                    .replace("inputIdentifiedBy\\s*:".toRegex(), "\ninputIdentifiedBy:")
                                    .replace("indexed\\s*:".toRegex(), "\nindexed:")
                                    .replace("batched\\s*:".toRegex(), "\nbatched:")
                                    .replace("batchSize\\s*:".toRegex(), "\nbatchSize:")
                                    .replace("timeout\\s*:".toRegex(), "\ntimeout:")
                                    .replace("arguments\\s*:".toRegex(), "\narguments:")
                                    .replace("when\\s*:".toRegex(), "\nwhen:")
                                    .lineSequence()
                                    .filter {
                                        it.isNotBlank()
                                    }
                                    .map {
                                        indent + "  " + it.trim()
                                    }
                                    .joinToString("\n")

                                val newHydrated = sequenceOf(
                                    "$indent@hydrated(",
                                    newArgs,
                                    "$indent)",
                                ).joinToString("\n")

                                val newLine = line.substringBefore(atHydrated).trimEnd() + "\n" + newHydrated
                                newLine
                            } else {
                                it
                            }
                        }
                        .joinToString("\n").trimEnd() + "\n"
                }
            file.writeText(newText)
        }
}

@gnawf gnawf changed the base branch from graphql-syntax-highlighting to master December 19, 2023 22:53
@gnawf gnawf marked this pull request as ready for review December 19, 2023 22:54
@gnawf gnawf requested a review from sbarker2 December 20, 2023 00:56
@gnawf gnawf merged commit a5a1054 into master Jan 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants