Skip to content

Commit c41888b

Browse files
committed
add new js target for browser extensions
Signed-off-by: Adam Ratzman <[email protected]>
1 parent a34aff2 commit c41888b

File tree

18 files changed

+151
-45
lines changed

18 files changed

+151
-45
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
2323
SPOTIFY_API_PUBLISH_VERSION: ${{ github.event.inputs.release_version }}
2424
jobs:
25-
release_android_jvm_linux:
25+
release_android_jvm_linux_js:
2626
runs-on: ubuntu-latest
2727
environment: release
2828
steps:
@@ -32,13 +32,14 @@ jobs:
3232
run: sudo apt-get install -y curl libcurl4-openssl-dev
3333
- name: Verify Android
3434
run: gradle testDebugUnitTest
35-
- name: Verify JVM
36-
run: gradle jvmTest
35+
- name: Verify JVM/JS
36+
run: gradle jvmTest jsIrTest jsBrowserExtensionsLegacyTest
3737
- name: Publish JVM/Linux/Android
38-
run: gradle publishJvmPublicationToNexusRepository publishAndroidPublicationToNexusRepository publishLinuxX64PublicationToNexusRepository
38+
run: gradle publishJvmPublicationToNexusRepository publishAndroidPublicationToNexusRepository publishLinuxX64PublicationToNexusRepository publishJsPublicationToNexusRepository publishJsBrowserExtensionsPublicationToNexusRepository
3939
release_mac:
4040
runs-on: macos-latest
4141
environment: release
42+
needs: release_android_jvm_linux_js
4243
steps:
4344
- name: Check out repo
4445
uses: actions/checkout@v2
@@ -49,6 +50,7 @@ jobs:
4950
release_windows:
5051
runs-on: windows-latest
5152
environment: release
53+
needs: release_mac
5254
steps:
5355
- name: Check out repo
5456
uses: actions/checkout@v2
@@ -59,6 +61,7 @@ jobs:
5961
release_docs:
6062
runs-on: ubuntu-latest
6163
environment: release
64+
needs: release_windows
6265
steps:
6366
- name: Check out repo
6467
uses: actions/checkout@v2
@@ -69,7 +72,7 @@ jobs:
6972
env:
7073
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
7174
with:
72-
source-directory: 'build'
75+
source-directory: 'docs'
7376
destination-github-username: 'adamint'
7477
destination-repository-name: 'spotify-web-api-kotlin-docs'
7578
user-email: [email protected]

README_ANDROID.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ host. Ex: for the redirect uri `myapp://authcallback`, the scheme is `myapp` and
218218
android:name="YOUR_CLASS_IMPLEMENTING_AbstractSpotifyAppImplicitLoginActivity"
219219
android:theme="@android:style/Theme.Translucent.NoTitleBar">
220220
<intent-filter>
221-
<action android:name="android.intent.action.VIEW" />
222-
<category android:name="android.intent.category.DEFAULT" />
223-
<category android:name="android.intent.category.BROWSABLE" />
221+
<action android:name="android.intent.action.VIEW"/>
222+
<category android:name="android.intent.category.DEFAULT"/>
223+
<category android:name="android.intent.category.BROWSABLE"/>
224224
<data android:scheme="YOUR_REDIRECT_SCHEME" android:host="YOUR_REDIRECT_HOST"/>
225225
</intent-filter>
226226
</activity>

build.gradle.kts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@ kotlin {
121121
}
122122

123123
val irOnlyJs = project.hasProperty("irOnly")
124-
js(if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.BOTH) {
124+
js(if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.IR) {
125125

126126
mavenPublication {
127127
setupPom(artifactId)
128128
}
129129

130130
browser {
131131
webpackTask {
132+
output.globalObject = "this"
132133
output.libraryTarget = Target.UMD
133134
}
134135

@@ -152,6 +153,28 @@ kotlin {
152153
if (irOnlyJs) binaries.library()
153154
}
154155

156+
js("jsBrowserExtensions", if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.IR) {
157+
mavenPublication {
158+
setupPom(artifactId)
159+
}
160+
161+
browser {
162+
webpackTask {
163+
output.libraryTarget = "plain"//Target.
164+
}
165+
166+
testTask {
167+
useKarma {
168+
useChromeHeadless()
169+
//useChrome()
170+
webpackConfig.cssSupport.enabled = true
171+
}
172+
}
173+
}
174+
175+
if (irOnlyJs) binaries.library()
176+
}
177+
155178
// val hostOs = System.getProperty("os.name")
156179
// val isMainHost = hostOs.contains("mac", true)
157180
// val isMingwX64 = hostOs.startsWith("Windows")
@@ -212,6 +235,8 @@ kotlin {
212235
}
213236

214237
targets {
238+
val kotlinxDatetimeVersion = "0.2.1"
239+
215240
sourceSets {
216241
val serializationVersion = "1.2.2"
217242
val ktorVersion = "1.6.2"
@@ -220,13 +245,11 @@ kotlin {
220245
val androidSpotifyAuthVersion = "1.2.3"
221246
val androidCryptoVersion = "1.0.0"
222247
val coroutineMTVersion = "1.5.1-native-mt"
223-
val kotlinxDatetimeVersion = "0.2.1"
224248

225249
val commonMain by getting {
226250
dependencies {
227251
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
228252
implementation("io.ktor:ktor-client-core:$ktorVersion")
229-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetimeVersion")
230253
implementation("com.soywiz.korlibs.krypto:krypto:$korlibsVersion")
231254
implementation("com.soywiz.korlibs.korim:korim:$korlibsVersion")
232255

@@ -244,6 +267,7 @@ kotlin {
244267
dependsOn(commonMain)
245268

246269
dependencies {
270+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetimeVersion")
247271
implementation("net.sourceforge.streamsupport:android-retrofuture:1.7.3")
248272
}
249273
}
@@ -274,7 +298,6 @@ kotlin {
274298
implementation(npm("abort-controller", "3.0.0"))
275299
implementation(npm("node-fetch", "2.6.1"))
276300
implementation(kotlin("stdlib-js"))
277-
278301
}
279302
}
280303

@@ -284,6 +307,16 @@ kotlin {
284307
}
285308
}
286309

310+
val jsBrowserExtensionsMain by getting {
311+
dependsOn(jsMain)
312+
313+
}
314+
315+
val jsBrowserExtensionsTest by getting {
316+
dependsOn(jsTest)
317+
318+
}
319+
287320
val androidMain by getting {
288321
dependsOn(commonJvmLikeMain)
289322

@@ -318,6 +351,7 @@ kotlin {
318351
}
319352
}
320353
implementation("io.ktor:ktor-client-curl:$ktorVersion")
354+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetimeVersion")
321355
}
322356
}
323357

@@ -359,6 +393,7 @@ kotlin {
359393
}
360394
}
361395
implementation("io.ktor:ktor-client-ios:$ktorVersion")
396+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetimeVersion")
362397
}
363398
}
364399

@@ -479,7 +514,9 @@ tasks {
479514

480515

481516
fun MavenPublication.setupPom(publicationName: String) {
482-
artifactId = artifactId.replace("-web", "")
517+
artifactId = artifactId
518+
.replace("-web", "")
519+
.replace("jsbrowserextensions", "js-browser-extensions")
483520
artifact(dokkaJar.get())
484521

485522
pom {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.adamratzman.spotify.utils
2+
3+
import kotlinx.datetime.Clock
4+
import kotlinx.datetime.Instant
5+
6+
/**
7+
* The current time in milliseconds since UNIX epoch.
8+
*/
9+
actual fun getCurrentTimeMs(): Long = Clock.System.now().toEpochMilliseconds()
10+
11+
/**
12+
* Format date to ISO 8601 format
13+
*/
14+
internal actual fun formatDate(date: Long): String {
15+
return Instant.fromEpochMilliseconds(date).toString()
16+
}

src/commonMain/kotlin/com.adamratzman.spotify/utils/IO.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.soywiz.korio.file.VfsFile
77
import com.soywiz.korio.file.std.UrlVfs
88
import com.soywiz.korio.file.std.localVfs
99
import com.soywiz.krypto.encoding.Base64
10-
import io.ktor.utils.io.core.String
1110

1211
/**
1312
* Represents an image. Please use convertXToBufferedImage and convertBufferedImageToX methods to read and write [BufferedImage]

src/commonMain/kotlin/com.adamratzman.spotify/utils/Utils.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ package com.adamratzman.spotify.utils
33

44
import com.adamratzman.spotify.SpotifyException
55
import com.adamratzman.spotify.models.ResultEnum
6-
import kotlinx.datetime.Clock
7-
import kotlinx.datetime.Instant
86
import kotlinx.serialization.json.JsonElement
97

108
/**
119
* The current time in milliseconds since UNIX epoch.
1210
*/
13-
public fun getCurrentTimeMs(): Long = Clock.System.now().toEpochMilliseconds()
11+
public expect fun getCurrentTimeMs(): Long
12+
13+
/**
14+
* Format date to ISO 8601 format
15+
*/
16+
internal expect fun formatDate(date: Long): String
1417

1518
internal fun jsonMap(vararg pairs: Pair<String, JsonElement>) = pairs.toMap().toMutableMap()
1619

@@ -27,11 +30,5 @@ internal suspend inline fun <T> catch(crossinline function: suspend () -> T): T?
2730
internal fun <T : ResultEnum> Array<T>.match(identifier: String) =
2831
firstOrNull { it.retrieveIdentifier().toString().equals(identifier, true) }
2932

30-
/**
31-
* Format date to ISO 8601 format
32-
*/
33-
internal fun formatDate(date: Long): String {
34-
return Instant.fromEpochMilliseconds(date).toString()
35-
}
3633

3734
public expect fun <T> runBlockingOnJvmAndNative(block: suspend () -> T): T

src/commonTest/kotlin/com.adamratzman/spotify/pub/PublicArtistsApiTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ class PublicArtistsApiTest : AbstractTest<GenericSpotifyApi>() {
1818
@Test
1919
fun testGetArtists() {
2020
return runBlockingTest {
21-
println("here")
2221
super.build<GenericSpotifyApi>()
23-
println("here2")
24-
println(api)
2522
if (!testPrereq()) return@runBlockingTest else api!!
2623
println("here3")
2724
assertNull(api!!.artists.getArtist("adkjlasdf"))

src/desktopMain/kotlin/com/adamratzman/spotify/utils/PlatformUtils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package com.adamratzman.spotify.utils
33

44
import io.ktor.http.encodeURLQueryComponent
5+
import kotlinx.datetime.Clock
6+
import kotlinx.datetime.Instant
57

68
internal actual fun String.encodeUrl() = encodeURLQueryComponent()
79

@@ -13,3 +15,15 @@ public actual val currentApiPlatform: Platform = Platform.NATIVE
1315
public actual typealias ConcurrentHashMap<K, V> = HashMap<K, V>
1416

1517
public actual fun <K, V> ConcurrentHashMap<K, V>.asList(): List<Pair<K, V>> = toList()
18+
19+
/**
20+
* The current time in milliseconds since UNIX epoch.
21+
*/
22+
public actual fun getCurrentTimeMs(): Long = Clock.System.now().toEpochMilliseconds()
23+
24+
/**
25+
* Format date to ISO 8601 format
26+
*/
27+
internal actual fun formatDate(date: Long): String {
28+
return Instant.fromEpochMilliseconds(date).toString()
29+
}

src/jsMain/kotlin/co.scdn.sdk/SpotifyPlayerJs.kt renamed to src/jsBrowserExtensionsMain/kotlin/co.scdn.sdk/SpotifyPlayerJs.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
22
package co.scdn.sdk
3-
/*
3+
44
import com.adamratzman.spotify.webplayer.Error
55
import com.adamratzman.spotify.webplayer.PlaybackState
66
import com.adamratzman.spotify.webplayer.WebPlaybackInstance
77
import kotlinx.browser.window
8-
/*
8+
99
public fun setOnSpotifyWebPlaybackSDKReady(callback: suspend () -> Unit) {
1010
val dynamicWindow: dynamic = window
1111
dynamicWindow["onSpotifyWebPlaybackSDKReady"] = callback
@@ -51,5 +51,4 @@ public enum class SpotifyWebPlaybackEvent(public val spotifyId: String) {
5151

5252
public typealias ErrorListener = (err: Error) -> Unit
5353
public typealias PlaybackPlayerListener = (inst: WebPlaybackInstance) -> Unit
54-
public typealias PlaybackStateListener = (s: PlaybackState) -> Unit
55-
*/
54+
public typealias PlaybackStateListener = (s: PlaybackState) -> Unit

src/jsMain/kotlin/com/adamratzman/spotify/utils/ImplicitGrant.kt renamed to src/jsBrowserExtensionsMain/kotlin/com/adamratzman/spotify/utils/ImplicitGrant.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ package com.adamratzman.spotify.utils
66
import com.adamratzman.spotify.SpotifyImplicitGrantApi
77
import com.adamratzman.spotify.models.Token
88
import org.w3c.dom.url.URLSearchParams
9-
/*
9+
1010
import kotlinx.browser.window
1111

1212
/**
1313
* Parse the current url into a valid [Token] to be used when instantiating a new [SpotifyImplicitGrantApi]
1414
*/
1515
public fun parseSpotifyCallbackHashToToken(): Token = parseSpotifyCallbackHashToToken(window.location.hash.substring(1))
16-
*/
16+
1717
/**
1818
* Parse the hash string into a valid [Token] to be used when instantiating a new [SpotifyImplicitGrantApi]
1919
*

0 commit comments

Comments
 (0)