Skip to content

Commit 716d956

Browse files
committed
undo
1 parent 56e481b commit 716d956

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

build.gradle.kts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
67
import util.getSpacePassword
7-
import util.getSpaceUsername
88
import util.kotlinVersionParsed
99
import util.libs
1010

@@ -70,33 +70,44 @@ val executeNpmLogin by tasks.registering {
7070
val isCI = System.getenv("TEAMCITY_VERSION") != null
7171
val localYarnUpdate = project.providers.gradleProperty("kotlinx.rpc.localYarnUpdate")
7272

73-
if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
74-
return@registering
75-
}
73+
val usePrivateRegistry = isCI || localYarnUpdate.orNull?.toBooleanStrictOrNull() == true
7674

77-
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
75+
val registryUrl = if (usePrivateRegistry) {
76+
"https://packages.jetbrains.team/npm/p/krpc/build-deps/"
77+
} else {
78+
"https://registry.npmjs.org"
79+
}
7880

7981
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
8082
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
8183
val buildNpmConfigFile = File(project.rootDir, "build/js/.npmrc")
8284

83-
val spacePassword: String = project.getSpacePassword()
85+
val spacePassword: String? = project.getSpacePasswordOrNull()
8486

8587
doLast {
86-
if (spacePassword.split(".").size != 3) {
87-
error("Unexpected Space Token format")
88-
}
89-
9088
val outputYarnText = """
9189
registry: "$registryUrl"
9290
""".trimIndent()
9391

94-
val outputNpmText = """
92+
var outputNpmText = """
9593
registry: "$registryUrl"
96-
always-auth: true
97-
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
9894
""".trimIndent()
9995

96+
if (usePrivateRegistry) {
97+
if (spacePassword == null) {
98+
error("Expected space password for NPM log in")
99+
}
100+
101+
if (spacePassword.split(".").size != 3) {
102+
error("Unexpected Space Token format")
103+
}
104+
105+
outputNpmText += '\n' + """
106+
always-auth: true
107+
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
108+
""".trimIndent()
109+
}
110+
100111
buildYarnConfigFile.createNewFile()
101112
buildYarnConfigFile.writeText(outputYarnText)
102113
buildNpmConfigFile.createNewFile()

gradle-conventions-settings/src/main/kotlin/util/properties.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,26 @@ fun Project.getLocalProperties(): Properties {
3232
}
3333
}
3434

35+
private const val SPACE_USERNAME = "kotlinx.rpc.team.space.username"
36+
private const val SPACE_USERNAME_ENV = "kotlinx_rpc_team_space_username"
37+
3538
fun Project.getSpaceUsername(): String {
36-
val username = "kotlinx.rpc.team.space.username"
37-
val usernameEnv = "kotlinx_rpc_team_space_username"
38-
return getLocalProperties()[username] as String?
39-
?: providers.gradleProperty(username).orNull
40-
?: System.getenv(usernameEnv)?.ifEmpty { null }
41-
?: requiredPropertyError(username, usernameEnv)
39+
return getLocalProperties()[SPACE_USERNAME] as String?
40+
?: providers.gradleProperty(SPACE_USERNAME).orNull
41+
?: System.getenv(SPACE_USERNAME_ENV)?.ifEmpty { null }
42+
?: requiredPropertyError(SPACE_USERNAME, SPACE_USERNAME_ENV)
4243
}
4344

45+
private const val SPACE_PASSWORD = "kotlinx.rpc.team.space.password"
46+
private const val SPACE_PASSWORD_ENV = "kotlinx_rpc_team_space_password"
47+
4448
fun Project.getSpacePassword(): String {
45-
val password = "kotlinx.rpc.team.space.password"
46-
val passwordEnv = "kotlinx_rpc_team_space_password"
47-
return getLocalProperties()[password] as String?
48-
?: providers.gradleProperty(password).orNull
49-
?: System.getenv(passwordEnv)?.ifEmpty { null }
50-
?: requiredPropertyError(password, passwordEnv)
49+
return getSpacePasswordOrNull()
50+
?: requiredPropertyError(SPACE_PASSWORD, SPACE_PASSWORD_ENV)
51+
}
52+
53+
fun Project.getSpacePasswordOrNull(): String? {
54+
return getLocalProperties()[SPACE_PASSWORD] as String?
55+
?: providers.gradleProperty(SPACE_PASSWORD).orNull
56+
?: System.getenv(SPACE_PASSWORD_ENV)?.ifEmpty { null }
5157
}

0 commit comments

Comments
 (0)