|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion |
| 6 | +import util.getSpacePassword |
| 7 | +import util.getSpaceUsername |
6 | 8 | import util.kotlinVersionParsed |
7 | 9 | import util.libs |
8 | 10 |
|
@@ -64,7 +66,57 @@ if (kotlinVersion != kotlinGPVersion) { |
64 | 66 | error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion") |
65 | 67 | } |
66 | 68 |
|
| 69 | +val executeNpmLogin by tasks.registering { |
| 70 | + val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/" |
| 71 | + |
| 72 | + // To prevent leaking of credentials in VCS on dev machine use the build directory config file |
| 73 | + val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc") |
| 74 | + val buildYarnYmlConfigFile = File(project.rootDir, "build/js/.yarnrc.yml") |
| 75 | + |
| 76 | + val spaceUsername: String? = getSpaceUsername() |
| 77 | + val spacePassword: String? = getSpacePassword() |
| 78 | + |
| 79 | + doLast { |
| 80 | + if (spaceUsername == null || spacePassword == null) { |
| 81 | + return@doLast |
| 82 | + } |
| 83 | + |
| 84 | + if (spacePassword.split(".").size != 3) { |
| 85 | + error("Unexpected Space Token format") |
| 86 | + } |
| 87 | + |
| 88 | + val outputYarnYmlText = """ |
| 89 | + npmRegistryServer: "$registryUrl" |
| 90 | + npmAlwaysAuth: true |
| 91 | + npmAuthToken: "$spacePassword" |
| 92 | + """.trimIndent() |
| 93 | + |
| 94 | + buildYarnConfigFile.createNewFile() |
| 95 | + buildYarnConfigFile.writeText("registry: $registryUrl") |
| 96 | + buildYarnYmlConfigFile.createNewFile() |
| 97 | + buildYarnYmlConfigFile.writeText(outputYarnYmlText) |
| 98 | + } |
| 99 | + |
| 100 | + outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile") |
| 101 | + outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile") |
| 102 | +} |
| 103 | + |
| 104 | +plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach { |
| 105 | + rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) { |
| 106 | + download = true |
| 107 | + downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/" |
| 108 | + } |
| 109 | + |
| 110 | + tasks.named("kotlinNpmInstall").configure { |
| 111 | + dependsOn(executeNpmLogin) |
| 112 | + } |
| 113 | +} |
| 114 | + |
67 | 115 | // necessary for CI js tests |
68 | 116 | rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> { |
69 | | - rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false |
| 117 | + rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> { |
| 118 | + ignoreScripts = false |
| 119 | + download = true |
| 120 | + downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/" |
| 121 | + } |
70 | 122 | } |
0 commit comments